public function testSetDefinition() { $tubePressDefinition = $this->mock('tubepress_internal_ioc_Definition'); $symfonyDefinition = $this->mock('\\Symfony\\Component\\DependencyInjection\\Definition'); $tubePressDefinition->shouldReceive('getUnderlyingSymfonyDefinition')->once()->andReturn($symfonyDefinition); $this->assertFalse($this->_sut->has('x')); $this->assertFalse($this->_sut->hasDefinition('x')); $this->_sut->setDefinition('x', $tubePressDefinition); $this->assertTrue($this->_sut->has('x')); $this->assertTrue($this->_sut->hasDefinition('x')); $result = $this->_sut->getDefinition('x'); $this->assertInstanceOf('tubepress_api_ioc_DefinitionInterface', $result); }
public function testLoad() { $this->prepareForLoad(); $this->_sut->load($this->_mockContainer); $realContainerBuilder = new tubepress_internal_ioc_ContainerBuilder(); $realContainerBuilder->registerExtension($this->_sut); foreach ($this->getExpectedExternalServicesMap() as $id => $type) { if (is_string($type)) { $realContainerBuilder->set($id, $this->mock($type)); } else { $realContainerBuilder->set($id, $type); } } foreach ($this->getExpectedParameterMap() as $key => $value) { $realContainerBuilder->setParameter($key, $value); } foreach ($this->_expectedDecoratedServices as $serviceId) { $decoratedDefinition = new tubepress_internal_ioc_Definition($serviceId); $decoratedDefinition->setFactoryClass('Mockery'); $decoratedDefinition->setFactoryMethod('mock'); $decoratedDefinition->addArgument($serviceId); $realContainerBuilder->setDefinition(strtolower($serviceId), $decoratedDefinition); } $this->preCompile($realContainerBuilder); $realContainerBuilder->compile(); $this->postCompile($realContainerBuilder); foreach ($this->_expectedServiceConstructions as $id => $type) { $this->assertTrue($realContainerBuilder->hasDefinition($id), "Expected that container has definition for {$id}"); $this->assertTrue($realContainerBuilder->has($id), "Expected that container has definition for {$id}"); $service = $realContainerBuilder->get($id); if (is_string($type)) { $this->assertInstanceOf($type, $service, "{$id} is not an instance of {$type} (actually is " . get_class($service) . ')'); } else { /** * @var $def tubepress_api_ioc_DefinitionInterface */ $def = $type; $this->assertInstanceOf($def->getClass(), $service); } } }