Exemplo n.º 1
0
 public function testCanGenerate()
 {
     $classModelFactory = Mockery::mock(ClassModelFactory::class);
     $classModelCacher = Mockery::mock(ClassModelCacher::class);
     $classModel = Mockery::mock(ClassModel::class);
     $classModelFactory->shouldReceive('make')->times(1)->with('Foo')->andReturn($classModel);
     $classModelCacher->shouldReceive('write')->times(1)->with($classModel)->andReturnNull();
     $generator = new Generator($classModelFactory, $classModelCacher);
     $result = $generator->createAndWrite('Foo');
     $this->assertInstanceOf(Generator::class, $generator);
 }
Exemplo n.º 2
0
 public function testCanUseAllSetters()
 {
     $namespacePrefix = 'Tebru\\Test';
     $parameterDataProviderFactory = Mockery::mock(ParameterDataProviderFactory::class);
     $reader = Mockery::mock(Reader::class);
     $annotationDataProviderFactory = Mockery::mock(AnnotationDataProviderFactory::class);
     $methodDataProviderFactory = Mockery::mock(MethodDataProviderFactory::class);
     $interfaceDataProviderFactory = Mockery::mock(InterfaceDataProviderFactory::class);
     $parameterModelFactory = Mockery::mock(ParameterModelFactory::class);
     $methodModelFactory = Mockery::mock(MethodModelFactory::class);
     $eventDispatcher = Mockery::mock(EventDispatcherInterface::class);
     $classModelFactory = Mockery::mock(ClassModelFactory::class);
     $cacheDir = '';
     $filesystem = Mockery::mock(Filesystem::class);
     $builderFactory = Mockery::mock(BuilderFactory::class);
     $lexer = Mockery::mock(Lexer::class);
     $parser = Mockery::mock(ParserAbstract::class);
     $traverser = Mockery::mock(NodeTraverserInterface::class);
     $classModelTransformer = Mockery::mock(ClassModelTransformer::class);
     $printer = Mockery::mock(PrettyPrinterAbstract::class);
     $classModelCacher = Mockery::mock(ClassModelCacher::class);
     $traverser->shouldReceive('addVisitor')->with(Mockery::type(NameResolver::class))->andReturnNull();
     $generator = Generator::builder()->setNamespacePrefix($namespacePrefix)->setParameterDataProviderFactory($parameterDataProviderFactory)->setReader($reader)->setAnnotationDataProviderFactory($annotationDataProviderFactory)->setMethodDataProviderFactory($methodDataProviderFactory)->setInterfaceDataProviderFactory($interfaceDataProviderFactory)->setParameterModelFactory($parameterModelFactory)->setMethodModelFactory($methodModelFactory)->setEventDispatcher($eventDispatcher)->setClassModelFactory($classModelFactory)->setCacheDir($cacheDir)->setFilesystem($filesystem)->setBuilderFactory($builderFactory)->setLexer($lexer)->setParser($parser)->setTraverser($traverser)->setClassModelTransformer($classModelTransformer)->setPrinter($printer)->setClassModelCacher($classModelCacher)->build();
     $this->assertInstanceOf(Generator::class, $generator);
 }
Exemplo n.º 3
0
 /**
  * Creates cache files based on registered services
  *
  * @return int Number of services cached
  */
 public function createCache()
 {
     foreach ($this->services as $service) {
         $this->generator->createAndWrite($service);
     }
     return count($this->services);
 }
 /**
  * Build a retrofit instance
  *
  * @return Retrofit
  */
 public function build()
 {
     if (null === $this->eventDispatcher) {
         $this->eventDispatcher = new EventDispatcher();
     }
     $this->eventDispatcher->addListener(StartEvent::NAME, new DynamoStartListener());
     $this->eventDispatcher->addListener(MethodEvent::NAME, new DynamoMethodListener(new HandlerFactory(), new MethodBodyBuilderFactory()));
     if (null === $this->cacheDir) {
         $this->cacheDir = sys_get_temp_dir() . '/retrofit';
     }
     if (null === $this->serviceResolver) {
         $this->serviceResolver = new ServiceResolver();
     }
     if (null === $this->generator) {
         $this->generator = Generator::builder()->setNamespacePrefix(Retrofit::NAMESPACE_PREFIX)->setCacheDir($this->cacheDir . '/retrofit')->setEventDispatcher($this->eventDispatcher)->build();
     }
     return new Retrofit($this->serviceResolver, $this->generator);
 }