Avoid injecting the container in the YamlDataLoader
This commit is contained in:
parent
c1eebcf61b
commit
d1ef814d57
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
namespace Propel\PropelBundle\DataFixtures\Loader;
|
namespace Propel\PropelBundle\DataFixtures\Loader;
|
||||||
|
|
||||||
|
use Faker\Generator;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\Yaml\ParseException;
|
use Symfony\Component\Yaml\ParseException;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
@ -22,18 +23,18 @@ use Symfony\Component\Yaml\Yaml;
|
||||||
class YamlDataLoader extends AbstractDataLoader
|
class YamlDataLoader extends AbstractDataLoader
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Symfony\Component\DependencyInjection\ContainerInterface
|
* @var \Faker\Generator
|
||||||
*/
|
*/
|
||||||
private $container;
|
private $faker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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));
|
throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $file));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $this->container && $this->container->has('faker.generator')) {
|
if (null !== $this->faker) {
|
||||||
$generator = $this->container->get('faker.generator');
|
$generator = $this->faker;
|
||||||
$faker = function ($type) use ($generator) {
|
$faker = function ($type) use ($generator) {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
array_shift($args);
|
array_shift($args);
|
||||||
|
|
|
@ -52,7 +52,8 @@
|
||||||
|
|
||||||
<service id="propel.loader.yaml" class="%propel.loader.yaml.class%">
|
<service id="propel.loader.yaml" class="%propel.loader.yaml.class%">
|
||||||
<argument>%kernel.root_dir%</argument>
|
<argument>%kernel.root_dir%</argument>
|
||||||
<argument type="service" id="service_container" />
|
<argument>%propel.configuration%</argument>
|
||||||
|
<argument type="service" id="faker.generator" on-invalid="null" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="propel.loader.xml" class="%propel.loader.xml.class%">
|
<service id="propel.loader.xml" class="%propel.loader.xml.class%">
|
||||||
|
|
|
@ -37,7 +37,7 @@ class YamlDataLoaderTest extends TestCase
|
||||||
YAML;
|
YAML;
|
||||||
$filename = $this->getTempFile($fixtures);
|
$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');
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con);
|
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con);
|
||||||
|
@ -61,7 +61,7 @@ Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookAuthor:
|
||||||
YAML;
|
YAML;
|
||||||
$filename = $this->getTempFile($fixtures);
|
$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');
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con);
|
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con);
|
||||||
|
@ -85,7 +85,7 @@ Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookAuthor:
|
||||||
YAML;
|
YAML;
|
||||||
$filename = $this->getTempFile($fixtures);
|
$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');
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con);
|
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con);
|
||||||
|
@ -109,7 +109,7 @@ Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookAuthor:
|
||||||
YAML;
|
YAML;
|
||||||
$filename = $this->getTempFile($fixtures);
|
$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');
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con);
|
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con);
|
||||||
|
@ -137,10 +137,8 @@ Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBook:
|
||||||
|
|
||||||
YAML;
|
YAML;
|
||||||
$filename = $this->getTempFile($fixtures);
|
$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');
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con);
|
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con);
|
||||||
|
@ -215,7 +213,7 @@ YAML;
|
||||||
|
|
||||||
$con = $builder->build();
|
$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');
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyBookQuery::create()->find($con);
|
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyBookQuery::create()->find($con);
|
||||||
|
@ -303,7 +301,7 @@ YAML;
|
||||||
$builder->setSchema($schema);
|
$builder->setSchema($schema);
|
||||||
$con = $builder->build();
|
$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');
|
$loader->load(array($filename1, $filename2), 'default');
|
||||||
|
|
||||||
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookQuery::create()->find($con);
|
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlManyToManyMultipleFilesBookQuery::create()->find($con);
|
||||||
|
@ -372,7 +370,7 @@ YAML;
|
||||||
$builder->setSchema($schema);
|
$builder->setSchema($schema);
|
||||||
$con = $builder->build();
|
$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');
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedRelationshipBookQuery::create()->find($con);
|
$books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlInheritedRelationshipBookQuery::create()->find($con);
|
||||||
|
@ -407,7 +405,7 @@ YAML;
|
||||||
$builder->setSchema($schema);
|
$builder->setSchema($schema);
|
||||||
$con = $builder->build();
|
$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');
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
$book = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlBookWithObjectQuery::create(null)->findOne($con);
|
$book = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlBookWithObjectQuery::create(null)->findOne($con);
|
||||||
|
@ -457,7 +455,7 @@ YAML;
|
||||||
$builder->setSchema($schema);
|
$builder->setSchema($schema);
|
||||||
$con = $builder->build();
|
$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');
|
$loader->load(array($filename), 'default');
|
||||||
|
|
||||||
$authors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlDelegateOnPrimaryKeyAuthorQuery::create()->find($con);
|
$authors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\YamlDelegateOnPrimaryKeyAuthorQuery::create()->find($con);
|
||||||
|
|
Loading…
Reference in a new issue