function it_should_get_interfaces(ContainerBuilder $container, Definition $resolverDefinition) { $resolverDefinition->hasTag('doctrine.event_listener')->shouldBeCalled()->willReturn(false); $resolverDefinition->addTag('doctrine.event_listener', array('event' => 'loadClassMetadata'))->shouldBeCalled(); $container->hasDefinition('doctrine.orm.listeners.resolve_target_entity')->shouldBeCalled()->willReturn(true); $container->findDefinition('doctrine.orm.listeners.resolve_target_entity')->shouldBeCalled()->willReturn($resolverDefinition); $container->hasParameter(RepositoryInterface::class)->shouldBeCalled()->willReturn(false); $container->hasParameter('spec\\Sylius\\Bundle\\ResourceBundle\\Fixture\\Entity\\Foo')->shouldBeCalled()->willReturn(false); $resolverDefinition->addMethodCall('addResolveTargetEntity', array(RepositoryInterface::class, 'spec\\Sylius\\Bundle\\ResourceBundle\\Fixture\\Entity\\Foo', array()))->shouldBeCalled(); $this->resolve($container, array(RepositoryInterface::class => 'spec\\Sylius\\Bundle\\ResourceBundle\\Fixture\\Entity\\Foo')); }
function it_should_get_interfaces(ContainerBuilder $container, Definition $resolverDefinition) { $resolverDefinition->hasTag('doctrine.event_listener')->willReturn(false); $resolverDefinition->addTag('doctrine.event_listener', ['event' => 'loadClassMetadata'])->shouldBeCalled(); $container->hasDefinition('doctrine.orm.listeners.resolve_target_entity')->willReturn(true); $container->findDefinition('doctrine.orm.listeners.resolve_target_entity')->willReturn($resolverDefinition); $container->hasParameter(RepositoryInterface::class)->willReturn(false); $container->hasParameter(Foo::class)->willReturn(false); $resolverDefinition->addMethodCall('addResolveTargetEntity', [RepositoryInterface::class, Foo::class, []])->shouldBeCalled(); $this->resolve($container, [RepositoryInterface::class => Foo::class]); }
/** * @covers Symfony\Component\DependencyInjection\Definition::addTag * @covers Symfony\Component\DependencyInjection\Definition::getTag * @covers Symfony\Component\DependencyInjection\Definition::getTags * @covers Symfony\Component\DependencyInjection\Definition::hasTag */ public function testTags() { $def = new Definition('stdClass'); $this->assertEquals(array(), $def->getTag('foo'), '->getTag() returns an empty array if the tag is not defined'); $this->assertFalse($def->hasTag('foo')); $this->assertSame($def, $def->addTag('foo'), '->addTag() implements a fluent interface'); $this->assertTrue($def->hasTag('foo')); $this->assertEquals(array(array()), $def->getTag('foo'), '->getTag() returns attributes for a tag name'); $def->addTag('foo', array('foo' => 'bar')); $this->assertEquals(array(array(), array('foo' => 'bar')), $def->getTag('foo'), '->addTag() can adds the same tag several times'); $def->addTag('bar', array('bar' => 'bar')); $this->assertEquals($def->getTags(), array('foo' => array(array(), array('foo' => 'bar')), 'bar' => array(array('bar' => 'bar'))), '->getTags() returns all tags'); }
/** * Check whether this definition has a tag with the given name * * @param string $name The name of the tag * * @return Boolean * * @api * @since 4.0.0 */ public function hasTag($name) { return $this->_underlyingSymfonyDefinition->hasTag($name); }
/** * @param Definition $formType * @param string $serviceId * * @throws \InvalidArgumentException */ public function assertTaggedServiceIsFormType(Definition $formType, $serviceId) { if (!$formType->hasTag('form.type')) { throw new \InvalidArgumentException(sprintf('Service with id "%s" has to be tagged with "form.type".', $serviceId)); } }
/** * @param string $id * @param Definition $definition * @param array $definitionArray */ private function tryHydrateDefinitionForRestoration($id, Definition $definition, array &$definitionArray) { if ($this->container->isLoaded($id) && $definition->hasTag('dumpable')) { $service = $this->container->get($id); if (!$service instanceof DumpableServiceInterface) { throw new ServiceNotDumpableException($id, get_class($service)); } $classProxy = $service->getClassProxy() ?: get_class($service); if (!in_array(self::RESTORABLE_SERVICE_INTERFACE, class_implements($classProxy))) { throw new InvalidServiceProxyException($classProxy); } if (isset($definitionArray['class'])) { if ($classProxy !== $definitionArray['class']) { unset($definitionArray['arguments']); } $definitionArray['class'] = $classProxy; } unset($definitionArray['configurator']); $definitionArray['calls'] = []; $definitionArray['calls'][] = ['restore', ['@service_container', $service->dump()]]; } }