|
14 | 14 | require_once __DIR__.'/Fixtures/includes/classes.php'; |
15 | 15 | require_once __DIR__.'/Fixtures/includes/ProjectExtension.php'; |
16 | 16 |
|
| 17 | +use Symfony\Bridge\PhpUnit\ErrorAssert; |
17 | 18 | use Symfony\Component\Config\Resource\ResourceInterface; |
18 | 19 | use Symfony\Component\DependencyInjection\Alias; |
19 | 20 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
@@ -60,28 +61,14 @@ public function testDefinitions() |
60 | 61 |
|
61 | 62 | public function testCreateDeprecatedService() |
62 | 63 | { |
63 | | - $deprecations = array(); |
64 | | - set_error_handler(function ($type, $msg) use (&$deprecations) { |
65 | | - if (E_USER_DEPRECATED !== $type) { |
66 | | - restore_error_handler(); |
| 64 | + ErrorAssert::assertDeprecationsAreTriggered('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', function () { |
| 65 | + $definition = new Definition('stdClass'); |
| 66 | + $definition->setDeprecated(true); |
67 | 67 |
|
68 | | - return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args()); |
69 | | - } |
70 | | - |
71 | | - $deprecations[] = $msg; |
| 68 | + $builder = new ContainerBuilder(); |
| 69 | + $builder->setDefinition('deprecated_foo', $definition); |
| 70 | + $builder->get('deprecated_foo'); |
72 | 71 | }); |
73 | | - |
74 | | - $definition = new Definition('stdClass'); |
75 | | - $definition->setDeprecated(true); |
76 | | - |
77 | | - $builder = new ContainerBuilder(); |
78 | | - $builder->setDefinition('deprecated_foo', $definition); |
79 | | - $builder->get('deprecated_foo'); |
80 | | - |
81 | | - restore_error_handler(); |
82 | | - |
83 | | - $this->assertCount(1, $deprecations); |
84 | | - $this->assertContains('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', $deprecations[0]); |
85 | 72 | } |
86 | 73 |
|
87 | 74 | public function testRegister() |
|
0 commit comments