/** * {@inheritdoc} */ public function process(ContainerBuilder $container) { foreach ($container->findTaggedServiceIds('es.filter_manager') as $managerId => $managerTags) { $managerDefinition = $container->getDefinition($managerId); foreach ($container->findTaggedServiceIds('ongr_filter_manager.filter') as $filterId => $filterTags) { foreach ($filterTags as $tag) { if (array_key_exists('manager', $tag) && $managerId === ONGRFilterManagerExtension::getFilterManagerId($tag['manager'])) { if (!array_key_exists('filter_name', $tag)) { throw new InvalidConfigurationException(sprintf('Filter tagged with `%s` must have `filter_name` set.', $filterId)); } $this->addFilter($managerDefinition, $tag['filter_name'], $filterId); $container->setDefinition($managerId, $managerDefinition); } } } $this->checkManager($managerDefinition, "Manager '{$managerId}' does not have any filters."); } }
/** * Test if services are created by compiler pass. * * @param string|null $manager * @param array $filters * * @dataProvider filterTestProvider */ public function testFilterImplementationException($manager, $filters) { // Check filter definitions. foreach ($filters as $filter => $class) { /** @var FilterInterface $filterInstance */ $filterInstance = $this->container->get(ONGRFilterManagerExtension::getFilterId($filter), ContainerInterface::NULL_ON_INVALID_REFERENCE); $this->assertInstanceOf($class, $filterInstance); } if ($manager === null) { return; } /** @var FiltersManager $managerInstance */ $managerInstance = $this->container->get(ONGRFilterManagerExtension::getFilterManagerId($manager), ContainerInterface::NULL_ON_INVALID_REFERENCE); $this->assertInstanceOf('ONGR\\FilterManagerBundle\\Search\\FiltersManager', $managerInstance); $filterContainer = $this->getFilterContainer($managerInstance); $actualFilters = $filterContainer->all(); $this->assertSameSize($filters, $actualFilters); foreach ($filters as $filter => $class) { $this->assertArrayHasKey($filter, $actualFilters); $this->assertInstanceOf($class, $actualFilters[$filter]); $filterInstance = $this->container->get(ONGRFilterManagerExtension::getFilterId($filter), ContainerInterface::NULL_ON_INVALID_REFERENCE); $this->assertSame($filterInstance, $actualFilters[$filter]); } }
/** * Tests if exception is thrown when filter names are duplicated. * * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @expectedExceptionMessage Found duplicate filter name `test_sorting` in `match` filter */ public function testConfigWithDuplicateNameException() { $config = array_replace_recursive($this->getDummyConfig(), ['ongr_filter_manager' => ['filters' => ['match' => ['test_sorting' => ['request_field' => 'test_q', 'field' => 'test_title']]]]]); $container = new ContainerBuilder(); $extension = new ONGRFilterManagerExtension(); $extension->load($config, $container); }