/** * @test */ public function reduceTargetClassNamesFiltersAllClassesNotHavingAMethodWithTheGivenAnnotation() { $availableClassNames = ['TestPackage\\Subpackage\\Class1', 'TestPackage\\Class2', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'TestPackage\\Subpackage2\\Class4']; sort($availableClassNames); $availableClassNamesIndex = new Aop\Builder\ClassNameIndex(); $availableClassNamesIndex->setClassNames($availableClassNames); $mockReflectionService = $this->getMockBuilder(ReflectionService::class)->disableOriginalConstructor()->getMock(); $mockReflectionService->expects($this->any())->method('getClassesContainingMethodsAnnotatedWith')->with('SomeAnnotationClass')->will($this->returnValue(['TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3', 'SomeMoreClass'])); $methodAnnotatedWithFilter = new Aop\Pointcut\PointcutMethodAnnotatedWithFilter('SomeAnnotationClass'); $methodAnnotatedWithFilter->injectReflectionService($mockReflectionService); $expectedClassNames = ['TestPackage\\Subpackage\\Class1', 'TestPackage\\Subpackage\\SubSubPackage\\Class3']; sort($expectedClassNames); $expectedClassNamesIndex = new Aop\Builder\ClassNameIndex(); $expectedClassNamesIndex->setClassNames($expectedClassNames); $result = $methodAnnotatedWithFilter->reduceTargetClassNames($availableClassNamesIndex); $this->assertEquals($expectedClassNamesIndex, $result, 'The wrong class names have been filtered'); }
/** * Takes a method annotation filter pattern and adds a so configured method annotation filter to the * filter composite object. * * @param string $operator The operator * @param string $annotationPattern The pattern expression as configuration for the method annotation filter * @param PointcutFilterComposite $pointcutFilterComposite An instance of the pointcut filter composite. The result (ie. the method annotation filter) will be added to this composite object. * @return void */ protected function parseDesignatorMethodAnnotatedWith($operator, $annotationPattern, PointcutFilterComposite $pointcutFilterComposite) { $annotationPropertyConstraints = []; $this->parseAnnotationPattern($annotationPattern, $annotationPropertyConstraints); $filter = new PointcutMethodAnnotatedWithFilter($annotationPattern, $annotationPropertyConstraints); $filter->injectReflectionService($this->reflectionService); $filter->injectSystemLogger($this->objectManager->get(SystemLoggerInterface::class)); $pointcutFilterComposite->addFilter($operator, $filter); }