@@ -150,6 +150,67 @@ class MyTest extends TestCase
150
150
}
151
151
```
152
152
153
+ ## Displaying deprecations after running a PHPUnit test suite
154
+
155
+ It is possible to integrate this library with PHPUnit to display all
156
+ deprecations triggered during the test suite execution.
157
+
158
+ ``` xml
159
+ <phpunit xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
160
+ xsi : noNamespaceSchemaLocation =" vendor/phpunit/phpunit/phpunit.xsd"
161
+ colors =" true"
162
+ bootstrap =" vendor/autoload.php"
163
+ displayDetailsOnTestsThatTriggerDeprecations =" true"
164
+ failOnDeprecation =" true"
165
+ >
166
+ <!-- one attribute to display the deprecations, the other to fail the test suite -->
167
+
168
+ <php >
169
+ <!-- ensures native PHP deprecations are used -->
170
+ <server name =" DOCTRINE_DEPRECATIONS" value =" trigger" />
171
+ </php >
172
+
173
+ <!-- ensures the @ operator in @trigger_error is ignored -->
174
+ <source ignoreSuppressionOfDeprecations =" true" >
175
+ <include >
176
+ <directory >src</directory >
177
+ </include >
178
+ </source >
179
+ </phpunit >
180
+ ```
181
+
182
+ Note that you can still trigger Deprecations in your code, provided you use the
183
+ ` #[WithoutErrorHandler] ` attribute to disable PHPUnit's error handler for tests
184
+ that call it. Be wary that this will disable all error handling, meaning it
185
+ will mask any warnings or errors that would otherwise be caught by PHPUnit.
186
+
187
+ At the moment, it is not possible to disable deduplication with an environment
188
+ variable, but you can use a bootstrap file to achieve that:
189
+
190
+ ``` php
191
+ // tests/bootstrap.php
192
+ <?php
193
+
194
+ declare(strict_types=1);
195
+
196
+ require dirname(__DIR__) . '/vendor/autoload.php';
197
+
198
+ use Doctrine\Deprecations\Deprecation;
199
+
200
+ Deprecation::withoutDeduplication();
201
+ ```
202
+
203
+ Then, reference that file in your PHPUnit configuration:
204
+
205
+ ``` xml
206
+ <phpunit …
207
+ bootstrap =" tests/bootstrap.php"
208
+ …
209
+ >
210
+ …
211
+ </phpunit >
212
+ ```
213
+
153
214
## What is a deprecation identifier?
154
215
155
216
An identifier for deprecations is just a link to any resource, most often a
0 commit comments