The bundle's internal tests show several ways to load fixtures:
- data with fixtures dependencies
- data with dependency injection
- fixture loading with Alice
- custom provider:
- using events to perform actions during fixtures loading:
<?php
declare(strict_types=1);
namespace Liip\FooBundle\Tests;
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class ExampleFunctionalTest extends WebTestCase
{
/**
* @var AbstractDatabaseTool
*/
protected $databaseTool;
public function setUp(): void
{
parent::setUp();
$this->databaseTool = static::getContainer()->get(DatabaseToolCollection::class)->get();
}
/**
* Example using LiipFunctionalBundle the fixture loader.
*/
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->databaseTool->loadFixtures(['Liip\FooBundle\Tests\Fixtures\LoadUserData']);
$crawler = $client->request('GET', '/users/foo');
// …
}
protected function tearDown(): void
{
parent::tearDown();
unset($this->databaseTool);
}
}