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']);
 }
Exemplo n.º 2
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;
 }