summaryrefslogtreecommitdiff
path: root/vendor/doctrine/deprecations/lib/Doctrine/Deprecations/PHPUnit/VerifyDeprecations.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/deprecations/lib/Doctrine/Deprecations/PHPUnit/VerifyDeprecations.php')
-rw-r--r--vendor/doctrine/deprecations/lib/Doctrine/Deprecations/PHPUnit/VerifyDeprecations.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/vendor/doctrine/deprecations/lib/Doctrine/Deprecations/PHPUnit/VerifyDeprecations.php b/vendor/doctrine/deprecations/lib/Doctrine/Deprecations/PHPUnit/VerifyDeprecations.php
new file mode 100644
index 0000000..4c3366a
--- /dev/null
+++ b/vendor/doctrine/deprecations/lib/Doctrine/Deprecations/PHPUnit/VerifyDeprecations.php
@@ -0,0 +1,66 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\Deprecations\PHPUnit;
6
7use Doctrine\Deprecations\Deprecation;
8
9use function sprintf;
10
11trait VerifyDeprecations
12{
13 /** @var array<string,int> */
14 private $doctrineDeprecationsExpectations = [];
15
16 /** @var array<string,int> */
17 private $doctrineNoDeprecationsExpectations = [];
18
19 public function expectDeprecationWithIdentifier(string $identifier): void
20 {
21 $this->doctrineDeprecationsExpectations[$identifier] = Deprecation::getTriggeredDeprecations()[$identifier] ?? 0;
22 }
23
24 public function expectNoDeprecationWithIdentifier(string $identifier): void
25 {
26 $this->doctrineNoDeprecationsExpectations[$identifier] = Deprecation::getTriggeredDeprecations()[$identifier] ?? 0;
27 }
28
29 /**
30 * @before
31 */
32 public function enableDeprecationTracking(): void
33 {
34 Deprecation::enableTrackingDeprecations();
35 }
36
37 /**
38 * @after
39 */
40 public function verifyDeprecationsAreTriggered(): void
41 {
42 foreach ($this->doctrineDeprecationsExpectations as $identifier => $expectation) {
43 $actualCount = Deprecation::getTriggeredDeprecations()[$identifier] ?? 0;
44
45 $this->assertTrue(
46 $actualCount > $expectation,
47 sprintf(
48 "Expected deprecation with identifier '%s' was not triggered by code executed in test.",
49 $identifier
50 )
51 );
52 }
53
54 foreach ($this->doctrineNoDeprecationsExpectations as $identifier => $expectation) {
55 $actualCount = Deprecation::getTriggeredDeprecations()[$identifier] ?? 0;
56
57 $this->assertTrue(
58 $actualCount === $expectation,
59 sprintf(
60 "Expected deprecation with identifier '%s' was triggered by code executed in test, but expected not to.",
61 $identifier
62 )
63 );
64 }
65 }
66}