Apply the processor(s)
public process ( Closur\Closure | Closur\Closure[] $processors = null ) | ||
$processors | Closur\Closure | Closur\Closure[] | One or more processors |
public function testMergeOperationsWithSamePath() { $swagger = new Swagger([]); $analysis = new Analysis([$swagger, new Get(['path' => '/comments']), new Post(['path' => '/comments'])]); $analysis->process(new MergeIntoSwagger()); $analysis->process(new BuildPaths()); $this->assertCount(1, $swagger->paths); $path = $swagger->paths[0]; $this->assertSame('/comments', $path->path); $this->assertInstanceOf('\\Swagger\\Annotations\\Path', $path); $this->assertInstanceOf('\\Swagger\\Annotations\\Get', $path->get); $this->assertInstanceOf('\\Swagger\\Annotations\\Post', $path->post); $this->assertNull($path->put); }
public function testCleanUnmergedProcessor() { $comment = <<<END @SWG\\Info( title="Info only has one contact field.", version="test", ) @SWG\\License( name="MIT", @SWG\\Contact( name="Batman" ) ) END; $analysis = new Analysis($this->parseComment($comment)); $this->assertCount(3, $analysis->annotations); $analysis->process(new MergeIntoSwagger()); $this->assertCount(4, $analysis->annotations); $before = $analysis->split(); $this->assertCount(2, $before->merged->annotations, 'Generated @SWG\\Swagger + @SWG\\Info'); $this->assertCount(2, $before->unmerged->annotations, '@SWG\\License + @SWG\\Contact'); $this->assertCount(0, $analysis->swagger->_unmerged); $analysis->validate(); // Validation fails to detect the unmerged annotations. // CleanUnmerged should place the unmerged annotions into the swagger->_unmerged array. $analysis->process(new CleanUnmerged()); $between = $analysis->split(); $this->assertCount(2, $between->merged->annotations, 'Generated @SWG\\Swagger + @SWG\\Info'); $this->assertCount(2, $between->unmerged->annotations, '@SWG\\License + @SWG\\Contact'); $this->assertCount(2, $analysis->swagger->_unmerged); // 1 would also be oke, Could a'Only the @SWG\License' $this->assertSwaggerLogEntryStartsWith('Unexpected @SWG\\License(), expected to be inside @SWG\\Info in '); $this->assertSwaggerLogEntryStartsWith('Unexpected @SWG\\Contact(), expected to be inside @SWG\\Info in '); $analysis->validate(); // When a processor places a previously unmerged annotation into the swagger obect. $license = $analysis->getAnnotationsOfType('Swagger\\Annotations\\License')[0]; $contact = $analysis->getAnnotationsOfType('Swagger\\Annotations\\Contact')[0]; $analysis->swagger->info->contact = $contact; $this->assertCount(1, $license->_unmerged); $analysis->process(new CleanUnmerged()); $this->assertCount(0, $license->_unmerged); $after = $analysis->split(); $this->assertCount(3, $after->merged->annotations, 'Generated @SWG\\Swagger + @SWG\\Info + @SWG\\Contact'); $this->assertCount(1, $after->unmerged->annotations, '@SWG\\License'); $this->assertCount(1, $analysis->swagger->_unmerged); $this->assertSwaggerLogEntryStartsWith('Unexpected @SWG\\License(), expected to be inside @SWG\\Info in '); $analysis->validate(); }
public function testRegisterProcessor() { $counter = 0; $analysis = new Analysis(); $analysis->process(); $this->assertSame(0, $counter); $countProcessor = function (Analysis $a) use(&$counter) { $counter++; }; Analysis::registerProcessor($countProcessor); $analysis->process(); $this->assertSame(1, $counter); Analysis::unregisterProcessor($countProcessor); $analysis->process(); $this->assertSame(1, $counter); }
public function testProcessor() { $swagger = new Swagger([]); $info = new Info([]); $analysis = new Analysis([$swagger, $info]); $this->assertNull($analysis->swagger); $this->assertNull($swagger->info); $analysis->process(new MergeIntoSwagger()); $this->assertInstanceOf('Swagger\\Annotations\\Swagger', $analysis->swagger); $this->assertSame($info, $swagger->info); $this->assertCount(0, $analysis->unmerged()->annotations); }
/** * {@inheritDoc} */ public function getServiceConfig() { return array('aliases' => array('service.swagger' => 'Swagger\\Annotations\\Swagger'), 'factories' => array('SwaggerModule\\Options\\ModuleOptions' => function ($serviceManager) { $config = $serviceManager->get('Config'); $config = isset($config['swagger']) ? $config['swagger'] : null; if ($config === null) { throw new RuntimeException('Configuration for SwaggerModule was not found'); } return new SwaggerModuleOptions($config); }, 'Swagger\\Annotations\\Swagger' => function ($serviceManager) { /** @var $options \SwaggerModule\Options\ModuleOptions */ $options = $serviceManager->get('SwaggerModule\\Options\\ModuleOptions'); $analyser = new SwaggerStaticAnalyser(); $analysis = new SwaggerAnalysis(); $processors = SwaggerAnalysis::processors(); // Crawl directory and parse all files $paths = $options->getPaths(); foreach ($paths as $directory) { $finder = SwaggerUtil::finder($directory); foreach ($finder as $file) { $analysis->addAnalysis($analyser->fromFile($file->getPathname())); } } // Post processing $analysis->process($processors); // Validation (Generate notices & warnings) $analysis->validate(); // Pass options to analyzer $resourceOptions = $options->getResourceOptions(); if (!empty($resourceOptions['defaultBasePath'])) { $analysis->swagger->basePath = $resourceOptions['defaultBasePath']; } if (!empty($resourceOptions['defaultHost'])) { $analysis->swagger->host = $resourceOptions['defaultHost']; } if (!empty($resourceOptions['schemes'])) { $analysis->swagger->schemes = $resourceOptions['schemes']; } return $analysis->swagger; })); }