8000 [PhpUnitBridge] Deprecate the expectedDeprecation annotation by javiereguiluz · Pull Request #13356 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[PhpUnitBridge] Deprecate the expectedDeprecation annotation #13356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions components/phpunit_bridge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -335,23 +335,41 @@ Write Assertions about Deprecations

When adding deprecations to your code, you might like writing tests that verify
that they are triggered as required. To do so, the bridge provides the
``@expectedDeprecation`` annotation that you can use on your test methods.
``expectDeprecation()`` method that you can use on your test methods.
It requires you to pass the expected message, given in the same format as for
the `PHPUnit's assertStringMatchesFormat()`_ method. If you expect more than one
deprecation message for a given test method, you can use the annotation several
deprecation message for a given test method, you can use the method several
times (order matters)::

/**
* @group legacy
* @expectedDeprecation This "%s" method is deprecated.
* @expectedDeprecation The second argument of the "%s" method is deprecated.
*/
public function testDeprecatedCode()
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;

class MyTest extends TestCase
{
@trigger_error('This "Foo" method is deprecated.', E_USER_DEPRECATED);
@trigger_error('The second argument of the "Bar" method is deprecated.', E_USER_DEPRECATED);
use ExpectDeprecationTrait;

/**
* @group legacy
*/
public function testDeprecatedCode()
{
// test some code that triggers the following deprecation:
// @trigger_error('This "Foo" method is deprecated.', E_USER_DEPRECATED);
$this->expectDeprecation('This "%s" method is deprecated');

// ...

// test some code that triggers the following deprecation:
// @trigger_error('The second argument of the "Bar" method is deprecated.', E_USER_DEPRECATED);
$this->expectDeprecation('The second argument of the "%s" method is deprecated.');
}
}

.. deprecated:: 5.1

Symfony versions previous to 5.1 also included a ``@expectedDeprecation``
annotation to test deprecations, but it was deprecated in favor of the method.

Display the Full Stack Trace
----------------------------

Expand Down
0