8000 minor #13356 [PhpUnitBridge] Deprecate the expectedDeprecation annota… · symfony/symfony-docs@ab66936 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab66936

Browse files
committed
minor #13356 [PhpUnitBridge] Deprecate the expectedDeprecation annotation (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- [PhpUnitBridge] Deprecate the expectedDeprecation annotation Fixes #13353. Commits ------- 513f4f7 [PhpUnitBridge] Deprecate the expectedDeprecation annotation
2 parents eca529c + 513f4f7 commit ab66936

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

components/phpunit_bridge.rst

Lines changed: 28 additions & 10 deletions
+
{
Original file line numberDiff line numberDiff line change
@@ -335,23 +335,41 @@ Write Assertions about Deprecations
335335

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

344-
/**
345-
* @group legacy
346-
* @expectedDeprecation This "%s" method is deprecated.
347-
* @expectedDeprecation The second argument of the "%s" method is deprecated.
348-
*/
349-
public function testDeprecatedCode()
344+
use PHPUnit\Framework\TestCase;
345+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
346+
347+
class MyTest extends TestCase
350348
{
351-
@trigger_error('This "Foo" method is deprecated.', E_USER_DEPRECATED);
352-
@trigger_error('The second argument of the "Bar" method is deprecated.', E_USER_DEPRECATED);
349+
use ExpectDeprecationTrait;
350+
351+
/**
352+
* @group legacy
353+
*/
354+
public function testDeprecatedCode()
355
356+
// test some code that triggers the following deprecation:
357+
// @trigger_error('This "Foo" method is deprecated.', E_USER_DEPRECATED);
358+
$this->expectDeprecation('This "%s" method is deprecated');
359+
360+
// ...
361+
362+
// test some code that triggers the following deprecation:
363+
// @trigger_error('The second argument of the "Bar" method is deprecated.', E_USER_DEPRECATED);
364+
$this->expectDeprecation('The second argument of the "%s" method is deprecated.');
365+
}
353366
}
354367

368+
.. deprecated:: 5.1
369+
370+
Symfony versions previous to 5.1 also included a ``@expectedDeprecation``
371+
annotation to test deprecations, but it was deprecated in favor of the method.
372+
355373
Display the Full Stack Trace
356374
----------------------------
357375

0 commit comments

Comments
 (0)
0