Beispiel #1
0
 /**
  * Loads a fixture file into an object container
  *
  * @param string|array $file filename to load data from or data array
  * @param object       $container object container
  * @param array        $options available options:
  *                                - providers: an array of additional faker providers
  *                                - locale: the faker locale
  */
 public static function load($file, $container, array $options = array())
 {
     $defaults = array('locale' => 'en_US', 'providers' => array());
     $options = array_merge($defaults, $options);
     if (is_string($file) && preg_match('{\\.ya?ml(\\.php)?$}', $file)) {
         $loader = new Loader\Yaml($options['locale'], $options['providers']);
     } elseif (is_string($file) && preg_match('{\\.php$}', $file) || is_array($file)) {
         $loader = new Loader\Base($options['locale'], $options['providers']);
     } else {
         throw new \InvalidValueException('Unknown file/data type: ' . gettype($file) . ' (' . json_encode($file) . ')');
     }
     if ($container instanceof ObjectManager) {
         $persister = new ORM\Doctrine($container);
     } else {
         throw new \InvalidValueException('Unknown container type ' . get_class($container));
     }
     $objects = $loader->load($file);
     $persister->persist($objects);
     return $objects;
 }
 /**
  * {@inheritDoc}
  */
 public function load($file)
 {
     ob_start();
     $loader = $this;
     $includeWrapper = function () use($file, $loader) {
         return include $file;
     };
     $data = $includeWrapper();
     if (true !== $data) {
         $yaml = ob_get_clean();
         $data = YamlParser::parse($yaml);
     }
     if (!is_array($data)) {
         throw new \UnexpectedValueException('Yaml files must parse to an array of data');
     }
     return parent::load($data);
 }
Beispiel #3
0
 /**
  * {@inheritDoc}
  */
 public function load($file)
 {
     ob_start();
     $loader = $this;
     $includeWrapper = function () use($file, $loader) {
         return include $file;
     };
     $data = $includeWrapper();
     if (true !== $data) {
         $yaml = ob_get_clean();
         $data = YamlParser::parse($yaml);
     }
     if (!is_array($data)) {
         throw new \UnexpectedValueException('Yaml files must parse to an array of data');
     }
     foreach ($data as $key => $value) {
         if ($key == "Victoire\\Bundle\\UserBundle\\Entity\\User") {
             $data[$this->userClass] = $value;
         }
         unset($data[$key]);
     }
     return parent::load($data);
 }
Beispiel #4
0
 public function load($data)
 {
     $this->persist(parent::load($data));
 }
 /**
  * @expectedException \RuntimeException
  */
 public function testUniqueValuesException()
 {
     $loader = new Base("en_US", array(new FakerProvider()));
     $res = $loader->load(array(self::USER => array('user{0..1}' => array('username(unique)' => '<fooGenerator()>'))));
 }
Beispiel #6
0
 public function testConstructorCustomProviders()
 {
     $loader = new Base('en_US', array(new FakerProvider()));
     $res = $loader->load(array(self::USER => array('user0' => array('username' => '<fooGenerator>'))));
     $this->assertEquals('foo', $res[0]->username);
 }
 public function testAtLiteral()
 {
     $loader = new Base('en_US', array(new FakerProvider()));
     $res = $loader->load(array(self::USER => array('user' => array('__construct' => array('\\@<fooGenerator()> \\\\@foo \\\\\\@foo \\foo')))));
     $this->assertInstanceOf(self::USER, $res['user']);
     $this->assertSame('@foo \\@foo \\@foo \\foo', $res['user']->username);
 }
 /**
  * {@inheritDoc}
  */
 public function load($file)
 {
     $data = $this->parse($file);
     return parent::load($data);
 }