I am trying to configure symfony to use sqlite for tests.
composer.json (require-dev)
"doctrine/doctrine-fixtures-bundle": "^3.1",
"liip/functional-test-bundle": "~2.0@alpha",
config/packages/test/doctrine.yaml:
doctrine:
dbal:
driver: 'pdo_sqlite'
url: 'sqlite:///%kernel.project_dir%/var/test.db3'
then I made a test like this
class SimplestTest extends WebTestCase
{
private $fixtures;
public function setUp()
{
$this->fixtures = $this->loadFixtures([
MyFixtures::class
])->getReferenceRepository();
}
public function testToSeeIfItWorks()
{
$this->assertTrue(true);
}
}
MyFixtures class extends AbstractFixture and load some simple objects:
class MyFixtures extends AbstractFixture
{
public function load(ObjectManager $manager)
{
$user1 = new User();
$user1->setRoles(['ROLE_USER']);
$manager->persist($user1);
$manager->flush();
$myFeed = new Feed();
$myFeed->setName('Feed 1');
$myFeed->setUrl('http://someurl');
$myFeed->setUser($user1);
$manager->persist($myFeed);
$manager->flush();
}
}
When I run the test I get:
InvalidArgumentException: "App\Tests\DataFixtures\ORM\MyFixtures" is not a registered fixture
no idea why. any help?
thank you
MyFixture, remove the first$manager->flush(). Maybe, for whatever dark doctrine reason, it produces the error. - Michał Tomczuk