Ejemplo n.º 1
0
 /**
  *
  * @param  string|array $path
  * @param array $options
  * @return FixtureCollection
  */
 public function load($path, array $options = array())
 {
     $collection = new FixtureCollection();
     foreach ($this->loaders as $loader) {
         $data = $loader->load($path, $options);
         $collection->merge($data);
     }
     return $collection;
 }
 public function testExpressionLanguageListenerCreateObject()
 {
     $fixtures = new FixtureCollection(array($this->createFixture('test1', array('key1' => array('foo' => '@expr(object("test2", "key2").test)'))), $this->createFixture('test2', array('key2' => array('test' => '@expr("foo" ~ "bar")')))));
     $this->executor->expects($this->once())->method('createObject')->will($this->returnValue((object) array('test' => 'foobar')));
     $event = new FixtureCollectionEvent($this->createFixtureManagerMock(), $fixtures);
     $this->listener->onPreExecute($event);
     $data1 = $fixtures->get('test1')->get('key1')->getData();
     $data2 = $fixtures->get('test2')->get('key2')->getData();
     $this->assertEquals('foobar', $data1['foo']);
     $this->assertEquals('foobar', $data2['test']);
 }
Ejemplo n.º 3
0
 /**
  *
  * @param mixed $path
  * @param array $options
  * @return FixtureCollection
  */
 public function load($path, array $options = array())
 {
     if (!is_array($path)) {
         return $this->loader->load($path, $options);
     }
     $collection = new FixtureCollection();
     foreach ($path as $p) {
         $c = $this->loader->load($p, $options);
         $collection->merge($c);
     }
     return $collection;
 }
Ejemplo n.º 4
0
 /**
  *
  * @param  string|array $path
  * @param array $options
  * @return FixtureCollection
  */
 public function load($path, array $options = array())
 {
     if (empty($path)) {
         $path = $this->getFixturesByBundles();
     } elseif (!is_array($path)) {
         $path = array($path);
     }
     $collection = new FixtureCollection();
     foreach ($path as $p) {
         $collection->merge($this->loader->load($p));
     }
     return $collection;
 }
Ejemplo n.º 5
0
 public function testLoadFixture()
 {
     $expects = array('user' => array('properties' => array('class' => 'DavidBadura\\Fixtures\\TestObjects\\User', 'constructor' => array(0 => 'name', 1 => 'email')), 'data' => array('david' => array('name' => 'David Badura', 'email' => '*****@*****.**', 'group' => array(0 => '@group:owner', 1 => '@group:developer'), 'role' => array(0 => '@role:admin')), 'other' => array('name' => 'Somebody', 'email' => '*****@*****.**', 'group' => array(0 => '@group:developer'), 'role' => array(0 => '@role:user')))));
     $collection = FixtureCollection::create($expects);
     $data = $this->loader->load(__DIR__ . '/../TestResources/fixtures/user.yml');
     $this->assertEquals($collection, $data);
 }
Ejemplo n.º 6
0
 /**
  *
  * @param  string|array $path
  * @param array $options
  * @return FixtureCollection
  */
 public function load($path, array $options = array())
 {
     if (!file_exists($path)) {
         throw new \RuntimeException(sprintf('"%s" dir or file not found', $path));
     }
     if (is_file($path)) {
         return $this->loader->load($path, $options);
     }
     $finder = new Finder();
     $finder->in($path)->files();
     $collection = new FixtureCollection();
     foreach ($finder as $file) {
         $col = $this->loader->load(realpath($file->getPathname()), $options);
         $collection->merge($col);
     }
     return $collection;
 }
Ejemplo n.º 7
0
 public function testLoadFixtures()
 {
     $user = array('user' => array('properties' => array('class' => 'DavidBadura\\Fixtures\\TestObjects\\User', 'constructor' => array(0 => 'name', 1 => 'email')), 'data' => array('david' => array('name' => 'David Badura', 'email' => '*****@*****.**', 'group' => array(0 => '@group:owner', 1 => '@group:developer'), 'role' => array(0 => '@role:admin')), 'other' => array('name' => 'Somebody', 'email' => '*****@*****.**', 'group' => array(0 => '@group:developer'), 'role' => array(0 => '@role:user')))));
     $group = array('group' => array('properties' => array('class' => 'DavidBadura\\Fixtures\\TestObjects\\Group'), 'data' => array('developer' => array('name' => 'Developer', 'leader' => '@@user:david'))));
     $role = array('role' => array('properties' => array('class' => 'DavidBadura\\Fixtures\\TestObjects\\Role'), 'data' => array('admin' => array('name' => 'Admin'), 'user' => array('name' => 'User'))));
     $this->assertEquals(FixtureCollection::create($user), $this->loader->load(__DIR__ . '/../TestResources/chainFixtures/user.yml'));
     $this->assertEquals(FixtureCollection::create($group), $this->loader->load(__DIR__ . '/../TestResources/chainFixtures/groups.json'));
     $this->assertEquals(FixtureCollection::create($role), $this->loader->load(__DIR__ . '/../TestResources/chainFixtures/roles.php'));
 }
Ejemplo n.º 8
0
 /**
  *
  * @param  mixed $path
  * @param array $options
  * @return FixtureCollection
  */
 public function load($path, array $options = array())
 {
     $collection = $this->callback($path, $options);
     if (is_array($collection)) {
         return FixtureCollection::create($collection);
     } elseif ($collection instanceof FixtureCollection) {
         return $collection;
     }
     throw new FixtureException('the callback function must return a FixtureCollection instance or a fixture array');
 }
Ejemplo n.º 9
0
 public function testServiceProvider()
 {
     $serviceProvicer = new \DavidBadura\Fixtures\ServiceProvider\ServiceProvider();
     $fixtureManager = new FixtureManagerPublicMethods($this->loader, $this->executor, $this->persister, $serviceProvicer, $this->eventDispatcher);
     $faker = \Faker\Factory::create();
     $fixtureManager->addService('faker', $faker);
     $data = array('user' => array('data' => array('user{0..2}' => array('name' => '<faker::name()>', 'email' => '<faker::email()>', 'random' => 'blubbtest', 'text' => '<faker::sentence(3)>'))));
     $collection = FixtureCollection::create($data);
     $fixtureManager->publicReplaceMultiPlaceholder($collection);
     $fixtureManager->publicReplaceServicePlaceholder($collection);
     $fixture = $collection->get('user');
     $user0 = $fixture->get('user0')->getData();
     $user1 = $fixture->get('user1')->getData();
     $user2 = $fixture->get('user2')->getData();
     $this->assertEquals(3, count($fixture));
     $this->assertTrue(strpos($user0['email'], '@') !== false);
     $this->assertTrue(strpos($user1['email'], '@') !== false);
     $this->assertTrue(strpos($user2['email'], '@') !== false);
 }
Ejemplo n.º 10
0
 /**
  *
  * @param  string $path
  * @param array $options
  * @return FixtureCollection
  */
 public function load($path, array $options = array())
 {
     $data = json_decode(file_get_contents($path), true);
     return FixtureCollection::create($data);
 }
Ejemplo n.º 11
0
 /**
  *
  * @param  string $path
  * @param array $options
  * @return FixtureCollection
  */
 public function load($path, array $options = array())
 {
     $data = Parser::fromFile($path);
     return FixtureCollection::create($data);
 }
Ejemplo n.º 12
0
 /**
  *
  * @param  mixed $path
  * @param array $options
  * @return FixtureCollection
  */
 public function load($path, array $options = array())
 {
     $data = (include $path);
     return FixtureCollection::create($data);
 }
Ejemplo n.º 13
0
 /**
  * @param array $data
  * @param FixtureCollection $collection
  * @return array
  */
 protected function prepareDataForFinalize($data, FixtureCollection $collection)
 {
     array_walk_recursive($data, function (&$value, $key) use($collection) {
         if (!is_string($value)) {
             return;
         }
         if (preg_match('/^@@([\\w-_]*):([\\w-_]*)$/', $value, $hit)) {
             if (!$collection->has($hit[1]) || !$collection->get($hit[1])->get($hit[2])) {
                 throw new ReferenceNotFoundException($hit[1], $hit[2]);
             }
             $object = $collection->get($hit[1])->get($hit[2])->getObject();
             if (!$object) {
                 throw new FixtureException(sprintf("Object for %s:%s does not exist", $hit[1], $hit[2]));
             }
             $value = $object;
         }
     });
     return $data;
 }
Ejemplo n.º 14
0
 /**
  *
  * @param  string $path
  * @param array $options
  * @return FixtureCollection
  */
 public function load($path, array $options = array())
 {
     $data = Yaml::parse(file_get_contents($path));
     return FixtureCollection::create($data);
 }