Skip to content

Commit 66a9d1f

Browse files
Merge branch '3.1'
* 3.1: Tweak merge update tests to use the new error assertion helper [ci] Upgrade to symfony/phpunit-bridge >=3.2@dev update tests to use the new error assertion helper Conflicts: src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php
2 parents c241a02 + ede5f52 commit 66a9d1f

File tree

2 files changed

+19
-43
lines changed

2 files changed

+19
-43
lines changed

Tests/ContainerBuilderTest.php

Lines changed: 8 additions & 23 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;
@@ -58,31 +59,15 @@ public function testDefinitions()
5859

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

66-
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
67-
}
68-
69-
$deprecations[] = $msg;
66+
$builder = new ContainerBuilder();
67+
$builder->setDefinition('deprecated_foo', $definition);
68+
$builder->compile();
69+
$builder->get('deprecated_foo');
7070
});
71-
72-
$definition = new Definition('stdClass');
73-
$definition->setDeprecated(true);
74-
75-
$builder = new ContainerBuilder();
76-
$builder->setDefinition('deprecated_foo', $definition);
77-
78-
$builder->compile();
79-
80-
$builder->get('deprecated_foo');
81-
82-
restore_error_handler();
83-
84-
$this->assertCount(1, $deprecations);
85-
$this->assertContains('The "deprecated_foo" service is deprecated. You should stop using it, as it will soon be removed.', $deprecations[0]);
8671
}
8772

8873
public function testRegister()

Tests/Loader/XmlFileLoaderTest.php

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

1212
namespace Symfony\Component\DependencyInjection\Tests\Loader;
1313

14+
use Symfony\Bridge\PhpUnit\ErrorAssert;
1415
use Symfony\Component\DependencyInjection\ContainerInterface;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
@@ -546,29 +547,19 @@ public function testAutowire()
546547
*/
547548
public function testAliasDefinitionContainsUnsupportedElements()
548549
{
549-
$container = new ContainerBuilder();
550-
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
550+
$deprecations = array(
551+
'Using the attribute "class" is deprecated for alias definition "bar"',
552+
'Using the element "tag" is deprecated for alias definition "bar"',
553+
'Using the element "factory" is deprecated for alias definition "bar"',
554+
);
551555

552-
$deprecations = array();
553-
set_error_handler(function ($type, $msg) use (&$deprecations) {
554-
if (E_USER_DEPRECATED !== $type) {
555-
restore_error_handler();
556+
ErrorAssert::assertDeprecationsAreTriggered($deprecations, function () {
557+
$container = new ContainerBuilder();
558+
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
556559

557-
return call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', func_get_args());
558-
}
560+
$loader->load('legacy_invalid_alias_definition.xml');
559561

560-
$deprecations[] = $msg;
562+
$this->assertTrue($container->has('bar'));
561563
});
562-
563-
$loader->load('legacy_invalid_alias_definition.xml');
564-
565-
restore_error_handler();
566-
567-
$this->assertTrue($container->has('bar'));
568-
569-
$this->assertCount(3, $deprecations);
570-
$this->assertContains('Using the attribute "class" is deprecated for alias definition "bar"', $deprecations[0]);
571-
$this->assertContains('Using the element "tag" is deprecated for alias definition "bar"', $deprecations[1]);
572-
$this->assertContains('Using the element "factory" is deprecated for alias definition "bar"', $deprecations[2]);
573564
}
574565
}

0 commit comments

Comments
 (0)