Innmind /
Reflection
| 1 | <?php |
||
| 2 | declare(strict_types = 1); |
||
| 3 | |||
| 4 | namespace Tests\Innmind\Reflection\Instanciator; |
||
| 5 | |||
| 6 | use Innmind\Reflection\{ |
||
| 7 | Instanciator\ConstructorLessInstanciator, |
||
| 8 | Instanciator, |
||
| 9 | }; |
||
| 10 | use Innmind\Immutable\Map; |
||
| 11 | use function Innmind\Immutable\unwrap; |
||
| 12 | use PHPUnit\Framework\TestCase; |
||
| 13 | |||
| 14 | class ConstructorLessInstanciatorTest extends TestCase |
||
| 15 | { |
||
| 16 | public function testInterface() |
||
| 17 | { |
||
| 18 | $this->assertInstanceOf( |
||
| 19 | Instanciator::class, |
||
| 20 | new ConstructorLessInstanciator |
||
| 21 | ); |
||
| 22 | } |
||
| 23 | |||
| 24 | public function testBuild() |
||
| 25 | { |
||
| 26 | $instanciator = new ConstructorLessInstanciator; |
||
| 27 | $object = new class('bar') { |
||
| 28 | public $foo; |
||
| 29 | |||
| 30 | public function __construct(string $foo) |
||
| 31 | { |
||
| 32 | $this->foo = $foo; |
||
| 33 | } |
||
| 34 | }; |
||
| 35 | |||
| 36 | $this->assertInstanceOf( |
||
| 37 | 'stdClass', |
||
| 38 | $instanciator->build( |
||
| 39 | 'stdClass', |
||
| 40 | Map::of('string', 'variable') |
||
| 41 | ) |
||
| 42 | ); |
||
| 43 | |||
| 44 | $builtObject = $instanciator->build( |
||
| 45 | get_class($object), |
||
| 46 | Map::of('string', 'variable') |
||
| 47 | ); |
||
| 48 | |||
| 49 | $this->assertInstanceOf(get_class($object), $builtObject); |
||
| 50 | $this->assertNull($builtObject->foo); |
||
| 51 | } |
||
| 52 | |||
| 53 | public function testGetParameters() |
||
| 54 | { |
||
| 55 | $instanciator = new ConstructorLessInstanciator; |
||
| 56 | $object = new class('bar') { |
||
| 57 | public function __construct(string $foo) |
||
|
0 ignored issues
–
show
|
|||
| 58 | { |
||
| 59 | } |
||
| 60 | }; |
||
| 61 | |||
| 62 | $this->assertSame( |
||
| 63 | [], |
||
| 64 | unwrap($instanciator->parameters('stdClass')), |
||
| 65 | ); |
||
| 66 | $this->assertSame( |
||
| 67 | [], |
||
| 68 | unwrap($instanciator->parameters(get_class($object))), |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | } |
||
| 72 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.