|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * This file is part of phpDocumentor. |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + * |
| 11 | + * @link http://phpdoc.org |
| 12 | + */ |
| 13 | + |
| 14 | +namespace phpDocumentor\Reflection\DocBlock\Tags; |
| 15 | + |
| 16 | +use Mockery as m; |
| 17 | +use phpDocumentor\Reflection\Fqsen; |
| 18 | +use phpDocumentor\Reflection\Type; |
| 19 | +use phpDocumentor\Reflection\Types\Array_; |
| 20 | +use phpDocumentor\Reflection\Types\Boolean; |
| 21 | +use phpDocumentor\Reflection\Types\Float_; |
| 22 | +use phpDocumentor\Reflection\Types\Integer; |
| 23 | +use phpDocumentor\Reflection\Types\Nullable; |
| 24 | +use phpDocumentor\Reflection\Types\Object_; |
| 25 | +use phpDocumentor\Reflection\Types\String_; |
| 26 | +use PHPUnit\Framework\TestCase; |
| 27 | + |
| 28 | +/** |
| 29 | + * @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Method |
| 30 | + * @covers ::<private> |
| 31 | + */ |
| 32 | +class MethodParameterTest extends TestCase |
| 33 | +{ |
| 34 | + /** |
| 35 | + * Call Mockery::close after each test. |
| 36 | + */ |
| 37 | + public function tearDown(): void |
| 38 | + { |
| 39 | + m::close(); |
| 40 | + } |
| 41 | + |
| 42 | + public function collectionDefaultValuesProvider(): array |
| 43 | + { |
| 44 | + return [ |
| 45 | + [new String_(), '1', '\'1\''], |
| 46 | + [new Integer(), 1, '1'], |
| 47 | + [new Boolean(), true, 'true'], |
| 48 | + [new Float_(), 1.23, '1.23'], |
| 49 | + [new Array_(), [1, '2', true], '[1,\'2\',true]'], |
| 50 | + [new Array_(), [[1, 2], '2', true], '[[1,2],\'2\',true]'], |
| 51 | + [new Nullable(new Float_()), null, 'null'], |
| 52 | + [new Nullable(new Float_()), 1.23, '1.23'], |
| 53 | + [new Object_(new Fqsen('\\stdClass')), new \stdClass(), 'new stdClass()'], |
| 54 | + ]; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__construct |
| 59 | + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::getDefaultValue() |
| 60 | + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__toString |
| 61 | + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
| 62 | + * |
| 63 | + * @dataProvider collectionDefaultValuesProvider |
| 64 | + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render |
| 65 | + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName |
| 66 | + */ |
| 67 | + public function testIfTagCanBeRenderedUsingMethodParameterWithDefaultValue(Type $type, $defaultValue, string $defaultValueStr): void |
| 68 | + { |
| 69 | + $fixture = new MethodParameter('argument', $type, false, false, $defaultValue); |
| 70 | + |
| 71 | + $this->assertSame( |
| 72 | + sprintf('%s $argument = %s', $type, $defaultValueStr), |
| 73 | + (string) $fixture |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__construct |
| 79 | + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::getDefaultValue() |
| 80 | + * @uses \phpDocumentor\Reflection\DocBlock\Tags\MethodParameter::__toString |
| 81 | + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
| 82 | + * |
| 83 | + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render |
| 84 | + * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName |
| 85 | + */ |
| 86 | + public function testIfTagCanBeRenderedUsingMethodParameterWithNoDefaultValue(): void |
| 87 | + { |
| 88 | + $fixture = new MethodParameter('argument', new Float_()); |
| 89 | + |
| 90 | + $this->assertSame( |
| 91 | + 'float $argument', |
| 92 | + (string) $fixture |
| 93 | + ); |
| 94 | + } |
| 95 | +} |
0 commit comments