1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Doctrine\Tests; |
5
|
|
|
|
6
|
|
|
use function set_error_handler; |
7
|
|
|
use const E_USER_DEPRECATED; |
8
|
|
|
|
9
|
|
|
trait VerifyDeprecations |
10
|
|
|
{ |
11
|
|
|
/** @var string[] */ |
12
|
|
|
private $expectedDeprecations = []; |
13
|
|
|
|
14
|
|
|
/** @var string[] */ |
15
|
|
|
private $actualDeprecations = []; |
16
|
|
|
|
17
|
|
|
/** @var callable|null */ |
18
|
|
|
private $originalHandler; |
19
|
|
|
|
20
|
|
|
/** @before */ |
21
|
|
|
public function resetDeprecations() : void |
22
|
|
|
{ |
23
|
|
|
$this->actualDeprecations = []; |
24
|
|
|
$this->expectedDeprecations = []; |
25
|
|
|
|
26
|
|
|
$this->originalHandler = set_error_handler( |
27
|
|
|
function (int $errorNumber, string $errorMessage) : void { |
28
|
|
|
$this->actualDeprecations[] = $errorMessage; |
29
|
|
|
}, |
30
|
|
|
E_USER_DEPRECATED |
31
|
|
|
); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** @after */ |
35
|
|
|
public function resetErrorHandler() : void |
36
|
|
|
{ |
37
|
|
|
set_error_handler($this->originalHandler, E_USER_DEPRECATED); |
38
|
|
|
$this->originalHandler = null; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** @after */ |
42
|
|
|
public function validateDeprecationExpectations() : void |
43
|
|
|
{ |
44
|
|
|
if ($this->expectedDeprecations === []) { |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
self::assertSame( |
49
|
|
|
$this->expectedDeprecations, |
50
|
|
|
$this->actualDeprecations, |
51
|
|
|
'Triggered deprecation messages do not match with expected ones.' |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function expectDeprecationMessage(string $message) : void |
56
|
|
|
{ |
57
|
|
|
$this->expectedDeprecations[] = $message; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function assertHasDeprecationMessages() : void |
61
|
|
|
{ |
62
|
|
|
self::assertNotSame([], $this->actualDeprecations, 'Failed asserting that test has triggered deprecation messages.'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected function assertNotHasDeprecationMessages() : void |
66
|
|
|
{ |
67
|
|
|
self::assertSame([], $this->actualDeprecations, 'Failed asserting that test has not triggered deprecation messages.'); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|