Exemplo n.º 1
0
 public function testLoader()
 {
     $locator = new FileLocator(__DIR__);
     $loader = new YamlFileLoader($locator);
     $conf = $loader->load(__DIR__ . '/fixtures/services.yml');
     static::assertInternalType('array', $conf);
     static::assertArrayHasKey('parameters', $conf);
     static::assertCount(1, $conf['parameters']);
     $parameter = $conf['parameters'][0];
     static::assertInstanceOf('G\\Yaml2Pimple\\Parameter', $parameter);
     /** @var \G\Yaml2Pimple\Parameter $parameter */
     static::assertEquals('name', $parameter->getParameterName());
     static::assertEquals('Gonzalo', $parameter->getParameterValue());
     static::assertArrayHasKey('services', $conf);
     static::assertArrayHasKey('App', $conf['services']);
     static::assertArrayHasKey('Curl', $conf['services']);
     static::assertArrayHasKey('Proxy', $conf['services']);
     $app = $conf['services']['App'];
     $curl = $conf['services']['Curl'];
     $proxy = $conf['services']['Proxy'];
     static::assertInstanceOf('G\\Yaml2Pimple\\Definition', $app);
     static::assertInstanceOf('G\\Yaml2Pimple\\Definition', $curl);
     static::assertInstanceOf('G\\Yaml2Pimple\\Definition', $proxy);
     /** @var \G\Yaml2Pimple\Definition $app */
     /** @var \G\Yaml2Pimple\Definition $curl */
     /** @var \G\Yaml2Pimple\Definition $proxy */
     static::assertEquals('\\test\\fixtures\\App', $app->getClass());
     static::assertEquals(array('@Proxy', '%name%'), $app->getArguments());
     static::assertEquals('\\test\\fixtures\\Curl', $curl->getClass());
     static::assertEquals(array(), $curl->getArguments());
     static::assertEquals('\\test\\fixtures\\Proxy', $proxy->getClass());
     static::assertEquals(array('@Curl'), $proxy->getArguments());
 }
Exemplo n.º 2
0
 /**
  * @param \G\Yaml2Pimple\Loader\YamlFileLoader $loader
  * @param \G\Yaml2Pimple\ResourceCollection $resources
  * @param \G\Yaml2Pimple\FileCache $cache
  */
 public function it_adds_cache_depending_classes_to_resources($loader, $resources, $cache)
 {
     $this->setCache($cache);
     $cache->contains(Argument::any())->shouldBeCalled()->willReturn(false);
     $cache->setResources(Argument::any())->shouldBeCalled();
     $cache->save(Argument::type('string'), Argument::type('array'))->shouldBeCalled();
     $dependingClasses = array('\\G\\Yaml2Pimple\\Loader\\CacheLoader', '\\G\\Yaml2Pimple\\Parameter', '\\G\\Yaml2Pimple\\Definition');
     foreach ($dependingClasses as $class) {
         $refl = new \ReflectionClass($class);
         $testResource = new FileResource($refl->getFileName());
         $resources->add($testResource)->shouldBeCalled();
     }
     $resources->all()->shouldBeCalled();
     $resources->clear()->shouldBeCalled();
     $data = array();
     $loader->load(Argument::type('string'))->willReturn($data);
     $this->load('test.yaml')->shouldReturn($data);
 }