|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FileEye\MimeMap\Test; |
|
4
|
|
|
|
|
5
|
|
|
// PHPUnit compatibility trait for PHPUnit 5. |
|
6
|
|
|
trait Phpunit5CompatibilityTrait |
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* Checks if the trait is used in a class that has a method. |
|
10
|
|
|
* |
|
11
|
|
|
* @param string $method |
|
12
|
|
|
* Method to check. |
|
13
|
|
|
* |
|
14
|
|
|
* @return bool |
|
15
|
|
|
* TRUE if the method is supported, FALSE if not. |
|
16
|
|
|
*/ |
|
17
|
|
|
private function supports($method) |
|
18
|
|
|
{ |
|
19
|
|
|
// Get the parent class of the currently running test class. |
|
20
|
|
|
$parent = get_parent_class($this); |
|
21
|
|
|
// Ensure that the method_exists() check on the createMock method is carried |
|
22
|
|
|
// out on the first parent of $this that does not have access to this |
|
23
|
|
|
// trait's methods. This is because the trait also has a method called |
|
24
|
|
|
// createMock(). Most often the check will be made on |
|
25
|
|
|
// \PHPUnit\Framework\TestCase. |
|
26
|
|
|
while (method_exists($parent, 'supports')) { |
|
27
|
|
|
$parent = get_parent_class($parent); |
|
28
|
|
|
} |
|
29
|
|
|
return method_exists($parent, $method); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function setUp() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::setUp(); |
|
35
|
|
|
if (method_exists($this, 'fcSetUp')) { |
|
36
|
|
|
$this->fcSetUp(); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function tearDown() |
|
41
|
|
|
{ |
|
42
|
|
|
if (method_exists($this, 'fcTearDown')) { |
|
43
|
|
|
$this->fcTearDown(); |
|
44
|
|
|
} |
|
45
|
|
|
parent::tearDown(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function bcSetExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null) |
|
49
|
|
|
{ |
|
50
|
|
|
if ($this->supports('expectException')) { |
|
51
|
|
|
parent::expectException($exceptionName); |
|
52
|
|
|
if ($exceptionMessage) { |
|
53
|
|
|
parent::expectExceptionMessage($exceptionMessage); |
|
54
|
|
|
} |
|
55
|
|
|
if ($exceptionCode !== null) { |
|
56
|
|
|
parent::expectExceptionCode($exceptionCode); |
|
57
|
|
|
} |
|
58
|
|
|
} else { |
|
59
|
|
|
parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function expectException($exception) |
|
64
|
|
|
{ |
|
65
|
|
|
if ($this->supports('expectException')) { |
|
66
|
|
|
parent::expectException($exception); |
|
67
|
|
|
} else { |
|
68
|
|
|
parent::setExpectedException($exception); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function assertStringContainsString($needle, $haystack, $message = '') |
|
73
|
|
|
{ |
|
74
|
|
|
parent::assertContains($needle, $haystack, $message); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function assertStringNotContainsString($needle, $haystack, $message = '') |
|
78
|
|
|
{ |
|
79
|
|
|
parent::assertNotContains($needle, $haystack, $message); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|