diff --git a/DataFixtures/Loader/YamlDataLoader.php b/DataFixtures/Loader/YamlDataLoader.php index 988b0f6..b064974 100644 --- a/DataFixtures/Loader/YamlDataLoader.php +++ b/DataFixtures/Loader/YamlDataLoader.php @@ -10,6 +10,7 @@ namespace Propel\PropelBundle\DataFixtures\Loader; +use Faker\Generator; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Yaml\ParseException; use Symfony\Component\Yaml\Yaml; @@ -22,18 +23,18 @@ use Symfony\Component\Yaml\Yaml; class YamlDataLoader extends AbstractDataLoader { /** - * @var \Symfony\Component\DependencyInjection\ContainerInterface + * @var \Faker\Generator */ - private $container; + private $faker; /** * {@inheritdoc} */ - public function __construct($rootDir, ContainerInterface $container) + public function __construct($rootDir, array $datasources, Generator $faker = null) { - parent::__construct($rootDir, $container->getParameter('propel.configuration')); + parent::__construct($rootDir, $datasources); - $this->container = $container; + $this->faker = $faker; } /** @@ -46,8 +47,8 @@ class YamlDataLoader extends AbstractDataLoader throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $file)); } - if (null !== $this->container && $this->container->has('faker.generator')) { - $generator = $this->container->get('faker.generator'); + if (null !== $this->faker) { + $generator = $this->faker; $faker = function ($type) use ($generator) { $args = func_get_args(); array_shift($args); diff --git a/Resources/config/propel.xml b/Resources/config/propel.xml index 2c2c9a6..4f99828 100644 --- a/Resources/config/propel.xml +++ b/Resources/config/propel.xml @@ -52,7 +52,8 @@ %kernel.root_dir% - + %propel.configuration% + diff --git a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php index 2a63bb2..4c21a03 100644 --- a/Tests/DataFixtures/Loader/YamlDataLoaderTest.php +++ b/Tests/DataFixtures/Loader/YamlDataLoaderTest.php @@ -37,7 +37,7 @@ class YamlDataLoaderTest extends TestCase YAML; $filename = $this->getTempFile($fixtures); - $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', $this->getContainer()); + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', array()); $loader->load(array($filename), 'default'); $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con); @@ -61,7 +61,7 @@ Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookAuthor: YAML; $filename = $this->getTempFile($fixtures); - $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', $this->getContainer()); + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', array()); $loader->load(array($filename), 'default'); $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con); @@ -85,7 +85,7 @@ Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookAuthor: YAML; $filename = $this->getTempFile($fixtures); - $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', $this->getContainer()); + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', array()); $loader->load(array($filename), 'default'); $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con); @@ -109,7 +109,7 @@ Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookAuthor: YAML; $filename = $this->getTempFile($fixtures); - $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', $this->getContainer()); + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', array()); $loader->load(array($filename), 'default'); $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con); @@ -137,10 +137,8 @@ Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBook: YAML; $filename = $this->getTempFile($fixtures); - $container = $this->getContainer(); - $container->set('faker.generator', \Faker\Factory::create()); - $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', $container); + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', array(), \Faker\Factory::create()); $loader->load(array($filename), 'default'); $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con); @@ -215,7 +213,7 @@ YAML; $con = $builder->build(); - $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', $this->getContainer()); + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', array()); $loader->load(array($filename), 'default'); $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyBookQuery::create()->find($con); @@ -303,7 +301,7 @@ YAML; $builder->setSchema($schema); $con = $builder->build(); - $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', $this->getContainer()); + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', array()); $loader->load(array($filename1, $filename2), 'default'); $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookQuery::create()->find($con); @@ -372,7 +370,7 @@ YAML; $builder->setSchema($schema); $con = $builder->build(); - $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', $this->getContainer()); + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', array()); $loader->load(array($filename), 'default'); $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedRelationshipBookQuery::create()->find($con); @@ -407,7 +405,7 @@ YAML; $builder->setSchema($schema); $con = $builder->build(); - $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', $this->getContainer()); + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', array()); $loader->load(array($filename), 'default'); $book = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlBookWithObjectQuery::create(null)->findOne($con); @@ -457,7 +455,7 @@ YAML; $builder->setSchema($schema); $con = $builder->build(); - $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', $this->getContainer()); + $loader = new YamlDataLoader(__DIR__.'/../../Fixtures/DataFixtures/Loader', array()); $loader->load(array($filename), 'default'); $authors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlDelegateOnPrimaryKeyAuthorQuery::create()->find($con);