|
7 | 7 | use PHPUnit\Framework\TestCase; |
8 | 8 | use Ray\Di\Exception\Unbound; |
9 | 9 | use ReflectionMethod; |
| 10 | +use ReflectionParameter; |
10 | 11 |
|
11 | 12 | use function spl_object_hash; |
12 | 13 |
|
@@ -41,4 +42,115 @@ public function testUnbound(): void |
41 | 42 | $car = new FakeCar(new FakeEngine()); |
42 | 43 | $this->setterMethods->__invoke($car, $container); |
43 | 44 | } |
| 45 | + |
| 46 | + public function testAcceptWithUnboundException(): void |
| 47 | + { |
| 48 | + $this->expectException(Unbound::class); |
| 49 | + $method = new ReflectionMethod(FakeCar::class, 'setTires'); |
| 50 | + $setterMethod = new SetterMethod($method, new Name(Name::ANY)); |
| 51 | + |
| 52 | + $visitor = new class implements VisitorInterface |
| 53 | + { |
| 54 | + public function visitSetterMethod(string $method, Arguments $arguments): void |
| 55 | + { |
| 56 | + throw new Unbound(FakeTyreInterface::class); |
| 57 | + } |
| 58 | + |
| 59 | + public function visitDependency(NewInstance $newInstance, ?string $postConstruct, bool $isSingleton): void |
| 60 | + { |
| 61 | + } |
| 62 | + |
| 63 | + public function visitProvider(Dependency $dependency, string $context, bool $isSingleton): string |
| 64 | + { |
| 65 | + return ''; |
| 66 | + } |
| 67 | + |
| 68 | + /** @param mixed $value */ |
| 69 | + public function visitInstance($value): string |
| 70 | + { |
| 71 | + return ''; |
| 72 | + } |
| 73 | + |
| 74 | + public function visitAspectBind(\Ray\Aop\Bind $aopBind): void |
| 75 | + { |
| 76 | + } |
| 77 | + |
| 78 | + public function visitNewInstance(string $class, SetterMethods $setterMethods, ?Arguments $arguments, ?AspectBind $bind): void |
| 79 | + { |
| 80 | + } |
| 81 | + |
| 82 | + /** @param array<SetterMethod> $setterMethods */ |
| 83 | + public function visitSetterMethods(array $setterMethods): void |
| 84 | + { |
| 85 | + } |
| 86 | + |
| 87 | + /** @param array<Argument> $arguments */ |
| 88 | + public function visitArguments(array $arguments): void |
| 89 | + { |
| 90 | + } |
| 91 | + |
| 92 | + /** @param mixed $defaultValue */ |
| 93 | + public function visitArgument(string $index, bool $isDefaultAvailable, $defaultValue, ReflectionParameter $parameter): void |
| 94 | + { |
| 95 | + } |
| 96 | + }; |
| 97 | + |
| 98 | + $setterMethod->accept($visitor); |
| 99 | + } |
| 100 | + |
| 101 | + public function testAcceptWithUnboundExceptionOptional(): void |
| 102 | + { |
| 103 | + $method = new ReflectionMethod(FakeCar::class, 'setTires'); |
| 104 | + $setterMethod = new SetterMethod($method, new Name(Name::ANY)); |
| 105 | + $setterMethod->setOptional(); |
| 106 | + |
| 107 | + $visitor = new class implements VisitorInterface |
| 108 | + { |
| 109 | + public function visitSetterMethod(string $method, Arguments $arguments): void |
| 110 | + { |
| 111 | + throw new Unbound(FakeTyreInterface::class); |
| 112 | + } |
| 113 | + |
| 114 | + public function visitDependency(NewInstance $newInstance, ?string $postConstruct, bool $isSingleton): void |
| 115 | + { |
| 116 | + } |
| 117 | + |
| 118 | + public function visitProvider(Dependency $dependency, string $context, bool $isSingleton): string |
| 119 | + { |
| 120 | + return ''; |
| 121 | + } |
| 122 | + |
| 123 | + /** @param mixed $value */ |
| 124 | + public function visitInstance($value): string |
| 125 | + { |
| 126 | + return ''; |
| 127 | + } |
| 128 | + |
| 129 | + public function visitAspectBind(\Ray\Aop\Bind $aopBind): void |
| 130 | + { |
| 131 | + } |
| 132 | + |
| 133 | + public function visitNewInstance(string $class, SetterMethods $setterMethods, ?Arguments $arguments, ?AspectBind $bind): void |
| 134 | + { |
| 135 | + } |
| 136 | + |
| 137 | + /** @param array<SetterMethod> $setterMethods */ |
| 138 | + public function visitSetterMethods(array $setterMethods): void |
| 139 | + { |
| 140 | + } |
| 141 | + |
| 142 | + /** @param array<Argument> $arguments */ |
| 143 | + public function visitArguments(array $arguments): void |
| 144 | + { |
| 145 | + } |
| 146 | + |
| 147 | + /** @param mixed $defaultValue */ |
| 148 | + public function visitArgument(string $index, bool $isDefaultAvailable, $defaultValue, ReflectionParameter $parameter): void |
| 149 | + { |
| 150 | + } |
| 151 | + }; |
| 152 | + |
| 153 | + $result = $setterMethod->accept($visitor); |
| 154 | + $this->assertNull($result); |
| 155 | + } |
44 | 156 | } |
0 commit comments