-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-working fixtures loading to load tagged services
Also fixing a bug where getDependencies() Basically, currently getDependencies() won't work if any of your classes have required constructor args. We've added a clear error message for this situation. Also added forwards-compat for the soon-to-be-released doctrine/data-fixtures version 1.3, which will fix the above problem.
- Loading branch information
1 parent
74b8cc7
commit ee5eb61
Showing
20 changed files
with
582 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
language: php | ||
sudo: false | ||
cache: | ||
directories: | ||
- $HOME/.composer/cache/files | ||
|
||
matrix: | ||
fast_finish: true | ||
include: | ||
# Minimum supported PHP and Symfony version | ||
- php: 5.5 | ||
env: DEPENDENCIES="minimum" | ||
|
||
# Test the latest stable release | ||
- php: 5.5 | ||
- php: 5.6 | ||
- php: 7.0 | ||
- php: 7.1 | ||
- php: 7.2 | ||
|
||
# Test LTS version we support | ||
- php: 7.2 | ||
env: DEPENDENCIES="symfony/lts:v3" | ||
|
||
- php: 7.2 | ||
env: DEPENDENCIES="beta" | ||
|
||
before_install: | ||
- if [ "$DEPENDENCIES" = "minimum" ]; then COMPOSER_FLAGS="--prefer-stable --prefer-lowest"; fi; | ||
- if [ "$DEPENDENCIES" = "beta" ]; then composer config minimum-stability beta; fi; | ||
- if [[ $DEPENDENCIES == *"/"* ]]; then composer require --no-update $DEPENDENCIES; fi; | ||
|
||
install: | ||
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355 | ||
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi | ||
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction | ||
|
||
script: | ||
- ./vendor/bin/simple-phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Doctrine Fixtures Bundle | ||
* | ||
* The code was originally distributed inside the Symfony framework. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* (c) Doctrine Project | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Doctrine\Bundle\FixturesBundle\DependencyInjection\CompilerPass; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* @author Ryan Weaver <[email protected]> | ||
*/ | ||
final class FixturesCompilerPass implements CompilerPassInterface | ||
{ | ||
const FIXTURE_TAG = 'doctrine.fixture.orm'; | ||
|
||
public function process(ContainerBuilder $container) | ||
{ | ||
$definition = $container->getDefinition('doctrine.fixtures.loader'); | ||
$taggedServices = $container->findTaggedServiceIds(self::FIXTURE_TAG); | ||
|
||
foreach ($taggedServices as $serviceId => $tags) { | ||
$definition->addMethodCall('addFixture', [new Reference($serviceId)]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,15 +20,6 @@ | |
* | ||
* @author Javier Eguiluz <[email protected]> | ||
*/ | ||
abstract class Fixture extends AbstractFixture implements ContainerAwareInterface, DependentFixtureInterface | ||
abstract class Fixture extends AbstractFixture implements ORMFixtureInterface | ||
{ | ||
use ContainerAwareTrait; | ||
|
||
public function getDependencies() | ||
{ | ||
// 'EmptyFixture' is a fixture class that loads no data. It's required | ||
// because Doctrine doesn't allow to return an empty array in this method | ||
// See https://github.com/doctrine/data-fixtures/pull/252 | ||
return array(EmptyFixture::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Doctrine Fixtures Bundle. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Doctrine\Bundle\FixturesBundle\Loader; | ||
|
||
use Doctrine\Bundle\FixturesBundle\DependencyInjection\CompilerPass\FixturesCompilerPass; | ||
use Doctrine\Common\DataFixtures\DependentFixtureInterface; | ||
use Doctrine\Common\DataFixtures\FixtureInterface; | ||
use Doctrine\Common\DataFixtures\Loader; | ||
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader; | ||
|
||
/** | ||
* @author Ryan Weaver <[email protected]> | ||
*/ | ||
final class SymfonyFixturesLoader extends ContainerAwareLoader | ||
{ | ||
public function addFixture(FixtureInterface $fixture) | ||
{ | ||
// see https://github.com/doctrine/data-fixtures/pull/274 | ||
// this is to give a clear error if you do not have this version | ||
if (!method_exists(Loader::class, 'createFixture')) { | ||
$this->checkForNonInstantiableFixtures($fixture); | ||
} | ||
|
||
parent::addFixture($fixture); | ||
} | ||
|
||
/** | ||
* Overridden to not allow new fixture classes to be instantiated. | ||
*/ | ||
protected function createFixture($class) | ||
{ | ||
try { | ||
/* | ||
* We don't actually need to create the fixture. We just | ||
* return the one that already exists. | ||
*/ | ||
return $this->getFixture($class); | ||
} catch (\InvalidArgumentException $e) { | ||
throw new \LogicException(sprintf('The "%s" fixture class is trying to be loaded, but is not available. Make sure this class is defined as a service and tagged with "%s".', $class, FixturesCompilerPass::FIXTURE_TAG)); | ||
} | ||
} | ||
|
||
/** | ||
* For doctrine/data-fixtures 1.2 or lower, this detects an unsupported | ||
* feature with DependentFixtureInterface so that we can throw a | ||
* clear exception. | ||
* | ||
* @param FixtureInterface $fixture | ||
* @throws \Exception | ||
*/ | ||
private function checkForNonInstantiableFixtures(FixtureInterface $fixture) | ||
{ | ||
if (!$fixture instanceof DependentFixtureInterface) { | ||
return; | ||
} | ||
|
||
foreach ($fixture->getDependencies() as $dependency) { | ||
if (!class_exists($dependency)) { | ||
continue; | ||
} | ||
|
||
if (!method_exists($dependency, '__construct')) { | ||
continue; | ||
} | ||
|
||
$reflMethod = new \ReflectionMethod($dependency, '__construct'); | ||
foreach ($reflMethod->getParameters() as $param) { | ||
if (!$param->isOptional()) { | ||
throw new \LogicException(sprintf('The getDependencies() method returned a class (%s) that has required constructor arguments. Upgrade to "doctrine/data-fixtures" version 1.3 or higher to support this.', $dependency)); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\FixturesBundle; | ||
|
||
use Doctrine\Common\DataFixtures\FixtureInterface; | ||
|
||
/** | ||
* Marks your fixtures that are specifically for the ORM. | ||
*/ | ||
interface ORMFixtureInterface extends FixtureInterface | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.