8000 Use ExpectDeprecationTrait · dunglas/symfony@08febef · GitHub
[go: up one dir, main page]

Skip to content

Commit 08febef

Browse files
committed
Use ExpectDeprecationTrait
1 parent 6dc7d8b commit 08febef

File tree

10 files changed

+65
-23
lines changed

10 files changed

+65
-23
lines changed

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

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

src/Symfony/Component/DependencyInjection/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', 10000 'stdClass');
302307

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

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

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

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

src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php

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

1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

14+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1415
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
1516
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
1617
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
@@ -19,6 +20,8 @@
1920

2021
class ChoiceTypeTest extends BaseTypeTest
2122
{
23+
use ExpectDeprecationTrait;
24+
2225
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
2326

2427
private $choices = [
@@ -2146,13 +2149,13 @@ public function testFilteredChoiceLoader()
21462149

21472150
/**
21482151
* @group legacy
2149-
*
2150-
* @expectedDeprecation The "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromChoices()" method will require a new "callable|null $filter" argument in the next major version of its interface "Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface", not defining it is deprecated.
2151-
* @expectedDeprecation The "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromLoader()" method will require a new "callable|null $filter" argument in the next major version of its interface "Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface", not defining it is deprecated.
2152-
* @expectedDeprecation Since symfony/form 5.1: Not defining a third parameter "callable|null $filter" in "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromChoices()" is deprecated.
21532152
*/
21542153
public function testUsingDeprecatedChoiceListFactory()
21552154
{
2155+
$this->expectDeprecation('The "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromChoices()" method will require a new "callable|null $filter" argument in the next major version of its interface "Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface", not defining it is deprecated.');
2156+
$this->expectDeprecation('The "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromLoader()" method will require a new "callable|null $filter" argument in the next major version of its interface "Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface", not defining it is deprecated.');
2157+
$this->expectDeprecation('Since symfony/form 5.1: Not defining a third parameter "callable|null $filter" in "Symfony\Component\Form\Tests\Fixtures\ChoiceList\DeprecatedChoiceListFactory::createListFromChoices()" is deprecated.');
2158+
21562159
new ChoiceType(new DeprecatedChoiceListFactory());
21572160
}
21582161
}

src/Symfony/Component/HttpKernel/Tests/Controller/ContainerControllerResolverTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@
1313

1414
use Psr\Container\ContainerInterface;
1515
use Psr\Log\LoggerInterface;
16+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1617
use Symfony\Component\DependencyInjection\Container;
1718
use Symfony\Component\HttpFoundation\Request;
1819
use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver;
1920

2021
class ContainerControllerResolverTest extends ControllerResolverTest
2122
{
23+
use ExpectDeprecationTrait;
24+
2225
/**
2326
* @group legacy
24-
* @expectedDeprecation Since symfony/http-kernel 5.1: Referencing controllers with a single colon is deprecated. Use "foo::action" instead.
2527
*/
2628
public function testGetControllerServiceWithSingleColon()
2729
{
30+
$this->expectDeprecation('Since symfony/http-kernel 5.1: Referencing controllers with a single colon is deprecated. Use "foo::action" instead.');
31+
2832
$service = new ControllerTestService('foo');
2933

3034
$container = $this->createMockContainer();

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

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

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Yaml\Exception\ParseException;
1617
use Symfony\Component\Yaml\Inline;
1718
use Symfony\Component\Yaml\Tag\TaggedValue;
1819
use Symfony\Component\Yaml\Yaml;
1920

2021
class InlineTest extends TestCase
2122
{
23+
use ExpectDeprecationTrait;
24+
2225
protected function setUp(): void
2326
{
2427
Inline::initialize(0, 0);
@@ -742,11 +745,11 @@ public function getTestsForOctalNumbers()
742745
* @dataProvider phpObjectTagWithEmptyValueProvider
743746
*
744747
* @group legacy
745-
*
746-
* @expectedDeprecation Since symfony/yaml 5.1: Using the !php/object tag without a value is deprecated.
747748
*/
748749
public function testPhpObjectWithEmptyValue($expected, $value)
749750
{
751+
$this->expectDeprecation('Since symfony/yaml 5.1: Using the !php/object tag without a value is deprecated.');
752+
750753
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_OBJECT));
751754
}
752755

@@ -766,11 +769,11 @@ public function phpObjectTagWithEmptyValueProvider()
766769
* @dataProvider phpConstTagWithEmptyValueProvider
767770
*
768771
* @group legacy
769-
*
770-
* @expectedDeprecation Since symfony/yaml 5.1: Using the !php/const tag without a value is deprecated.
771772
*/
772773
public function testPhpConstTagWithEmptyValue($expected, $value)
773774
{
775+
$this->expectDeprecation('Since symfony/yaml 5.1: Using the !php/const tag without a value is deprecated.');
776+
774777
$this->assertSame($expected, Inline::parse($value, Yaml::PARSE_CONSTANT));
775778
}
776779

0 commit comments

Comments
 (0)
0