|
| 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\Types; |
| 15 | + |
| 16 | +use phpDocumentor\Reflection\Fqsen; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | + |
| 19 | +final class CallableTest extends TestCase |
| 20 | +{ |
| 21 | + public function testCreate(): void |
| 22 | + { |
| 23 | + $identifier = 'callable'; |
| 24 | + $parameters = [ |
| 25 | + new CallableParameter( |
| 26 | + new Object_(new Fqsen('\\phpDocumentor\\A')), |
| 27 | + 'a', |
| 28 | + true, |
| 29 | + true, |
| 30 | + true |
| 31 | + ), |
| 32 | + new CallableParameter( |
| 33 | + new Object_(new Fqsen('\\phpDocumentor\\B')), |
| 34 | + null, |
| 35 | + true, |
| 36 | + true, |
| 37 | + true |
| 38 | + ), |
| 39 | + new CallableParameter( |
| 40 | + new Object_(new Fqsen('\\phpDocumentor\\C')), |
| 41 | + null, |
| 42 | + false, |
| 43 | + false, |
| 44 | + false |
| 45 | + ), |
| 46 | + ]; |
| 47 | + |
| 48 | + $returnType = new Object_(new Fqsen('\\phpDocumentor\\Foo')); |
| 49 | + |
| 50 | + $type = new Callable_($identifier, $parameters, $returnType); |
| 51 | + |
| 52 | + $this->assertSame($identifier, $type->getIdentifier()); |
| 53 | + $this->assertSame($parameters, $type->getParameters()); |
| 54 | + $this->assertSame($returnType, $type->getReturnType()); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @dataProvider provideToStringData |
| 59 | + */ |
| 60 | + public function testToString(string $expectedResult, Callable_ $type): void |
| 61 | + { |
| 62 | + $this->assertSame($expectedResult, (string) $type); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @return array<string, array{string, Callable_}> |
| 67 | + */ |
| 68 | + public static function provideToStringData(): array |
| 69 | + { |
| 70 | + return [ |
| 71 | + 'basic' => [ |
| 72 | + 'callable', |
| 73 | + new Callable_(), |
| 74 | + ], |
| 75 | + 'closure' => [ |
| 76 | + '\Closure', |
| 77 | + new Callable_('\Closure'), |
| 78 | + ], |
| 79 | + ]; |
| 80 | + } |
| 81 | +} |
0 commit comments