Skip to content

Commit 427cdb4

Browse files
committed
update tests to use the new error assertion helper
1 parent d563040 commit 427cdb4

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

Tests/ContainerBuilderTest.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
require_once __DIR__.'/Fixtures/includes/classes.php';
1515
require_once __DIR__.'/Fixtures/includes/ProjectExtension.php';
1616

17+
use Symfony\Bridge\PhpUnit\ErrorAssert;
1718
use Symfony\Component\Config\Resource\ResourceInterface;
1819
use Symfony\Component\DependencyInjection\Alias;
1920
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -61,27 +62,13 @@ public function testDefinitions()
6162

6263
public function testCreateDeprecatedService()
6364
{
64-
$deprecations = array();
65-
set_error_handler(function ($type, $msg) use (&$deprecations) {
66-
if (E_USER_DEPRECATED !== $type) {
67-
restore_error_handler();
65+
ErrorAssert::assertDeprecationsAreTriggered('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', function () {
66+
$definition = new Definition('stdClass');
67+
$definition->setDeprecated(true);
6868

69-
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
70-
}
71-
72-
$deprecations[] = $msg;
69+
$builder = new ContainerBuilder();
70+
$builder->createService($definition, 'deprecated_foo');
7371
});
74-
75-
$definition = new Definition('stdClass');
76-
$definition->setDeprecated(true);
77-
78-
$builder = new ContainerBuilder();
79-
$builder->createService($definition, '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]);
8572
}
8673

8774
public function testRegister()

0 commit comments

Comments
 (0)