Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add "Default" group to fixtures that have no group #292

Draft
wants to merge 1 commit into
base: 3.4.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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