|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Toolkit\PhpUtilTest; |
| 4 | + |
| 5 | +use PHPUnit\Framework\TestCase; |
| 6 | +use Toolkit\PhpUtil\PhpDoc; |
| 7 | + |
| 8 | +/** |
| 9 | + * Class PhpDocTest |
| 10 | + * @package Toolkit\PhpUtilTest |
| 11 | + */ |
| 12 | +class PhpDocTest extends TestCase |
| 13 | +{ |
| 14 | + public function testGetTags(): void |
| 15 | + { |
| 16 | + $comment = <<<DOC |
| 17 | +/** |
| 18 | + * Provide some commands to manage the HTTP Server |
| 19 | + * |
| 20 | + * @since 2.0 |
| 21 | + * |
| 22 | + * @example |
| 23 | + * {fullCmd}:start Start the http server |
| 24 | + * {fullCmd}:stop Stop the http server |
| 25 | + */ |
| 26 | +DOC; |
| 27 | + $ret = PhpDoc::getTags($comment); |
| 28 | + $this->assertCount(3, $ret); |
| 29 | + $this->assertArrayHasKey('since', $ret); |
| 30 | + $this->assertArrayHasKey('example', $ret); |
| 31 | + $this->assertArrayHasKey('description', $ret); |
| 32 | + |
| 33 | + $ret = PhpDoc::getTags($comment, ['allow' => ['example']]); |
| 34 | + $this->assertCount(2, $ret); |
| 35 | + $this->assertArrayNotHasKey('since', $ret); |
| 36 | + $this->assertArrayHasKey('example', $ret); |
| 37 | + $this->assertArrayHasKey('description', $ret); |
| 38 | + |
| 39 | + $ret = PhpDoc::getTags($comment, [ |
| 40 | + 'allow' => ['example'], |
| 41 | + 'default' => 'desc' |
| 42 | + ]); |
| 43 | + $this->assertCount(2, $ret); |
| 44 | + $this->assertArrayNotHasKey('since', $ret); |
| 45 | + $this->assertArrayHasKey('example', $ret); |
| 46 | + $this->assertArrayHasKey('desc', $ret); |
| 47 | + $this->assertArrayNotHasKey('description', $ret); |
| 48 | + } |
| 49 | +} |
0 commit comments