Skip to content

Commit

Permalink
Tests: Don't load Hautelook in the default configuration,
Browse files Browse the repository at this point in the history
it replaced NelmioAlice loader during all the tests

See #246
  • Loading branch information
alexislefebvre committed Mar 20, 2016
1 parent 3a67aa2 commit 97cedfc
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 135 deletions.
1 change: 0 additions & 1 deletion Tests/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public function registerBundles()
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
new Liip\FunctionalTestBundle\LiipFunctionalTestBundle(),
new Hautelook\AliceBundle\HautelookAliceBundle(),
);

return $bundles;
Expand Down
5 changes: 0 additions & 5 deletions Tests/App/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,3 @@ security:
access_control:
- { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY }

# HautelookAliceBundle: custom Faker provider
services:
faker.provider.foo:
class: Liip\FunctionalTestBundle\Tests\App\DataFixtures\Faker\Provider\FooProvider
tags: [ { name: hautelook_alice.faker.provider } ]
10 changes: 10 additions & 0 deletions Tests/AppConfig/AppConfigKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@

class AppConfigKernel extends AppKernel
{
public function registerBundles()
{
return array_merge(
parent::registerBundles(),
array(
new Hautelook\AliceBundle\HautelookAliceBundle(),
)
);
}

/**
* Load the config.yml from the current directory.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* with this source code in the file LICENSE.
*/

namespace Liip\FunctionalTestBundle\Tests\App\DataFixtures\Faker\Provider;
namespace Liip\FunctionalTestBundle\Tests\AppConfig\DataFixtures\Faker\Provider;

class FooProvider
{
Expand Down
6 changes: 6 additions & 0 deletions Tests/AppConfig/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ liip_functional_test:
ignores_extract:
- 'ignore_extract_1'
- 'ignore_extract_2'

# HautelookAliceBundle: custom Faker provider
services:
faker.provider.foo:
class: Liip\FunctionalTestBundle\Tests\AppConfig\DataFixtures\Faker\Provider\FooProvider
tags: [ { name: hautelook_alice.faker.provider } ]
128 changes: 128 additions & 0 deletions Tests/Test/WebTestCaseConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,132 @@ public function testAnnotationAndException()

$this->client->request('GET', $path);
}

/**
* Test if there is a call-out to the service if defined.
*/
public function testHautelookServiceUsage()
{
$hautelookLoaderMock = $this->getMockBuilder('\Hautelook\AliceBundle\Alice\DataFixtures\Loader')
->disableOriginalConstructor()
->setMethods(array('load'))
->getMock();
$hautelookLoaderMock->expects(self::once())->method('load');

$this->getContainer()->set('hautelook_alice.fixtures.loader', $hautelookLoaderMock);

$this->loadFixtureFiles(array(
'@LiipFunctionalTestBundle/Tests/App/DataFixtures/ORM/user.yml',
));
}

/**
* Use hautelook.
*/
public function testLoadFixturesFilesWithHautelook()
{
if (!class_exists('Hautelook\AliceBundle\Faker\Provider\ProviderChain')) {
self::markTestSkipped('Please use hautelook/alice-bundle >=1.2');
}

$fakerProcessorChain = new \Hautelook\AliceBundle\Faker\Provider\ProviderChain(array());
$aliceProcessorChain = new \Hautelook\AliceBundle\Alice\ProcessorChain(array());
$fixtureLoader = new \Hautelook\AliceBundle\Alice\DataFixtures\Fixtures\Loader('en_US', $fakerProcessorChain);
$loader = new \Hautelook\AliceBundle\Alice\DataFixtures\Loader($fixtureLoader, $aliceProcessorChain, true, 10);
$this->getContainer()->set('hautelook_alice.fixtures.loader', $loader);

$fixtures = $this->loadFixtureFiles(array(
'@LiipFunctionalTestBundle/Tests/App/DataFixtures/ORM/user.yml',
));

$this->assertInternalType(
'array',
$fixtures
);

// 10 users are loaded
$this->assertCount(
10,
$fixtures
);

$em = $this->getContainer()
->get('doctrine.orm.entity_manager');

$users = $em->getRepository('LiipFunctionalTestBundle:User')
->findAll();

$this->assertSame(
10,
count($users)
);

/** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */
$user = $em->getRepository('LiipFunctionalTestBundle:User')
->findOneBy(array(
'id' => 1,
));

$this->assertTrue(
$user->getEnabled()
);

$user = $em->getRepository('LiipFunctionalTestBundle:User')
->findOneBy(array(
'id' => 10,
));

$this->assertTrue(
$user->getEnabled()
);
}

/**
* Load Data Fixtures with hautelook and custom loader defined in configuration.
*/
public function testLoadFixturesFilesWithHautelookCustomProvider()
{
if (!class_exists('Hautelook\AliceBundle\Faker\Provider\ProviderChain')) {
self::markTestSkipped('Please use hautelook/alice-bundle >=1.2');
}

// Load default Data Fixtures.
$fixtures = $this->loadFixtureFiles(array(
'@LiipFunctionalTestBundle/Tests/App/DataFixtures/ORM/user.yml',
));

$this->assertInternalType(
'array',
$fixtures
);

// 10 users are loaded
$this->assertCount(
10,
$fixtures
);

/** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */
$user = $fixtures['id1'];

// The custom provider has not been used successfully.
$this->assertStringStartsNotWith(
'foo',
$user->getName()
);

// Load Data Fixtures with custom loader defined in configuration.
$fixtures = $this->loadFixtureFiles(array(
'@LiipFunctionalTestBundle/Tests/App/DataFixtures/ORM/user_with_custom_provider.yml',
));

/** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */
$user = $fixtures['id1'];

// The custom provider "foo" has been loaded and used successfully.
$this->assertSame(
'fooa string',
$user->getName()
);
}
}
128 changes: 0 additions & 128 deletions Tests/Test/WebTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,134 +413,6 @@ public function testLoadFixturesFiles()
);
}

/**
* Test if there is a call-out to the service if defined.
*/
public function testHautelookServiceUsage()
{
$hautelookLoaderMock = $this->getMockBuilder('\Hautelook\AliceBundle\Alice\DataFixtures\Loader')
->disableOriginalConstructor()
->setMethods(array('load'))
->getMock();
$hautelookLoaderMock->expects(self::once())->method('load');

$this->getContainer()->set('hautelook_alice.fixtures.loader', $hautelookLoaderMock);

$this->loadFixtureFiles(array(
'@LiipFunctionalTestBundle/Tests/App/DataFixtures/ORM/user.yml',
));
}

/**
* Use hautelook.
*/
public function testLoadFixturesFilesWithHautelook()
{
if (!class_exists('Hautelook\AliceBundle\Faker\Provider\ProviderChain')) {
self::markTestSkipped('Please use hautelook/alice-bundle >=1.2');
}

$fakerProcessorChain = new \Hautelook\AliceBundle\Faker\Provider\ProviderChain(array());
$aliceProcessorChain = new \Hautelook\AliceBundle\Alice\ProcessorChain(array());
$fixtureLoader = new \Hautelook\AliceBundle\Alice\DataFixtures\Fixtures\Loader('en_US', $fakerProcessorChain);
$loader = new \Hautelook\AliceBundle\Alice\DataFixtures\Loader($fixtureLoader, $aliceProcessorChain, true, 10);
$this->getContainer()->set('hautelook_alice.fixtures.loader', $loader);

$fixtures = $this->loadFixtureFiles(array(
'@LiipFunctionalTestBundle/Tests/App/DataFixtures/ORM/user.yml',
));

$this->assertInternalType(
'array',
$fixtures
);

// 10 users are loaded
$this->assertCount(
10,
$fixtures
);

$em = $this->client->getContainer()
->get('doctrine.orm.entity_manager');

$users = $em->getRepository('LiipFunctionalTestBundle:User')
->findAll();

$this->assertSame(
10,
count($users)
);

/** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */
$user = $em->getRepository('LiipFunctionalTestBundle:User')
->findOneBy(array(
'id' => 1,
));

$this->assertTrue(
$user->getEnabled()
);

$user = $em->getRepository('LiipFunctionalTestBundle:User')
->findOneBy(array(
'id' => 10,
));

$this->assertTrue(
$user->getEnabled()
);
}

/**
* Load Data Fixtures with hautelook and custom loader defined in configuration.
*/
public function testLoadFixturesFilesWithHautelookCustomProvider()
{
if (!class_exists('Hautelook\AliceBundle\Faker\Provider\ProviderChain')) {
self::markTestSkipped('Please use hautelook/alice-bundle >=1.2');
}

// Load default Data Fixtures.
$fixtures = $this->loadFixtureFiles(array(
'@LiipFunctionalTestBundle/Tests/App/DataFixtures/ORM/user.yml',
));

$this->assertInternalType(
'array',
$fixtures
);

// 10 users are loaded
$this->assertCount(
10,
$fixtures
);

/** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */
$user = $fixtures['id1'];

// The custom provider has not been used successfully.
$this->assertStringStartsNotWith(
'foo',
$user->getName()
);

// Load Data Fixtures with custom loader defined in configuration.
$fixtures = $this->loadFixtureFiles(array(
'@LiipFunctionalTestBundle/Tests/App/DataFixtures/ORM/user_with_custom_provider.yml',
));

/** @var \Liip\FunctionalTestBundle\Tests\App\Entity\User $user */
$user = $fixtures['id1'];

// The custom provider "foo" has been loaded and used successfully.
$this->assertSame(
'fooa string',
$user->getName()
);
}

/**
* Use nelmio/alice with full path to the file.
*/
Expand Down

0 comments on commit 97cedfc

Please sign in to comment.