示例#1
0
 public function testCanCreateMethodModel()
 {
     $parameterModelFactory = Mockery::mock(ParameterModelFactory::class);
     $classModel = Mockery::mock(ClassModel::class);
     $methodDataProvider = Mockery::mock(MethodDataProvider::class);
     $parameterDataProvider = Mockery::mock(ParameterDataProvider::class);
     $parameterModel = Mockery::mock(ParameterModel::class);
     $methodDataProvider->shouldReceive('getName')->times(1)->withNoArgs()->andReturn('testMethod');
     $methodDataProvider->shouldReceive('getParameters')->times(1)->withNoArgs()->andReturn([$parameterDataProvider]);
     $parameterModelFactory->shouldReceive('make')->times(1)->with(Mockery::type(MethodModel::class), $parameterDataProvider)->andReturn($parameterModel);
     $parameterModel->shouldReceive('getName')->times(1)->withNoArgs()->andReturn('testParameter');
     $factory = new MethodModelFactory($parameterModelFactory);
     $methodModel = $factory->make($classModel, $methodDataProvider);
     $this->assertInstanceOf(MethodModel::class, $methodModel);
     $this->assertSame('testMethod', $methodModel->getName());
     $this->assertCount(1, $methodModel->getParameters());
 }
示例#2
0
 /**
  * Create a new class model from an interface
  *
  * @param string $interfaceName
  * @return ClassModel
  */
 public function make($interfaceName)
 {
     $interfaceDataProvider = $this->interfaceDataProviderFactory->make($interfaceName);
     $namespace = $this->namespacePrefix . '\\' . $interfaceDataProvider->getNamespace();
     $classModel = new ClassModel($namespace, $interfaceDataProvider->getName(), $interfaceDataProvider->getFullName());
     // dispatch the start event
     $this->eventDispatcher->dispatch(StartEvent::NAME, new StartEvent($classModel));
     $methods = $interfaceDataProvider->getMethods();
     foreach ($methods as $methodDataProvider) {
         $methodModel = $this->methodModelFactory->make($classModel, $methodDataProvider);
         $annotationCollection = $methodDataProvider->getAnnotations();
         // skip methods that don't have any annotations
         $annotations = $annotationCollection->getAnnotations();
         if (empty($annotations)) {
             continue;
         }
         // dispatch the method event
         $this->eventDispatcher->dispatch(MethodEvent::NAME, new MethodEvent($methodModel, $annotationCollection));
         $classModel->addMethod($methodModel);
     }
     // dispatch the end event
     $this->eventDispatcher->dispatch(EndEvent::NAME, new EndEvent($classModel));
     return $classModel;
 }