@@ -17,99 +17,99 @@ |
||
| 17 | 17 | class Parser implements IParser |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * List of directories to scan for class files referenced in the parsed |
|
| 22 | - * command statements. |
|
| 23 | - * |
|
| 24 | - * @var string[] |
|
| 25 | - */ |
|
| 26 | - protected $common_dirs = []; |
|
| 20 | + /** |
|
| 21 | + * List of directories to scan for class files referenced in the parsed |
|
| 22 | + * command statements. |
|
| 23 | + * |
|
| 24 | + * @var string[] |
|
| 25 | + */ |
|
| 26 | + protected $common_dirs = []; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var AbstractPreprocessor |
|
| 30 | - */ |
|
| 31 | - private $Preprocessor; |
|
| 28 | + /** |
|
| 29 | + * @var AbstractPreprocessor |
|
| 30 | + */ |
|
| 31 | + private $Preprocessor; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Create a new text parser and set directories to scan for referenced |
|
| 35 | - * class files. |
|
| 36 | - * |
|
| 37 | - * @param string[] $dirs |
|
| 38 | - */ |
|
| 39 | - public function __construct(array $dirs = []) |
|
| 40 | - { |
|
| 41 | - foreach ($dirs as $dir) { |
|
| 42 | - $this->common_dirs[] = realpath($dir); |
|
| 43 | - } |
|
| 33 | + /** |
|
| 34 | + * Create a new text parser and set directories to scan for referenced |
|
| 35 | + * class files. |
|
| 36 | + * |
|
| 37 | + * @param string[] $dirs |
|
| 38 | + */ |
|
| 39 | + public function __construct(array $dirs = []) |
|
| 40 | + { |
|
| 41 | + foreach ($dirs as $dir) { |
|
| 42 | + $this->common_dirs[] = realpath($dir); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $this->Preprocessor = new Preprocessor(); |
|
| 46 | - } |
|
| 45 | + $this->Preprocessor = new Preprocessor(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Add additional directories to scan for referenced class files. |
|
| 50 | - * |
|
| 51 | - * @param string[] $dirs |
|
| 52 | - */ |
|
| 53 | - public function addDirs(array $dirs) |
|
| 54 | - { |
|
| 55 | - foreach ($dirs as $dir) { |
|
| 56 | - $this->common_dirs[] = realpath($dir); |
|
| 57 | - } |
|
| 58 | - } |
|
| 48 | + /** |
|
| 49 | + * Add additional directories to scan for referenced class files. |
|
| 50 | + * |
|
| 51 | + * @param string[] $dirs |
|
| 52 | + */ |
|
| 53 | + public function addDirs(array $dirs) |
|
| 54 | + { |
|
| 55 | + foreach ($dirs as $dir) { |
|
| 56 | + $this->common_dirs[] = realpath($dir); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Parse a text file |
|
| 62 | - * |
|
| 63 | - * @param string $file |
|
| 64 | - * @param string[] $dirs |
|
| 65 | - * @param string[] $defines |
|
| 66 | - * @return Statement[] |
|
| 67 | - */ |
|
| 68 | - public function parse($file, array $dirs = [], array $defines = []) |
|
| 69 | - { |
|
| 70 | - return $this->parseText(file_get_contents(realpath($file)), $dirs); |
|
| 71 | - } |
|
| 60 | + /** |
|
| 61 | + * Parse a text file |
|
| 62 | + * |
|
| 63 | + * @param string $file |
|
| 64 | + * @param string[] $dirs |
|
| 65 | + * @param string[] $defines |
|
| 66 | + * @return Statement[] |
|
| 67 | + */ |
|
| 68 | + public function parse($file, array $dirs = [], array $defines = []) |
|
| 69 | + { |
|
| 70 | + return $this->parseText(file_get_contents(realpath($file)), $dirs); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Parse plain text |
|
| 75 | - * |
|
| 76 | - * @param string $text |
|
| 77 | - * @param string[] $dirs |
|
| 78 | - * @param string[] $defines |
|
| 79 | - * @return Statement[] |
|
| 80 | - */ |
|
| 81 | - public function parseText($text, array $dirs = [], array $defines = []): array |
|
| 82 | - { |
|
| 83 | - $this->Preprocessor->resetDefines(); |
|
| 84 | - $this->Preprocessor->addDefines($defines); |
|
| 85 | - $text = $this->Preprocessor->preprocess($text); |
|
| 73 | + /** |
|
| 74 | + * Parse plain text |
|
| 75 | + * |
|
| 76 | + * @param string $text |
|
| 77 | + * @param string[] $dirs |
|
| 78 | + * @param string[] $defines |
|
| 79 | + * @return Statement[] |
|
| 80 | + */ |
|
| 81 | + public function parseText($text, array $dirs = [], array $defines = []): array |
|
| 82 | + { |
|
| 83 | + $this->Preprocessor->resetDefines(); |
|
| 84 | + $this->Preprocessor->addDefines($defines); |
|
| 85 | + $text = $this->Preprocessor->preprocess($text); |
|
| 86 | 86 | |
| 87 | - $Statements = []; |
|
| 87 | + $Statements = []; |
|
| 88 | 88 | |
| 89 | - foreach (preg_split('/\\R/m', $text) as $line => $data) { |
|
| 90 | - $data = trim($data); |
|
| 91 | - $command = self::wordShift($data); |
|
| 92 | - if (!empty($command)) { |
|
| 93 | - $Statements[] = new Statement($command, $data, null, $line); |
|
| 94 | - } |
|
| 95 | - } |
|
| 89 | + foreach (preg_split('/\\R/m', $text) as $line => $data) { |
|
| 90 | + $data = trim($data); |
|
| 91 | + $command = self::wordShift($data); |
|
| 92 | + if (!empty($command)) { |
|
| 93 | + $Statements[] = new Statement($command, $data, null, $line); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return $Statements; |
|
| 98 | - } |
|
| 97 | + return $Statements; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Get the first word from a string and remove it from the string. |
|
| 102 | - * |
|
| 103 | - * @param string $data |
|
| 104 | - * @return boolean|string |
|
| 105 | - */ |
|
| 106 | - private static function wordShift(&$data) |
|
| 107 | - { |
|
| 108 | - if (preg_match('~^(\S+)\s*(.*)$~', $data, $matches) === 1) { |
|
| 109 | - $data = $matches[2]; |
|
| 110 | - return $matches[1]; |
|
| 111 | - } |
|
| 112 | - return false; |
|
| 113 | - } |
|
| 100 | + /** |
|
| 101 | + * Get the first word from a string and remove it from the string. |
|
| 102 | + * |
|
| 103 | + * @param string $data |
|
| 104 | + * @return boolean|string |
|
| 105 | + */ |
|
| 106 | + private static function wordShift(&$data) |
|
| 107 | + { |
|
| 108 | + if (preg_match('~^(\S+)\s*(.*)$~', $data, $matches) === 1) { |
|
| 109 | + $data = $matches[2]; |
|
| 110 | + return $matches[1]; |
|
| 111 | + } |
|
| 112 | + return false; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -spl_autoload_register(function ($classname) { |
|
| 3 | +spl_autoload_register(function($classname) { |
|
| 4 | 4 | $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php'; |
| 5 | 5 | if (is_file($file)) { |
| 6 | 6 | require_once $file; |
@@ -1,8 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | spl_autoload_register(function ($classname) { |
| 4 | - $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php'; |
|
| 5 | - if (is_file($file)) { |
|
| 6 | - require_once $file; |
|
| 7 | - } |
|
| 4 | + $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php'; |
|
| 5 | + if (is_file($file)) { |
|
| 6 | + require_once $file; |
|
| 7 | + } |
|
| 8 | 8 | }); |
@@ -13,14 +13,14 @@ |
||
| 13 | 13 | class Example |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @rest\endpoint /endpoint |
|
| 18 | - * @rest\method GET Something |
|
| 19 | - * @rest\response 200 uuid |
|
| 20 | - */ |
|
| 21 | - public function Dummy() |
|
| 22 | - { |
|
| 16 | + /** |
|
| 17 | + * @rest\endpoint /endpoint |
|
| 18 | + * @rest\method GET Something |
|
| 19 | + * @rest\response 200 uuid |
|
| 20 | + */ |
|
| 21 | + public function Dummy() |
|
| 22 | + { |
|
| 23 | 23 | |
| 24 | - } |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | } |
@@ -11,15 +11,15 @@ |
||
| 11 | 11 | class Example |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @rest\endpoint /endpoint/{listid} |
|
| 16 | - * @rest\method GET Something |
|
| 17 | - * @rest\param listid |
|
| 18 | - * @rest\response 200 |
|
| 19 | - */ |
|
| 20 | - public function Dummy() |
|
| 21 | - { |
|
| 14 | + /** |
|
| 15 | + * @rest\endpoint /endpoint/{listid} |
|
| 16 | + * @rest\method GET Something |
|
| 17 | + * @rest\param listid |
|
| 18 | + * @rest\response 200 |
|
| 19 | + */ |
|
| 20 | + public function Dummy() |
|
| 21 | + { |
|
| 22 | 22 | |
| 23 | - } |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | } |
@@ -11,17 +11,17 @@ |
||
| 11 | 11 | class Example |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @rest\endpoint /endpoint/{listid} |
|
| 16 | - * @rest\method GET Something |
|
| 17 | - * @rest\ifndef skip |
|
| 18 | - * @rest\param listid |
|
| 19 | - * @rest\endif |
|
| 20 | - * @rest\response 200 |
|
| 21 | - */ |
|
| 22 | - public function Dummy() |
|
| 23 | - { |
|
| 14 | + /** |
|
| 15 | + * @rest\endpoint /endpoint/{listid} |
|
| 16 | + * @rest\method GET Something |
|
| 17 | + * @rest\ifndef skip |
|
| 18 | + * @rest\param listid |
|
| 19 | + * @rest\endif |
|
| 20 | + * @rest\response 200 |
|
| 21 | + */ |
|
| 22 | + public function Dummy() |
|
| 23 | + { |
|
| 24 | 24 | |
| 25 | - } |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | } |
@@ -13,17 +13,17 @@ |
||
| 13 | 13 | class Example |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - public function Dummy() |
|
| 17 | - { |
|
| 18 | - /** |
|
| 19 | - * @rest\endpoint /v1/users/{id} |
|
| 20 | - * @rest\method GET Return a JSON with all the user attributes |
|
| 21 | - * @rest\path Int id The ID of the User |
|
| 22 | - * @rest\response 200 User |
|
| 23 | - */ |
|
| 24 | - $app->get('/v1/users/{id:[0-9]+}', function ($request, $response, $args) { |
|
| 25 | - // ... |
|
| 26 | - }); |
|
| 27 | - } |
|
| 16 | + public function Dummy() |
|
| 17 | + { |
|
| 18 | + /** |
|
| 19 | + * @rest\endpoint /v1/users/{id} |
|
| 20 | + * @rest\method GET Return a JSON with all the user attributes |
|
| 21 | + * @rest\path Int id The ID of the User |
|
| 22 | + * @rest\response 200 User |
|
| 23 | + */ |
|
| 24 | + $app->get('/v1/users/{id:[0-9]+}', function ($request, $response, $args) { |
|
| 25 | + // ... |
|
| 26 | + }); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | } |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | * @rest\path Int id The ID of the User |
| 22 | 22 | * @rest\response 200 User |
| 23 | 23 | */ |
| 24 | - $app->get('/v1/users/{id:[0-9]+}', function ($request, $response, $args) { |
|
| 24 | + $app->get('/v1/users/{id:[0-9]+}', function($request, $response, $args) { |
|
| 25 | 25 | // ... |
| 26 | 26 | }); |
| 27 | 27 | } |
@@ -5,191 +5,191 @@ |
||
| 5 | 5 | class ParserTest extends \SwaggerGen_TestCase |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @covers \SwaggerGen\Parser\Text\Parser::__construct |
|
| 10 | - */ |
|
| 11 | - public function testConstructor_Empty() |
|
| 12 | - { |
|
| 13 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 14 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * @covers \SwaggerGen\Parser\Text\Parser::__construct |
|
| 19 | - */ |
|
| 20 | - public function testConstructor_Dirs() |
|
| 21 | - { |
|
| 22 | - $this->markTestIncomplete('Not yet implemented.'); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @covers \SwaggerGen\Parser\Text\Parser::addDirs |
|
| 27 | - */ |
|
| 28 | - public function testAddDirs() |
|
| 29 | - { |
|
| 30 | - $this->markTestIncomplete('Not yet implemented.'); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 35 | - */ |
|
| 36 | - public function testParseText() |
|
| 37 | - { |
|
| 38 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 39 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 40 | - |
|
| 41 | - $statements = $object->parseText('title Some words'); |
|
| 42 | - |
|
| 43 | - $this->assertCount(1, $statements); |
|
| 44 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 45 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
| 46 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 51 | - */ |
|
| 52 | - public function testParseText_Whitespace() |
|
| 53 | - { |
|
| 54 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 55 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 56 | - |
|
| 57 | - $statements = $object->parseText(" \t title \t\t Some words \t "); |
|
| 58 | - |
|
| 59 | - $this->assertCount(1, $statements); |
|
| 60 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 61 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
| 62 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 67 | - */ |
|
| 68 | - public function testParseText_Multiple_LF() |
|
| 69 | - { |
|
| 70 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 71 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 72 | - |
|
| 73 | - $statements = $object->parseText("title Some words\nSome Random words"); |
|
| 74 | - |
|
| 75 | - $this->assertCount(2, $statements); |
|
| 76 | - |
|
| 77 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 78 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
| 79 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
| 80 | - |
|
| 81 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 82 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 83 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 88 | - */ |
|
| 89 | - public function testParseText_Multiple_CR() |
|
| 90 | - { |
|
| 91 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 92 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 93 | - |
|
| 94 | - $statements = $object->parseText("title Some words\rSome Random words"); |
|
| 95 | - |
|
| 96 | - $this->assertCount(2, $statements); |
|
| 97 | - |
|
| 98 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 99 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
| 100 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
| 101 | - |
|
| 102 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 103 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 104 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 109 | - */ |
|
| 110 | - public function testParseText_Multiple_CRLF() |
|
| 111 | - { |
|
| 112 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 113 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 114 | - |
|
| 115 | - $statements = $object->parseText("title Some words\r\nSome Random words"); |
|
| 116 | - |
|
| 117 | - $this->assertCount(2, $statements); |
|
| 118 | - |
|
| 119 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 120 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
| 121 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
| 122 | - |
|
| 123 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 124 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 125 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 130 | - */ |
|
| 131 | - public function testParseText_Multiple_BlankLines() |
|
| 132 | - { |
|
| 133 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 134 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 135 | - |
|
| 136 | - $statements = $object->parseText("title Some words\r\n\n\n\rSome Random words"); |
|
| 137 | - |
|
| 138 | - $this->assertCount(2, $statements); |
|
| 139 | - |
|
| 140 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 141 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
| 142 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
| 143 | - |
|
| 144 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 145 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 146 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 151 | - */ |
|
| 152 | - public function testParseText_Dirs() |
|
| 153 | - { |
|
| 154 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 155 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 156 | - |
|
| 157 | - $statements = $object->parseText("title Some words\r\n\n\n\rSome Random words", array( |
|
| 158 | - __DIR__ . '/ParserTest/not used by text parser', |
|
| 159 | - )); |
|
| 160 | - |
|
| 161 | - $this->assertCount(2, $statements); |
|
| 162 | - |
|
| 163 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 164 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
| 165 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
| 166 | - |
|
| 167 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 168 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 169 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @covers \SwaggerGen\Parser\Text\Parser::parse |
|
| 174 | - */ |
|
| 175 | - public function testParse() |
|
| 176 | - { |
|
| 177 | - $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 178 | - $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 179 | - |
|
| 180 | - $statements = $object->parse(__DIR__ . '/ParserTest/testParse.txt', array( |
|
| 181 | - __DIR__ . '/ParserTest/not used by text parser', |
|
| 182 | - )); |
|
| 183 | - |
|
| 184 | - $this->assertCount(2, $statements); |
|
| 185 | - |
|
| 186 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 187 | - $this->assertSame('title', $statements[0]->getCommand()); |
|
| 188 | - $this->assertSame('Some words', $statements[0]->getData()); |
|
| 189 | - |
|
| 190 | - $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 191 | - $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 192 | - $this->assertSame('Random words', $statements[1]->getData()); |
|
| 193 | - } |
|
| 8 | + /** |
|
| 9 | + * @covers \SwaggerGen\Parser\Text\Parser::__construct |
|
| 10 | + */ |
|
| 11 | + public function testConstructor_Empty() |
|
| 12 | + { |
|
| 13 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 14 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * @covers \SwaggerGen\Parser\Text\Parser::__construct |
|
| 19 | + */ |
|
| 20 | + public function testConstructor_Dirs() |
|
| 21 | + { |
|
| 22 | + $this->markTestIncomplete('Not yet implemented.'); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @covers \SwaggerGen\Parser\Text\Parser::addDirs |
|
| 27 | + */ |
|
| 28 | + public function testAddDirs() |
|
| 29 | + { |
|
| 30 | + $this->markTestIncomplete('Not yet implemented.'); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 35 | + */ |
|
| 36 | + public function testParseText() |
|
| 37 | + { |
|
| 38 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 39 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 40 | + |
|
| 41 | + $statements = $object->parseText('title Some words'); |
|
| 42 | + |
|
| 43 | + $this->assertCount(1, $statements); |
|
| 44 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 45 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
| 46 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 51 | + */ |
|
| 52 | + public function testParseText_Whitespace() |
|
| 53 | + { |
|
| 54 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 55 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 56 | + |
|
| 57 | + $statements = $object->parseText(" \t title \t\t Some words \t "); |
|
| 58 | + |
|
| 59 | + $this->assertCount(1, $statements); |
|
| 60 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 61 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
| 62 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 67 | + */ |
|
| 68 | + public function testParseText_Multiple_LF() |
|
| 69 | + { |
|
| 70 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 71 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 72 | + |
|
| 73 | + $statements = $object->parseText("title Some words\nSome Random words"); |
|
| 74 | + |
|
| 75 | + $this->assertCount(2, $statements); |
|
| 76 | + |
|
| 77 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 78 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
| 79 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
| 80 | + |
|
| 81 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 82 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 83 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 88 | + */ |
|
| 89 | + public function testParseText_Multiple_CR() |
|
| 90 | + { |
|
| 91 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 92 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 93 | + |
|
| 94 | + $statements = $object->parseText("title Some words\rSome Random words"); |
|
| 95 | + |
|
| 96 | + $this->assertCount(2, $statements); |
|
| 97 | + |
|
| 98 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 99 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
| 100 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
| 101 | + |
|
| 102 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 103 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 104 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 109 | + */ |
|
| 110 | + public function testParseText_Multiple_CRLF() |
|
| 111 | + { |
|
| 112 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 113 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 114 | + |
|
| 115 | + $statements = $object->parseText("title Some words\r\nSome Random words"); |
|
| 116 | + |
|
| 117 | + $this->assertCount(2, $statements); |
|
| 118 | + |
|
| 119 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 120 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
| 121 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
| 122 | + |
|
| 123 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 124 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 125 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 130 | + */ |
|
| 131 | + public function testParseText_Multiple_BlankLines() |
|
| 132 | + { |
|
| 133 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 134 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 135 | + |
|
| 136 | + $statements = $object->parseText("title Some words\r\n\n\n\rSome Random words"); |
|
| 137 | + |
|
| 138 | + $this->assertCount(2, $statements); |
|
| 139 | + |
|
| 140 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 141 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
| 142 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
| 143 | + |
|
| 144 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 145 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 146 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @covers \SwaggerGen\Parser\Text\Parser::parseText |
|
| 151 | + */ |
|
| 152 | + public function testParseText_Dirs() |
|
| 153 | + { |
|
| 154 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 155 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 156 | + |
|
| 157 | + $statements = $object->parseText("title Some words\r\n\n\n\rSome Random words", array( |
|
| 158 | + __DIR__ . '/ParserTest/not used by text parser', |
|
| 159 | + )); |
|
| 160 | + |
|
| 161 | + $this->assertCount(2, $statements); |
|
| 162 | + |
|
| 163 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 164 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
| 165 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
| 166 | + |
|
| 167 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 168 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 169 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @covers \SwaggerGen\Parser\Text\Parser::parse |
|
| 174 | + */ |
|
| 175 | + public function testParse() |
|
| 176 | + { |
|
| 177 | + $object = new \SwaggerGen\Parser\Text\Parser(); |
|
| 178 | + $this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
|
| 179 | + |
|
| 180 | + $statements = $object->parse(__DIR__ . '/ParserTest/testParse.txt', array( |
|
| 181 | + __DIR__ . '/ParserTest/not used by text parser', |
|
| 182 | + )); |
|
| 183 | + |
|
| 184 | + $this->assertCount(2, $statements); |
|
| 185 | + |
|
| 186 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
|
| 187 | + $this->assertSame('title', $statements[0]->getCommand()); |
|
| 188 | + $this->assertSame('Some words', $statements[0]->getData()); |
|
| 189 | + |
|
| 190 | + $this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
|
| 191 | + $this->assertSame('Some', $statements[1]->getCommand()); |
|
| 192 | + $this->assertSame('Random words', $statements[1]->getData()); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | 195 | } |
@@ -11,15 +11,15 @@ |
||
| 11 | 11 | class Example |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @rest\endpoint /endpoint/{listid} |
|
| 16 | - * @rest\method GET Something |
|
| 17 | - * @rest\param listid |
|
| 18 | - * @rest\response 200 |
|
| 19 | - */ |
|
| 20 | - public function Dummy() |
|
| 21 | - { |
|
| 14 | + /** |
|
| 15 | + * @rest\endpoint /endpoint/{listid} |
|
| 16 | + * @rest\method GET Something |
|
| 17 | + * @rest\param listid |
|
| 18 | + * @rest\response 200 |
|
| 19 | + */ |
|
| 20 | + public function Dummy() |
|
| 21 | + { |
|
| 22 | 22 | |
| 23 | - } |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | } |
@@ -14,44 +14,44 @@ |
||
| 14 | 14 | class ExternalDocumentation extends AbstractObject |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - private $url; |
|
| 18 | - private $description; |
|
| 19 | - |
|
| 20 | - public function __construct(AbstractObject $parent, $url, $description = null) |
|
| 21 | - { |
|
| 22 | - parent::__construct($parent); |
|
| 23 | - $this->url = $url; |
|
| 24 | - $this->description = $description; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @param string $command |
|
| 29 | - * @param string $data |
|
| 30 | - * @return AbstractObject|boolean |
|
| 31 | - */ |
|
| 32 | - public function handleCommand($command, $data = null) |
|
| 33 | - { |
|
| 34 | - switch (strtolower($command)) { |
|
| 35 | - case 'url': |
|
| 36 | - case 'description': |
|
| 37 | - $this->$command = $data; |
|
| 38 | - return $this; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - return parent::handleCommand($command, $data); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function toArray(): array |
|
| 45 | - { |
|
| 46 | - return self::arrayFilterNull(array_merge(array( |
|
| 47 | - 'url' => $this->url, |
|
| 48 | - 'description' => empty($this->description) ? null : $this->description, |
|
| 49 | - ), parent::toArray())); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function __toString() |
|
| 53 | - { |
|
| 54 | - return __CLASS__ . ' ' . $this->url; |
|
| 55 | - } |
|
| 17 | + private $url; |
|
| 18 | + private $description; |
|
| 19 | + |
|
| 20 | + public function __construct(AbstractObject $parent, $url, $description = null) |
|
| 21 | + { |
|
| 22 | + parent::__construct($parent); |
|
| 23 | + $this->url = $url; |
|
| 24 | + $this->description = $description; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @param string $command |
|
| 29 | + * @param string $data |
|
| 30 | + * @return AbstractObject|boolean |
|
| 31 | + */ |
|
| 32 | + public function handleCommand($command, $data = null) |
|
| 33 | + { |
|
| 34 | + switch (strtolower($command)) { |
|
| 35 | + case 'url': |
|
| 36 | + case 'description': |
|
| 37 | + $this->$command = $data; |
|
| 38 | + return $this; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + return parent::handleCommand($command, $data); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function toArray(): array |
|
| 45 | + { |
|
| 46 | + return self::arrayFilterNull(array_merge(array( |
|
| 47 | + 'url' => $this->url, |
|
| 48 | + 'description' => empty($this->description) ? null : $this->description, |
|
| 49 | + ), parent::toArray())); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function __toString() |
|
| 53 | + { |
|
| 54 | + return __CLASS__ . ' ' . $this->url; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | } |