← All changes
|
vendor/pimple/pimple/src/Pimple/Tests/PimpleTest.php
+32
-6
3.2.5
→
trunk
View file →
| @@ -25,10 +25,12 @@ | ||
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | namespace Pimple\Tests; |
| 28 | 28 | |
| 29 | +use PHPUnit\Framework\Attributes\DataProvider; | |
| 29 | 30 | use PHPUnit\Framework\TestCase; |
| 30 | 31 | use Pimple\Container; |
| 32 | +use Pimple\ServiceProviderInterface; | |
| 31 | 33 | |
| 32 | 34 | /** |
| 33 | 35 | * @author Igor Wiedler <[email protected]> |
| 34 | 36 | */ |
| @@ -149,8 +151,9 @@ | ||
| 149 | 151 | |
| 150 | 152 | /** |
| 151 | 153 | * @dataProvider serviceDefinitionProvider |
| 152 | 154 | */ |
| 155 | + #[DataProvider('serviceDefinitionProvider')] | |
| 153 | 156 | public function testShare($service) |
| 154 | 157 | { |
| 155 | 158 | $pimple = new Container(); |
| 156 | 159 | $pimple['shared_service'] = $service; |
| @@ -166,8 +169,9 @@ | ||
| 166 | 169 | |
| 167 | 170 | /** |
| 168 | 171 | * @dataProvider serviceDefinitionProvider |
| 169 | 172 | */ |
| 173 | + #[DataProvider('serviceDefinitionProvider')] | |
| 170 | 174 | public function testProtect($service) |
| 171 | 175 | { |
| 172 | 176 | $pimple = new Container(); |
| 173 | 177 | $pimple['protected'] = $pimple->protect($service); |
| @@ -200,9 +204,16 @@ | ||
| 200 | 204 | |
| 201 | 205 | public function testFluentRegister() |
| 202 | 206 | { |
| 203 | 207 | $pimple = new Container(); |
| 204 | - $this->assertSame($pimple, $pimple->register($this->getMockBuilder('Pimple\ServiceProviderInterface')->getMock())); | |
| 208 | + | |
| 209 | + $stub = new class implements ServiceProviderInterface { | |
| 210 | + public function register(Container $pimple) | |
| 211 | + { | |
| 212 | + } | |
| 213 | + }; | |
| 214 | + | |
| 215 | + $this->assertSame($pimple, $pimple->register($stub)); | |
| 205 | 216 | } |
| 206 | 217 | |
| 207 | 218 | public function testRawValidatesKeyIsPresent() |
| 208 | 219 | { |
| @@ -227,8 +238,9 @@ | ||
| 227 | 238 | |
| 228 | 239 | /** |
| 229 | 240 | * @dataProvider serviceDefinitionProvider |
| 230 | 241 | */ |
| 242 | + #[DataProvider('serviceDefinitionProvider')] | |
| 231 | 243 | public function testExtend($service) |
| 232 | 244 | { |
| 233 | 245 | $pimple = new Container(); |
| 234 | 246 | $pimple['shared_service'] = function () { |
| @@ -270,13 +282,17 @@ | ||
| 270 | 282 | }); |
| 271 | 283 | unset($pimple['foo']); |
| 272 | 284 | |
| 273 | 285 | $p = new \ReflectionProperty($pimple, 'values'); |
| 274 | - $p->setAccessible(true); | |
| 286 | + if (PHP_VERSION_ID < 80100) { | |
| 287 | + $p->setAccessible(true); | |
| 288 | + } | |
| 275 | 289 | $this->assertEmpty($p->getValue($pimple)); |
| 276 | 290 | |
| 277 | 291 | $p = new \ReflectionProperty($pimple, 'factories'); |
| 278 | - $p->setAccessible(true); | |
| 292 | + if (PHP_VERSION_ID < 80100) { | |
| 293 | + $p->setAccessible(true); | |
| 294 | + } | |
| 279 | 295 | $this->assertCount(0, $p->getValue($pimple)); |
| 280 | 296 | } |
| 281 | 297 | |
| 282 | 298 | public function testExtendValidatesKeyIsPresent() |
| @@ -331,8 +347,9 @@ | ||
| 331 | 347 | |
| 332 | 348 | /** |
| 333 | 349 | * @dataProvider badServiceDefinitionProvider |
| 334 | 350 | */ |
| 351 | + #[DataProvider('badServiceDefinitionProvider')] | |
| 335 | 352 | public function testFactoryFailsForInvalidServiceDefinitions($service) |
| 336 | 353 | { |
| 337 | 354 | $this->expectException(\Pimple\Exception\ExpectedInvokableException::class); |
| 338 | 355 | $this->expectExceptionMessage('Service definition is not a Closure or invokable object.'); |
| @@ -344,8 +361,9 @@ | ||
| 344 | 361 | /** |
| 345 | 362 | * @group legacy |
| 346 | 363 | * @dataProvider badServiceDefinitionProvider |
| 347 | 364 | */ |
| 365 | + #[DataProvider('badServiceDefinitionProvider')] | |
| 348 | 366 | public function testLegacyFactoryFailsForInvalidServiceDefinitions($service) |
| 349 | 367 | { |
| 350 | 368 | $this->expectException(\InvalidArgumentException::class); |
| 351 | 369 | $this->expectExceptionMessage('Service definition is not a Closure or invokable object.'); |
| @@ -356,8 +374,9 @@ | ||
| 356 | 374 | |
| 357 | 375 | /** |
| 358 | 376 | * @dataProvider badServiceDefinitionProvider |
| 359 | 377 | */ |
| 378 | + #[DataProvider('badServiceDefinitionProvider')] | |
| 360 | 379 | public function testProtectFailsForInvalidServiceDefinitions($service) |
| 361 | 380 | { |
| 362 | 381 | $this->expectException(\Pimple\Exception\ExpectedInvokableException::class); |
| 363 | 382 | $this->expectExceptionMessage('Callable is not a Closure or invokable object.'); |
| @@ -369,8 +388,9 @@ | ||
| 369 | 388 | /** |
| 370 | 389 | * @group legacy |
| 371 | 390 | * @dataProvider badServiceDefinitionProvider |
| 372 | 391 | */ |
| 392 | + #[DataProvider('badServiceDefinitionProvider')] | |
| 373 | 393 | public function testLegacyProtectFailsForInvalidServiceDefinitions($service) |
| 374 | 394 | { |
| 375 | 395 | $this->expectException(\InvalidArgumentException::class); |
| 376 | 396 | $this->expectExceptionMessage('Callable is not a Closure or invokable object.'); |
| @@ -381,8 +401,9 @@ | ||
| 381 | 401 | |
| 382 | 402 | /** |
| 383 | 403 | * @dataProvider badServiceDefinitionProvider |
| 384 | 404 | */ |
| 405 | + #[DataProvider('badServiceDefinitionProvider')] | |
| 385 | 406 | public function testExtendFailsForKeysNotContainingServiceDefinitions($service) |
| 386 | 407 | { |
| 387 | 408 | $this->expectException(\Pimple\Exception\InvalidServiceIdentifierException::class); |
| 388 | 409 | $this->expectExceptionMessage('Identifier "foo" does not contain an object definition.'); |
| @@ -396,8 +417,9 @@ | ||
| 396 | 417 | /** |
| 397 | 418 | * @group legacy |
| 398 | 419 | * @dataProvider badServiceDefinitionProvider |
| 399 | 420 | */ |
| 421 | + #[DataProvider('badServiceDefinitionProvider')] | |
| 400 | 422 | public function testLegacyExtendFailsForKeysNotContainingServiceDefinitions($service) |
| 401 | 423 | { |
| 402 | 424 | $this->expectException(\InvalidArgumentException::class); |
| 403 | 425 | $this->expectExceptionMessage('Identifier "foo" does not contain an object definition.'); |
| @@ -410,10 +432,12 @@ | ||
| 410 | 432 | |
| 411 | 433 | /** |
| 412 | 434 | * @group legacy |
| 413 | 435 | * @expectedDeprecation How Pimple behaves when extending protected closures will be fixed in Pimple 4. Are you sure "foo" should be protected? |
| 436 | + * @dataProvider badServiceDefinitionProvider | |
| 414 | 437 | */ |
| 415 | - public function testExtendingProtectedClosureDeprecation() | |
| 438 | + #[DataProvider('badServiceDefinitionProvider')] | |
| 439 | + public function testExtendingProtectedClosureDeprecation($service) | |
| 416 | 440 | { |
| 417 | 441 | $pimple = new Container(); |
| 418 | 442 | $pimple['foo'] = $pimple->protect(function () { |
| 419 | 443 | return 'bar'; |
| @@ -428,8 +452,9 @@ | ||
| 428 | 452 | |
| 429 | 453 | /** |
| 430 | 454 | * @dataProvider badServiceDefinitionProvider |
| 431 | 455 | */ |
| 456 | + #[DataProvider('badServiceDefinitionProvider')] | |
| 432 | 457 | public function testExtendFailsForInvalidServiceDefinitions($service) |
| 433 | 458 | { |
| 434 | 459 | $this->expectException(\Pimple\Exception\ExpectedInvokableException::class); |
| 435 | 460 | $this->expectExceptionMessage('Extension service definition is not a Closure or invokable object.'); |
| @@ -443,8 +468,9 @@ | ||
| 443 | 468 | /** |
| 444 | 469 | * @group legacy |
| 445 | 470 | * @dataProvider badServiceDefinitionProvider |
| 446 | 471 | */ |
| 472 | + #[DataProvider('badServiceDefinitionProvider')] | |
| 447 | 473 | public function testLegacyExtendFailsForInvalidServiceDefinitions($service) |
| 448 | 474 | { |
| 449 | 475 | $this->expectException(\InvalidArgumentException::class); |
| 450 | 476 | $this->expectExceptionMessage('Extension service definition is not a Closure or invokable object.'); |
| @@ -487,9 +513,9 @@ | ||
| 487 | 513 | |
| 488 | 514 | /** |
| 489 | 515 | * Provider for invalid service definitions. |
| 490 | 516 | */ |
| 491 | - public function badServiceDefinitionProvider() | |
| 517 | + public static function badServiceDefinitionProvider() | |
| 492 | 518 | { |
| 493 | 519 | return [ |
| 494 | 520 | [123], |
| 495 | 521 | [new Fixtures\NonInvokable()], |
| @@ -498,9 +524,9 @@ | ||
| 498 | 524 | |
| 499 | 525 | /** |
| 500 | 526 | * Provider for service definitions. |
| 501 | 527 | */ |
| 502 | - public function serviceDefinitionProvider() | |
| 528 | + public static function serviceDefinitionProvider() | |
| 503 | 529 | { |
| 504 | 530 | return [ |
| 505 | 531 | [function ($value) { |
| 506 | 532 | $service = new Fixtures\Service(); |