-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from baldurrensch/functional_tests
Functional tests
- Loading branch information
Showing
19 changed files
with
466 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Hautelook\AliceBundle\Tests\Functional; | ||
|
||
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; | ||
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle; | ||
use Hautelook\AliceBundle\HautelookAliceBundle; | ||
use Hautelook\AliceBundle\Tests\Functional\TestBundle\TestBundle; | ||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
class AppKernel extends Kernel | ||
{ | ||
public function registerBundles() | ||
{ | ||
return array( | ||
new FrameworkBundle(), | ||
new HautelookAliceBundle(), | ||
new DoctrineBundle(), | ||
new DoctrineFixturesBundle(), | ||
|
||
new TestBundle(), | ||
); | ||
} | ||
|
||
public function getCacheDir() | ||
{ | ||
return sys_get_temp_dir().'/AliceBundle/'; | ||
} | ||
|
||
public function registerContainerConfiguration(LoaderInterface $loader) | ||
{ | ||
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
namespace Hautelook\AliceBundle\Tests\Functional\Command; | ||
|
||
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\CreateSchemaDoctrineCommand; | ||
use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand; | ||
use Hautelook\AliceBundle\Tests\Functional\TestCase; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class DoctrineFixtureTest extends TestCase | ||
{ | ||
/** | ||
* @var Application | ||
*/ | ||
private $application; | ||
|
||
public function testFixture() | ||
{ | ||
$command = $this->application->find('doctrine:fixtures:load'); | ||
|
||
$commandTester = new CommandTester($command); | ||
$commandTester->execute(array(), array('interactive' => false)); | ||
|
||
$display = $commandTester->getDisplay(); | ||
|
||
$this->assertContains('> purging database', $display); | ||
$this->assertContains( | ||
'> loading Hautelook\AliceBundle\Tests\Functional\TestBundle\DataFixtures\ORM\FixtureLoader1', | ||
$display | ||
); | ||
$this->assertContains( | ||
'> loading Hautelook\AliceBundle\Tests\Functional\TestBundle\DataFixtures\ORM\FixtureLoader2', | ||
$display | ||
); | ||
|
||
$this->verifyProducts(); | ||
$this->verifyBrands(); | ||
} | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->application = new Application(self::getKernel()); | ||
$this->application->add(new LoadDataFixturesDoctrineCommand()); | ||
$this->application->add(new CreateSchemaDoctrineCommand()); | ||
|
||
$this->createDB(); | ||
} | ||
|
||
private function createDB() | ||
{ | ||
$command = $this->application->find('doctrine:schema:create'); | ||
|
||
$commandTester = new CommandTester($command); | ||
$commandTester->execute(array()); | ||
} | ||
|
||
/** | ||
* @return \Doctrine\Bundle\DoctrineBundle\Registry | ||
*/ | ||
private function getDoctrine() | ||
{ | ||
return $this->application->getKernel()->getContainer()->get('doctrine'); | ||
} | ||
|
||
private function verifyProducts() | ||
{ | ||
for ($i = 1; $i <= 10; $i++) { | ||
/** @var $brand \Hautelook\AliceBundle\Tests\Functional\TestBundle\Entity\Product */ | ||
$product = $this->getDoctrine()->getManager()->find( | ||
'Hautelook\AliceBundle\Tests\Functional\TestBundle\Entity\Product', | ||
$i | ||
); | ||
|
||
// Make sure every product has a brand | ||
$this->assertInstanceOf( | ||
'Hautelook\AliceBundle\Tests\Functional\TestBundle\Entity\Brand', | ||
$product->getBrand() | ||
); | ||
} | ||
} | ||
|
||
private function verifyBrands() | ||
{ | ||
for ($i = 1; $i <= 10; $i++) { | ||
/** @var $brand \Hautelook\AliceBundle\Tests\Functional\TestBundle\Entity\Brand */ | ||
$brand = $this->getDoctrine()->getManager()->find( | ||
'Hautelook\AliceBundle\Tests\Functional\TestBundle\Entity\Brand', | ||
$i | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Hautelook\AliceBundle\Tests\Functional; | ||
|
||
/** | ||
* @group functional | ||
*/ | ||
class ControllerTest extends TestCase | ||
{ | ||
public function testServiceSetup() | ||
{ | ||
$client = $this->createClient(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Hautelook\AliceBundle\Tests\Functional\TestBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class RootController extends Controller | ||
{ | ||
public function testAction(Request $request) | ||
{ | ||
return new Response("TestResponse"); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Tests/Functional/TestBundle/DataFixtures/ORM/FixtureLoader1.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Hautelook\AliceBundle\Tests\Functional\TestBundle\DataFixtures\ORM; | ||
|
||
use Doctrine\Common\DataFixtures\DependentFixtureInterface; | ||
use Hautelook\AliceBundle\Alice\DataFixtureLoader; | ||
|
||
class FixtureLoader1 extends DataFixtureLoader implements DependentFixtureInterface | ||
{ | ||
/** | ||
* Returns an array of file paths to fixtures | ||
* | ||
* @return array<string> | ||
*/ | ||
protected function getFixtures() | ||
{ | ||
return array( | ||
__DIR__ . '/product.yml', | ||
); | ||
} | ||
|
||
/** | ||
* This method must return an array of fixtures classes | ||
* on which the implementing class depends on | ||
* | ||
* @return array | ||
*/ | ||
function getDependencies() | ||
{ | ||
return array( | ||
'Hautelook\AliceBundle\Tests\Functional\TestBundle\DataFixtures\ORM\FixtureLoader2', | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Tests/Functional/TestBundle/DataFixtures/ORM/FixtureLoader2.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Hautelook\AliceBundle\Tests\Functional\TestBundle\DataFixtures\ORM; | ||
|
||
use Hautelook\AliceBundle\Alice\DataFixtureLoader; | ||
|
||
class FixtureLoader2 extends DataFixtureLoader | ||
{ | ||
/** | ||
* Returns an array of file paths to fixtures | ||
* | ||
* @return array<string> | ||
*/ | ||
protected function getFixtures() | ||
{ | ||
return array( | ||
__DIR__ . '/brand.yml', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Hautelook\AliceBundle\Tests\Functional\TestBundle\Entity\Brand: | ||
brand{1..10}: | ||
name: brand <current()> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Hautelook\AliceBundle\Tests\Functional\TestBundle\Entity\Product: | ||
product{1..10}: | ||
name: Product <current()> | ||
price: 10.0 | ||
description: Super awesome product | ||
brand: @brand* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Hautelook\AliceBundle\Tests\Functional\TestBundle\Entity; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="brand") | ||
*/ | ||
class Brand | ||
{ | ||
/** | ||
* @ORM\Column(type="integer") | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=100) | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* @ORM\OneToMany(targetEntity="Product", mappedBy="brand") | ||
*/ | ||
protected $products; | ||
|
||
public function __construct() | ||
{ | ||
$this->products = new ArrayCollection(); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return Collection | ||
*/ | ||
public function getProducts() | ||
{ | ||
return $this->products; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Hautelook\AliceBundle\Tests\Functional\TestBundle\Entity; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="product") | ||
*/ | ||
class Product | ||
{ | ||
/** | ||
* @ORM\Column(type="integer") | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=100) | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* @ORM\Column(type="decimal", scale=2) | ||
*/ | ||
protected $price; | ||
|
||
/** | ||
* @ORM\Column(type="text") | ||
*/ | ||
protected $description; | ||
|
||
/** | ||
* @var Brand | ||
* | ||
* @ORM\ManyToOne(targetEntity="Brand", inversedBy="products") | ||
* @ORM\JoinColumn(name="brand_id", referencedColumnName="id") | ||
*/ | ||
protected $brand; | ||
|
||
/** | ||
* @return Brand | ||
*/ | ||
public function getBrand() | ||
{ | ||
return $this->brand; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDescription() | ||
{ | ||
return $this->description; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getPrice() | ||
{ | ||
return $this->price; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
services: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Hautelook\AliceBundle\Tests\Functional\TestBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class TestBundle extends Bundle | ||
{ | ||
} |
Oops, something went wrong.