Skip to content

Commit f8937bd

Browse files
minor #19066 [2.8] update tests to use the new error assertion helper (xabbuh)
This PR was merged into the 2.8 branch. Discussion ---------- [2.8] update tests to use the new error assertion helper | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- e5cf4d4 update tests to use the new error assertion helper
2 parents 8ed6f40 + e5cf4d4 commit f8937bd

File tree

2 files changed

+12
-37
lines changed

2 files changed

+12
-37
lines changed

src/Symfony/Component/DependencyInjection/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()

src/Symfony/Component/Yaml/Tests/ParserTest.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Yaml\Tests;
1313

14+
use Symfony\Bridge\PhpUnit\ErrorAssert;
1415
use Symfony\Component\Yaml\Yaml;
1516
use Symfony\Component\Yaml\Parser;
1617

@@ -930,27 +931,14 @@ public function testFloatKeys()
930931
*/
931932
public function testColonInMappingValueException()
932933
{
933-
$yaml = <<<EOF
934+
$parser = $this->parser;
935+
936+
ErrorAssert::assertDeprecationsAreTriggered('Using a colon in the unquoted mapping value "bar: baz" in line 1 is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', function () use ($parser) {
937+
$yaml = <<<EOF
934938
foo: bar: baz
935939
EOF;
936-
937-
$deprecations = array();
938-
set_error_handler(function ($type, $msg) use (&$deprecations) {
939-
if (E_USER_DEPRECATED !== $type) {
940-
restore_error_handler();
941-
942-
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
943-
}
944-
945-
$deprecations[] = $msg;
940+
$parser->parse($yaml);
946941
});
947-
948-
$this->parser->parse($yaml);
949-
950-
restore_error_handler();
951-
952-
$this->assertCount(1, $deprecations);
953-
$this->assertContains('Using a colon in the unquoted mapping value "bar: baz" in line 1 is deprecated since Symfony 2.8 and will throw a ParseException in 3.0.', $deprecations[0]);
954942
}
955943

956944
public function testColonInMappingValueExceptionNotTriggeredByColonInComment()

0 commit comments

Comments
 (0)