Skip to content

Commit

Permalink
Merge pull request #62 from ndench/single-kernel
Browse files Browse the repository at this point in the history
Prevent duplicate kernels booting and ensure they're cleaned up
  • Loading branch information
alexislefebvre authored Apr 27, 2020
2 parents 664e155 + c6ca3fb commit 44f60a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
14 changes: 10 additions & 4 deletions doc/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ Tips for Fixture Loading Tests
public function testIndex()
{
// If you need a client, you must create it before loading fixtures because
// creating the client boots the kernel, which is used by loadFixtures
$client = $this->createClient();
// add all your fixtures classes that implement
// Doctrine\Common\DataFixtures\FixtureInterface
$this->loadFixtures(array(
Expand All @@ -100,7 +104,6 @@ Tips for Fixture Loading Tests
));
// you can now run your functional tests with a populated database
$client = $this->createClient();
// ...
}
}
Expand All @@ -120,10 +123,12 @@ Tips for Fixture Loading Tests
public function testIndex()
{
// If you need a client, you must create it before loading fixtures because
// creating the client boots the kernel, which is used by loadFixtures
$client = $this->createClient();
$this->loadFixtures();
// you can now run your functional tests with a populated database
$client = $this->createClient();
// ...
}
}
Expand Down Expand Up @@ -190,9 +195,10 @@ Tips for Fixture Loading Tests
'Me\MyBundle\DataFixtures\MongoDB\LoadData'
);
$this->loadFixtures($fixtures, false, null, 'doctrine_mongodb');
// If you need a client, you must create it before loading fixtures because
// creating the client boots the kernel, which is used by loadFixtures
$client = $this->createClient();
$this->loadFixtures($fixtures, false, null, 'doctrine_mongodb');
}
}
```
Expand Down
4 changes: 3 additions & 1 deletion doc/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ class ExampleFunctionalTest extends WebTestCase
*/
public function testUserFooIndex(): void
{
// If you need a client, you must create it before loading fixtures because
// creating the client boots the kernel, which is used by loadFixtures
$client = $this->createClient();
$this->loadFixtures(['Liip\FooBundle\Tests\Fixtures\LoadUserData']);

$client = $this->createClient();
$crawler = $client->request('GET', '/users/foo');

// …
Expand Down
9 changes: 6 additions & 3 deletions src/Test/FixturesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ protected function getContainer(): ContainerInterface
$options = [
'environment' => $environment,
];
$kernel = $this->createKernel($options);
$kernel->boot();

$container = $kernel->getContainer();
// Check that the kernel has not been booted separately (eg. with static::createClient())
if (null === static::$kernel || null === static::$kernel->getContainer()) {
$this->bootKernel($options);
}

$container = static::$kernel->getContainer();
if ($container->has('test.service_container')) {
$this->containers[$environment] = $container->get('test.service_container');
} else {
Expand Down

0 comments on commit 44f60a7

Please sign in to comment.