Skip to content

Commit

Permalink
Merge pull request #16 from baldurrensch/functional_tests
Browse files Browse the repository at this point in the history
Functional tests
  • Loading branch information
baldurrensch committed Mar 12, 2014
2 parents 8fe8c1f + 784bd98 commit 912ca53
Show file tree
Hide file tree
Showing 19 changed files with 466 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<argument type="collection">
<argument key="yaml" type="service" id="hautelook_alice.loader.yaml" />
</argument>
<argument type="service" id="logger" />
<argument type="service" id="logger" on-invalid="null"/>
</service>

</services>
Expand Down
36 changes: 36 additions & 0 deletions Tests/Functional/AppKernel.php
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');
}
}
95 changes: 95 additions & 0 deletions Tests/Functional/Command/DoctrineFixtureTest.php
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
);
}
}
}
14 changes: 14 additions & 0 deletions Tests/Functional/ControllerTest.php
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();
}
}
15 changes: 15 additions & 0 deletions Tests/Functional/TestBundle/Controller/RootController.php
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 Tests/Functional/TestBundle/DataFixtures/ORM/FixtureLoader1.php
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 Tests/Functional/TestBundle/DataFixtures/ORM/FixtureLoader2.php
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',
);
}
}
3 changes: 3 additions & 0 deletions Tests/Functional/TestBundle/DataFixtures/ORM/brand.yml
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()>
6 changes: 6 additions & 0 deletions Tests/Functional/TestBundle/DataFixtures/ORM/product.yml
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*
60 changes: 60 additions & 0 deletions Tests/Functional/TestBundle/Entity/Brand.php
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;
}
}
82 changes: 82 additions & 0 deletions Tests/Functional/TestBundle/Entity/Product.php
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;
}
}
1 change: 1 addition & 0 deletions Tests/Functional/TestBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
services:
9 changes: 9 additions & 0 deletions Tests/Functional/TestBundle/TestBundle.php
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
{
}
Loading

0 comments on commit 912ca53

Please sign in to comment.