/** * Checks if registered event subscribers use correct method references. * * @param TaggedService $service * @dataProvider getEventSubscribers */ public function testRegisteredEventSubscribers(TaggedService $service = null) { if ($service === null) { // No event subscribers registered, nothing to test. return; } $creator = new ServiceCreator($this->getContainer()); /* @var $subscriber EventSubscriberInterface */ $subscriber = $creator->create($service->getServiceId()); $message = 'Service "%s" is not a valid event subscriber.'; $this->assertThat($subscriber, new IsEventSubscriberConstraint(), sprintf($message, $service->getServiceId())); }
/** * Checks if registered Twig extensions implement the correct interface. * * @param TaggedService $service * @dataProvider getTwigExtensions */ public function testRegisteredTwigExtensionsImplementCorrectInterface(TaggedService $service = null) { if ($service === null) { // No twig extensions registered, nothing to test. return; } $creator = new ServiceCreator($this->getContainer()); /* @var $extension \Twig_ExtensionInterface */ $extension = $creator->create($service->getServiceId()); $message = 'Service "%s" is tagged as Twig extension, but it does not implement the required interface.'; $message = sprintf($message, $service->getServiceId()); $this->assertInstanceOf('\\Twig_ExtensionInterface', $extension, $message); }
/** * Checks if the validators that are configured in the container are aliased in Symfony Versions < 2.7. * * @param TaggedService $service * @dataProvider getValidators */ public function testRegisteredValidatorsAreAliasedInOlderSymfonyVersions(TaggedService $service = null) { if ($service === null) { // No validators registered, nothing to test. return; } if (defined('Symfony\\Component\\HttpKernel\\Kernel::VERSION') && version_compare(Kernel::VERSION, '2.7', '>=')) { // As of Symfony 2.7, validator services don't need to be aliased in every case. return; } $tagDefinition = $service->getTagDefinition(); $message = 'An alias must be defined for validation service "%s".'; $message = sprintf($message, $service->getServiceId()); $this->assertArrayHasKey('alias', $tagDefinition, $message); }
/** * Checks if the aliases for form types and their names are equal. * * Form types cannot be used if this is not the case. * * @param TaggedService|null $service * @dataProvider getFormTypes */ public function testFormTypeAliasAndNameAreEqual(TaggedService $service = null) { if ($service === null) { // No form types registered, nothing to test. return; } $creator = new ServiceCreator($this->getContainer()); /* @var $type \Symfony\Component\Form\FormTypeInterface */ $type = $creator->create($service->getServiceId()); $message = 'Service "%s" is tagged as form type, but it does not implement the required interface.'; $message = sprintf($message, $service->getServiceId()); $this->assertInstanceOf('\\Symfony\\Component\\Form\\FormTypeInterface', $type, $message); $tagDefinition = $service->getTagDefinition(); $message = 'An alias must be defined for form type "%s".'; $message = sprintf($message, $service->getServiceId()); $this->assertArrayHasKey('alias', $service->getTagDefinition(), $message); $message = 'Form type name and assigned alias must match, but service "%s" ' . 'uses "%s" as name and "%s" as alias.'; $message = sprintf($message, $service->getServiceId(), $type->getName(), $tagDefinition['alias']); $this->assertEquals($type->getName(), $tagDefinition['alias'], $message); }