From 928a23e2c8618acb6a4038f75467f458d6e04de5 Mon Sep 17 00:00:00 2001 From: Bez Hermoso Date: Thu, 7 Aug 2014 17:29:53 -0700 Subject: [PATCH] Updated regex pattern matching and added tests for parsing array<..> directives. --- Extractor/ApiDocExtractor.php | 2 +- Tests/Extractor/ApiDocExtractorTest.php | 39 +++++++++++++++++++++++++ Tests/Extractor/TestExtractor.php | 19 ++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 Tests/Extractor/TestExtractor.php diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index ed05a3c..19f3104 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -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]; diff --git a/Tests/Extractor/ApiDocExtractorTest.php b/Tests/Extractor/ApiDocExtractorTest.php index a0dbd29..a208b6e 100644 --- a/Tests/Extractor/ApiDocExtractorTest.php +++ b/Tests/Extractor/ApiDocExtractorTest.php @@ -256,4 +256,43 @@ class ApiDocExtractorTest extends WebTestCase ); $this->assertCount(1, $parsers); } + + public function testCollectionOutputNormalization() + { + $extractor = new TestExtractor(); + $normalized = $extractor->getNormalization('array'); + + $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 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('arrayassertArrayNotHasKey('collection', $normalized); + $this->assertArrayNotHasKey('collectionName', $normalized); + + } } diff --git a/Tests/Extractor/TestExtractor.php b/Tests/Extractor/TestExtractor.php new file mode 100644 index 0000000..da043b5 --- /dev/null +++ b/Tests/Extractor/TestExtractor.php @@ -0,0 +1,19 @@ +normalizeClassParameter($input); + } +}