mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-08 18:49:26 +03:00
Updated regex pattern matching and added tests for parsing array<..> directives.
This commit is contained in:
parent
f5c1b06807
commit
928a23e2c8
@ -374,7 +374,7 @@ class ApiDocExtractor
|
||||
}
|
||||
|
||||
$collectionData = array();
|
||||
preg_match_all("/array<(.*)>( as (.*))?/", $input['class'], $collectionData);
|
||||
preg_match_all("/array<(.*)>(\\s+as\\s+(.*))?/", $input['class'], $collectionData);
|
||||
|
||||
if (count($collectionData[0]) > 0) {
|
||||
$input['class'] = $collectionData[1][0];
|
||||
|
@ -256,4 +256,43 @@ class ApiDocExtractorTest extends WebTestCase
|
||||
);
|
||||
$this->assertCount(1, $parsers);
|
||||
}
|
||||
|
||||
public function testCollectionOutputNormalization()
|
||||
{
|
||||
$extractor = new TestExtractor();
|
||||
$normalized = $extractor->getNormalization('array<Vendor\\Namespace\\Test>');
|
||||
|
||||
$this->assertArrayHasKey('class', $normalized);
|
||||
$this->assertArrayHasKey('collection', $normalized);
|
||||
$this->assertArrayHasKey('collectionName', $normalized);
|
||||
|
||||
$this->assertEquals('Vendor\\Namespace\\Test', $normalized['class']);
|
||||
$this->assertEquals('', $normalized['collectionName']);
|
||||
$this->assertTrue($normalized['collection']);
|
||||
|
||||
}
|
||||
|
||||
public function testNamedCollectionOutputNormalization()
|
||||
{
|
||||
$extractor = new TestExtractor();
|
||||
$normalized = $extractor->getNormalization('array<Vendor\\Namespace\\Test> as tests');
|
||||
|
||||
$this->assertArrayHasKey('class', $normalized);
|
||||
$this->assertArrayHasKey('collection', $normalized);
|
||||
$this->assertArrayHasKey('collectionName', $normalized);
|
||||
|
||||
$this->assertEquals('Vendor\\Namespace\\Test', $normalized['class']);
|
||||
$this->assertEquals('tests', $normalized['collectionName']);
|
||||
$this->assertTrue($normalized['collection']);
|
||||
}
|
||||
|
||||
public function testFailedCollectionOutputNormalization()
|
||||
{
|
||||
$extractor = new TestExtractor();
|
||||
$normalized = $extractor->getNormalization('array<Vendor\\Test');
|
||||
|
||||
$this->assertArrayNotHasKey('collection', $normalized);
|
||||
$this->assertArrayNotHasKey('collectionName', $normalized);
|
||||
|
||||
}
|
||||
}
|
||||
|
19
Tests/Extractor/TestExtractor.php
Normal file
19
Tests/Extractor/TestExtractor.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Nelmio\ApiDocBundle\Tests\Extractor;
|
||||
|
||||
use Nelmio\ApiDocBundle\Extractor\ApiDocExtractor;
|
||||
|
||||
class TestExtractor extends ApiDocExtractor
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function getNormalization($input)
|
||||
{
|
||||
return $this->normalizeClassParameter($input);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user