Updated regex pattern matching and added tests for parsing array<..> directives.

This commit is contained in:
Bez Hermoso 2014-08-07 17:29:53 -07:00
parent f5c1b06807
commit 928a23e2c8
3 changed files with 59 additions and 1 deletions

View File

@ -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];

View File

@ -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);
}
}

View 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);
}
}