Example #1
0
 /**
  * Get method annotations
  *
  * Also gets class annotations and parent method/class annotations
  *
  * @return AnnotationCollection
  */
 public function getAnnotations()
 {
     // start with all of the method annotations
     $annotationCollection = new AnnotationCollection();
     $annotations = $this->reader->getMethodAnnotations($this->reflectionMethod);
     $annotations = $this->getDynamoAnnotations($annotations);
     $annotationCollection->addAnnotations($annotations);
     // get method's class' annotations
     $reflectionClass = $this->reflectionMethod->getDeclaringClass();
     $this->getAdditionalClassAnnotations($reflectionClass, $annotationCollection);
     // parse parent interfaces too
     $parents = $reflectionClass->getInterfaceNames();
     foreach ($parents as $parent) {
         $parentReflectionClass = new ReflectionClass($parent);
         try {
             // check to see if there is a parent method
             $parentReflectionMethod = $parentReflectionClass->getMethod($this->reflectionMethod->getName());
         } catch (ReflectionException $exception) {
             // parent method does not exist, add parent class annotations
             $this->getAdditionalClassAnnotations($parentReflectionClass, $annotationCollection);
             continue;
         }
         // add parent method/class annotations
         $this->getAdditionalMethodAnnotations($parentReflectionMethod, $annotationCollection);
         $this->getAdditionalClassAnnotations($parentReflectionClass, $annotationCollection);
     }
     return $annotationCollection;
 }
Example #2
0
 private function getFactory($shouldStub = true, $interfaceName = MockInterface::class)
 {
     $interfaceDataProviderFactory = Mockery::mock(InterfaceDataProviderFactory::class);
     $methodModelFactory = Mockery::mock(MethodModelFactory::class);
     $eventDispatcher = Mockery::mock(EventDispatcherInterface::class);
     $interfaceDataProvider = Mockery::mock(InterfaceDataProvider::class);
     $methodDataProvider = Mockery::mock(MethodDataProvider::class);
     $methodModel = Mockery::mock(MethodModel::class);
     $annotationCollection = new AnnotationCollection();
     $annotationCollection->addAnnotations([MockAnnotation::class => new MockAnnotation()]);
     if ($shouldStub) {
         $interfaceDataProviderFactory->shouldReceive('make')->times(1)->with($interfaceName)->andReturn($interfaceDataProvider);
         $interfaceDataProvider->shouldReceive('getNamespace')->times(1)->withNoArgs()->andReturn('Tebru\\Namespace');
         $interfaceDataProvider->shouldReceive('getName')->times(1)->withNoArgs()->andReturn('ClassName');
         $interfaceDataProvider->shouldReceive('getFullName')->times(1)->withNoArgs()->andReturn('\\' . MockInterface::class);
         $interfaceDataProvider->shouldReceive('getMethods')->times(1)->withNoArgs()->andReturn([$methodDataProvider, $methodDataProvider]);
         $methodModelFactory->shouldReceive('make')->times(2)->with(Mockery::type(ClassModel::class), $methodDataProvider)->andReturn($methodModel);
         $methodDataProvider->shouldReceive('getAnnotations')->times(1)->withNoArgs()->andReturn($annotationCollection);
         $methodDataProvider->shouldReceive('getAnnotations')->times(1)->withNoArgs()->andReturn(new AnnotationCollection());
         $eventDispatcher->shouldReceive('dispatch')->times(1)->with(StartEvent::NAME, Mockery::type(StartEvent::class))->andReturnNull();
         $eventDispatcher->shouldReceive('dispatch')->times(1)->with(MethodEvent::NAME, Mockery::type(MethodEvent::class))->andReturnNull();
         $eventDispatcher->shouldReceive('dispatch')->times(1)->with(EndEvent::NAME, Mockery::type(EndEvent::class))->andReturnNull();
         $methodModel->shouldReceive('getName')->times(1)->withNoArgs()->andReturn('testMethod');
     }
     return new ClassModelFactory('Tebru\\Foo', $interfaceDataProviderFactory, $methodModelFactory, $eventDispatcher);
 }
 public function testCanAddMultipleAnnotations()
 {
     $annotation1 = new MockAnnotation();
     $annotation2 = new MockAnnotation();
     $collection = new AnnotationCollection();
     $collection->addAnnotations([$annotation1, $annotation2]);
     $this->assertAttributeSame(['mock' => [$annotation1, $annotation2]], 'annotations', $collection);
 }