Skip to content

Commit

Permalink
Add "Default" group to fixtures that have no group
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetik committed Aug 23, 2019
1 parent 948f8b5 commit 5bbee66
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Loader/SymfonyFixturesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function addFixture(FixtureInterface $fixture) : void

if ($fixture instanceof FixtureGroupInterface) {
$this->addGroupsFixtureMapping($class, $fixture::getGroups());
} else {
$this->addGroupsFixtureMapping($class, ['Default']);
}

parent::addFixture($fixture);
Expand Down
16 changes: 16 additions & 0 deletions Tests/Fixtures/FooBundle/DataFixtures/NoGroupFixtures.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures;

use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class NoGroupFixtures implements ORMFixtureInterface
{
public function load(ObjectManager $manager)
{
//
}
}
33 changes: 33 additions & 0 deletions Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Bundle\FixturesBundle\DependencyInjection\CompilerPass\FixturesCompilerPass;
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\DependentOnRequiredConstructorArgsFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\NoGroupFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\OtherFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\RequiredConstructorArgsFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\WithDependenciesFixtures;
Expand Down Expand Up @@ -304,6 +305,38 @@ public function testLoadFixturesByShortName() : void
OtherFixtures::class,
], $actualFixtureClasses);
}

public function testLoadFixturesInDefaultGroup() : void
{
$kernel = new IntegrationTestKernel('dev', true);
$kernel->addServices(static function (ContainerBuilder $c) : void {
// has a "staging" group via the getGroups() method
$c->autowire(OtherFixtures::class)
->addTag(FixturesCompilerPass::FIXTURE_TAG);

// no getGroups() method
$c->autowire(NoGroupFixtures::class)
->addTag(FixturesCompilerPass::FIXTURE_TAG);

$c->setAlias('test.doctrine.fixtures.loader', new Alias('doctrine.fixtures.loader', true));
});
$kernel->boot();
$container = $kernel->getContainer();

/** @var ContainerAwareLoader $loader */
$loader = $container->get('test.doctrine.fixtures.loader');

$actualFixtures = $loader->getFixtures(['Default']);

$this->assertCount(1, $actualFixtures);
$actualFixtureClasses = array_map(static function ($fixture) {
return get_class($fixture);
}, $actualFixtures);

$this->assertSame([
NoGroupFixtures::class,
], $actualFixtureClasses);
}
}

class IntegrationTestKernel extends Kernel
Expand Down

0 comments on commit 5bbee66

Please sign in to comment.