|
7 | 7 | use Redbitcz\DebugMode\Detector;
|
8 | 8 | use Redbitcz\DebugMode\Enabler;
|
9 | 9 | use Redbitcz\DebugMode\InconsistentEnablerModeException;
|
| 10 | +use Redbitcz\DebugMode\Plugin\Plugin; |
10 | 11 | use Tester\Assert;
|
11 | 12 | use Tester\Helpers;
|
12 | 13 | use Tester\TestCase;
|
@@ -212,6 +213,121 @@ public function testMissingEnablerShortcut(): void
|
212 | 213 | Detector::detect(Detector::MODE_FULL);
|
213 | 214 | }, InconsistentEnablerModeException::class);
|
214 | 215 | }
|
| 216 | + |
| 217 | + public function testPluginPrepend() |
| 218 | + { |
| 219 | + $detector = new Detector(0); |
| 220 | + $detector->prependPlugin( |
| 221 | + new class implements Plugin { |
| 222 | + public function __invoke(Detector $detector): ?bool |
| 223 | + { |
| 224 | + Assert::true(true); |
| 225 | + return null; |
| 226 | + } |
| 227 | + } |
| 228 | + ); |
| 229 | + $detector->isDebugMode(); |
| 230 | + } |
| 231 | + |
| 232 | + public function testPluginAppend() |
| 233 | + { |
| 234 | + $detector = new Detector(0); |
| 235 | + $detector->appendPlugin( |
| 236 | + new class implements Plugin { |
| 237 | + public function __invoke(Detector $detector): ?bool |
| 238 | + { |
| 239 | + Assert::true(true); |
| 240 | + return null; |
| 241 | + } |
| 242 | + } |
| 243 | + ); |
| 244 | + $detector->isDebugMode(); |
| 245 | + } |
| 246 | + |
| 247 | + public function getPluginPrependReturnsProvider(): array |
| 248 | + { |
| 249 | + return [ |
| 250 | + [null, true], |
| 251 | + [true, true], |
| 252 | + [false, false], |
| 253 | + ]; |
| 254 | + } |
| 255 | + |
| 256 | + /** |
| 257 | + * @dataProvider getPluginPrependReturnsProvider |
| 258 | + */ |
| 259 | + public function testPluginPrependReturn(?bool $state, ?bool $result): void |
| 260 | + { |
| 261 | + $detector = new Detector(0); |
| 262 | + $detector->prependPlugin( |
| 263 | + new class() implements Plugin { |
| 264 | + public function __invoke(Detector $detector): ?bool |
| 265 | + { |
| 266 | + return true; |
| 267 | + } |
| 268 | + } |
| 269 | + ); |
| 270 | + $detector->prependPlugin( |
| 271 | + new class($state) implements Plugin { |
| 272 | + private ?bool $state; |
| 273 | + |
| 274 | + public function __construct(?bool $state) |
| 275 | + { |
| 276 | + $this->state = $state; |
| 277 | + } |
| 278 | + |
| 279 | + public function __invoke(Detector $detector): ?bool |
| 280 | + { |
| 281 | + return $this->state; |
| 282 | + } |
| 283 | + } |
| 284 | + ); |
| 285 | + |
| 286 | + Assert::equal($result, $detector->isDebugMode()); |
| 287 | + } |
| 288 | + |
| 289 | + |
| 290 | + public function getPluginAppendReturnsProvider(): array |
| 291 | + { |
| 292 | + return [ |
| 293 | + [null, false], |
| 294 | + [true, false], |
| 295 | + [false, false], |
| 296 | + ]; |
| 297 | + } |
| 298 | + |
| 299 | + /** |
| 300 | + * @dataProvider getPluginAppendReturnsProvider |
| 301 | + */ |
| 302 | + public function testPluginAppendReturn(?bool $state, ?bool $result): void |
| 303 | + { |
| 304 | + $detector = new Detector(0); |
| 305 | + $detector->appendPlugin( |
| 306 | + new class() implements Plugin { |
| 307 | + public function __invoke(Detector $detector): ?bool |
| 308 | + { |
| 309 | + return false; |
| 310 | + } |
| 311 | + } |
| 312 | + ); |
| 313 | + $detector->appendPlugin( |
| 314 | + new class($state) implements Plugin { |
| 315 | + private ?bool $state; |
| 316 | + |
| 317 | + public function __construct(?bool $state) |
| 318 | + { |
| 319 | + $this->state = $state; |
| 320 | + } |
| 321 | + |
| 322 | + public function __invoke(Detector $detector): ?bool |
| 323 | + { |
| 324 | + return $this->state; |
| 325 | + } |
| 326 | + } |
| 327 | + ); |
| 328 | + |
| 329 | + Assert::equal($result, $detector->isDebugMode()); |
| 330 | + } |
215 | 331 | }
|
216 | 332 |
|
217 | 333 | (new DetectorTest())->run();
|
0 commit comments