コード例 #1
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);
 }
コード例 #2
0
 public function testCanIterate()
 {
     $annotation = new MockAnnotation();
     $collection = new AnnotationCollection();
     $collection->addAnnotation($annotation);
     foreach ($collection as $key => $a) {
         $this->assertSame('mock', $key);
         $this->assertSame([$annotation], $a);
     }
 }
コード例 #3
0
 /**
  * Add unique class annotations to collection
  *
  * @param ReflectionClass $reflectionClass
  * @param AnnotationCollection $annotationCollection
  */
 private function getAdditionalClassAnnotations(ReflectionClass $reflectionClass, AnnotationCollection $annotationCollection)
 {
     $annotations = $this->reader->getClassAnnotations($reflectionClass);
     $annotations = $this->getDynamoAnnotations($annotations);
     foreach ($annotations as $annotation) {
         // skip annotations that already exist on method
         if ($annotationCollection->exists($annotation->getName())) {
             continue;
         }
         $annotationCollection->addAnnotation($annotation);
     }
 }
コード例 #4
0
 private function getBodyAnnotation()
 {
     return $this->annotations->get(Body::NAME);
 }
コード例 #5
0
 public function testGetResponseType()
 {
     $method = new MethodModel(new ClassModel('Foo', 'FooClass', 'FooInterface'), 'fooMethod');
     $collection = new AnnotationCollection();
     $collection->addAnnotation(new ResponseType(['value' => 'array']));
     $provider = new AnnotationProvider($collection, $method);
     $returnType = $provider->getResponseType();
     $this->assertSame('array', $returnType);
 }