Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace Doctrine\Deprecations\PHPUnit;
6
 
7
use Doctrine\Deprecations\Deprecation;
8
 
9
use function sprintf;
10
 
11
trait 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
}