Debian Codegraph @

vendor/doctrine/deprecations/src/PHPUnit/VerifyDeprecations.php

raw
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Doctrine\Deprecations\PHPUnit;
6
7 use Doctrine\Deprecations\Deprecation;
8 use PHPUnit\Framework\Attributes\After;
9 use PHPUnit\Framework\Attributes\Before;
10
11 use function sprintf;
12
13 trait VerifyDeprecations
14 {
15 /** @var array<string,int> */
16 private $doctrineDeprecationsExpectations = [];
17
18 /** @var array<string,int> */
19 private $doctrineNoDeprecationsExpectations = [];
20
21 public function expectDeprecationWithIdentifier(string $identifier): void
22 {
23 $this->doctrineDeprecationsExpectations[$identifier] = Deprecation::getTriggeredDeprecations()[$identifier] ?? 0;
24 }
25
26 public function expectNoDeprecationWithIdentifier(string $identifier): void
27 {
28 $this->doctrineNoDeprecationsExpectations[$identifier] = Deprecation::getTriggeredDeprecations()[$identifier] ?? 0;
29 }
30
31 /** @before */
32 #[Before]
33 public function enableDeprecationTracking(): void
34 {
35 Deprecation::enableTrackingDeprecations();
36 }
37
38 /** @after */
39 #[After]
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 "Deprecation with identifier '%s' was triggered by code executed in test, but expected not to.",
61 $identifier
62 )
63 );
64 }
65 }
66 }