Skip to content

Commit

Permalink
Loading fixtures registered as service (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gappa authored Jan 10, 2025
1 parent 3dba4a3 commit 2d05568
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Command/LoadDataFixturesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$fixtures = $this->fixturesLoader->getFixtures();
if ($fixtures === []) {

if ($fixtures === []) {
if ($paths === []) {
throw new LogicalException('Could not find any fixtures to load.');
} else {
Expand Down
16 changes: 16 additions & 0 deletions src/DI/FixturesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Nettrine\Fixtures\DI;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Nette\DI\CompilerExtension;
use Nette\DI\Definitions\ServiceDefinition;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use Nettrine\Fixtures\Command\LoadDataFixturesCommand;
Expand Down Expand Up @@ -35,4 +37,18 @@ public function loadConfiguration(): void
->addTag('console.command', 'doctrine:fixtures:load');
}

public function beforeCompile(): void
{
$builder = $this->getContainerBuilder();

$fixtures = $builder->findByType(FixtureInterface::class);

/** @var ServiceDefinition $fixtureLoader */
$fixtureLoader = $builder->getDefinitionByType(FixturesLoader::class);

foreach ($fixtures as $fixture) {
$fixtureLoader->addSetup('addFixture', [$fixture]);
}
}

}

0 comments on commit 2d05568

Please sign in to comment.