Skip to content

Commit 75b0bbb

Browse files
committed
Use ExpectDeprecationTrait
1 parent aebbe95 commit 75b0bbb

File tree

7 files changed

+46
-14
lines changed

7 files changed

+46
-14
lines changed

Tests/AliasTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\DependencyInjection\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\DependencyInjection\Alias;
1617

1718
class AliasTest extends TestCase
1819
{
20+
use ExpectDeprecationTrait;
21+
1922
public function testConstructor()
2023
{
2124
$alias = new Alias('foo');
@@ -59,10 +62,11 @@ public function testCanDeprecateAnAlias()
5962

6063
/**
6164
* @group legacy
62-
* @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.
6365
*/
6466
public function testItHasADefaultDeprecationMessage()
6567
{
68+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.');
69+
6670
$alias = new Alias('foo', false);
6771
$alias->setDeprecated();
6872

@@ -72,10 +76,11 @@ public function testItHasADefaultDeprecationMessage()
7276

7377
/**
7478
* @group legacy
75-
* @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.
7679
*/
7780
public function testSetDeprecatedWithoutPackageAndVersion()
7881
{
82+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.');
83+
7984
$def = new Alias('stdClass');
8085
$def->setDeprecated(true, '%alias_id%');
8186

@@ -98,11 +103,12 @@ public function testReturnsCorrectDeprecation()
98103

99104
/**
100105
* @group legacy
101-
* @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.
102-
* @expectedDeprecation Since symfony/dependency-injection 5.1: Passing a null message to un-deprecate a node is deprecated.
103106
*/
104107
public function testCanOverrideDeprecation()
105108
{
109+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.');
110+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Passing a null message to un-deprecate a node is deprecated.');
111+
106112
$alias = new Alias('foo', false);
107113
$alias->setDeprecated('vendor/package', '1.1', 'The "%alias_id%" is deprecated.');
108114
$this->assertTrue($alias->isDeprecated());

Tests/Compiler/ResolveChildDefinitionsPassTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\DependencyInjection\ChildDefinition;
1617
use Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
1819

1920
class ResolveChildDefinitionsPassTest extends TestCase
2021
{
22+
use ExpectDeprecationTrait;
23+
2124
public function testProcess()
2225
{
2326
$container = new ContainerBuilder();
@@ -310,11 +313,12 @@ public function testDecoratedServiceCopiesDeprecatedStatusFromParent()
310313

311314
/**
312315
* @group legacy
313-
* @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Definition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.
314-
* @expectedDeprecation Since symfony/dependency-injection 5.1: Passing a null message to un-deprecate a node is deprecated.
315316
*/
316317
public function testDecoratedServiceCanOverwriteDeprecatedParentStatus()
317318
{
319+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Definition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.');
320+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Passing a null message to un-deprecate a node is deprecated.');
321+
318322
$container = new ContainerBuilder();
319323
$container->register('deprecated_parent')
320324
->setDeprecated(true)

Tests/ContainerBuilderTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use PHPUnit\Framework\TestCase;
1919
use Psr\Container\ContainerInterface as PsrContainerInterface;
20+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
2021
use Symfony\Component\Config\Resource\ComposerResource;
2122
use Symfony\Component\Config\Resource\DirectoryResource;
2223
use Symfony\Component\Config\Resource\FileResource;
@@ -50,6 +51,8 @@
5051

5152
class ContainerBuilderTest extends TestCase
5253
{
54+
use ExpectDeprecationTrait;
55+
5356
public function testDefaultRegisteredDefinitions()
5457
{
5558
$builder = new ContainerBuilder();
@@ -94,10 +97,11 @@ public function testDefinitions()
9497

9598
/**
9699
* @group legacy
97-
* @expectedDeprecation The "deprecated_foo" service is deprecated. You should stop using it, as it will be removed in the future.
98100
*/
99101
public function testCreateDeprecatedService()
100102
{
103+
$this->expectDeprecation('The "deprecated_foo" service is deprecated. You should stop using it, as it will be removed in the future.');
104+
101105
$definition = new Definition('stdClass');
102106
$definition->setDeprecated(true);
103107

@@ -293,10 +297,11 @@ public function testAliases()
293297

294298
/**
295299
* @group legacy
296-
* @expectedDeprecation The "foobar" service alias is deprecated. You should stop using it, as it will be removed in the future.
297300
*/
298301
public function testDeprecatedAlias()
299302
{
303+
$this->expectDeprecation('The "foobar" service alias is deprecated. You should stop using it, as it will be removed in the future.');
304+
300305
$builder = new ContainerBuilder();
301306
$builder->register('foo', 'stdClass');
302307

Tests/DefinitionTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
namespace Symfony\Component\DependencyInjection\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\DependencyInjection\ContainerInterface;
1617
use Symfony\Component\DependencyInjection\Definition;
1718
use Symfony\Component\DependencyInjection\Reference;
1819

1920
class DefinitionTest extends TestCase
2021
{
22+
use ExpectDeprecationTrait;
23+
2124
public function testConstructor()
2225
{
2326
$def = new Definition('stdClass');
@@ -185,10 +188,11 @@ public function testSetIsDeprecated()
185188

186189
/**
187190
* @group legacy
188-
* @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Definition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.
189191
*/
190192
public function testSetDeprecatedWithoutPackageAndVersion()
191193
{
194+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Definition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.');
195+
192196
$def = new Definition('stdClass');
193197
$def->setDeprecated(true, '%service_id%');
194198

Tests/Loader/PhpFileLoaderTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Loader;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Config\FileLocator;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
@@ -20,6 +21,8 @@
2021

2122
class PhpFileLoaderTest extends TestCase
2223
{
24+
use ExpectDeprecationTrait;
25+
2326
public function testSupports()
2427
{
2528
$loader = new PhpFileLoader(new ContainerBuilder(), new FileLocator());
@@ -103,10 +106,11 @@ public function testFactoryShortNotationNotAllowed()
103106

104107
/**
105108
* @group legacy
106-
* @expectedDeprecation Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Loader\Configurator\Traits\DeprecateTrait::deprecate()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.
107109
*/
108110
public function testDeprecatedWithoutPackageAndVersion()
109111
{
112+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Loader\Configurator\Traits\DeprecateTrait::deprecate()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.');
113+
110114
$fixtures = realpath(__DIR__.'/../Fixtures');
111115
$loader = new PhpFileLoader($container = new ContainerBuilder(), new FileLocator());
112116
$loader->load($fixtures.'/config/deprecated_without_package_version.php');

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Loader;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Config\FileLocator;
1617
use Symfony\Component\Config\Loader\LoaderResolver;
1718
use Symfony\Component\Config\Resource\FileResource;
@@ -39,6 +40,8 @@
3940

4041
class XmlFileLoaderTest extends TestCase
4142
{
43+
use ExpectDeprecationTrait;
44+
4245
protected static $fixturesPath;
4346

4447
public static function setUpBeforeClass(): void
@@ -403,10 +406,11 @@ public function testDeprecated()
403406

404407
/**
405408
* @group legacy
406-
* @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated.
407409
*/
408410
public function testDeprecatedWithoutPackageAndVersion()
409411
{
412+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated.');
413+
410414
$container = new ContainerBuilder();
411415
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
412416
$loader->load('services_deprecated_without_package_and_version.xml');
@@ -435,10 +439,11 @@ public function testDeprecatedAliases()
435439

436440
/**
437441
* @group legacy
438-
* @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated.
439442
*/
440443
public function testDeprecatedAliaseWithoutPackageAndVersion()
441444
{
445+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the node "deprecated" is deprecated.');
446+
442447
$container = new ContainerBuilder();
443448
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
444449
$loader->load('deprecated_alias_definitions_without_package_and_version.xml');

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Loader;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Config\FileLocator;
1617
use Symfony\Component\Config\Loader\LoaderResolver;
1718
use Symfony\Component\Config\Resource\FileResource;
@@ -38,6 +39,8 @@
3839

3940
class YamlFileLoaderTest extends TestCase
4041
{
42+
use ExpectDeprecationTrait;
43+
4144
protected static $fixturesPath;
4245

4346
public static function setUpBeforeClass(): void
@@ -232,11 +235,12 @@ public function testDeprecatedAliases()
232235

233236
/**
234237
* @group legacy
235-
* @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the "deprecated" option is deprecated.
236-
* @expectedDeprecation Since symfony/dependency-injection 5.1: Not setting the attribute "version" of the "deprecated" option is deprecated.
237238
*/
238239
public function testDeprecatedAliasesWithoutPackageAndVersion()
239240
{
241+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "package" of the "deprecated" option is deprecated.');
242+
$this->expectDeprecation('Since symfony/dependency-injection 5.1: Not setting the attribute "version" of the "deprecated" option is deprecated.');
243+
240244
$container = new ContainerBuilder();
241245
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
242246
$loader->load('deprecated_alias_definitions_without_package_and_version.yml');

0 commit comments

Comments
 (0)