-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathUnitTestCase.php
More file actions
89 lines (77 loc) · 2.49 KB
/
UnitTestCase.php
File metadata and controls
89 lines (77 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace PHP_Parallel_Lint\PhpParallelLint\Tests;
use PHPUnit\Framework\TestCase;
abstract class UnitTestCase extends TestCase
{
/**
* @var string
*/
private $exceptionMessage = '';
/**
* Clear any stored exception information between each test.
*
* @after
*/
public function clearExceptionInfo()
{
$this->exceptionMessage = '';
}
/**
* PHPUnit Polyfill: Set an expectation to receive a particular type of Exception.
*
* @param mixed $exception The name of the exception to expect.
*
* @return void
*/
public function expectExceptionPolyfill($exception)
{
if (method_exists('\PHPUnit\Framework\TestCase', 'expectException')) {
// PHPUnit >= 5.2.0.
parent::expectException($exception);
return;
}
$this->setExpectedException($exception, $this->exceptionMessage);
}
/**
* PHPUnit Polyfill: Set an expectation to receive an Exception with a particular error message.
*
* @param string $message The error message to expect.
*
* @return void
*/
public function expectExceptionMessagePolyfill($message)
{
if (method_exists('\PHPUnit\Framework\TestCase', 'expectExceptionMessage')) {
// PHPUnit >= 5.2.0.
parent::expectExceptionMessage($message);
return;
}
// Store the received message in case any of the other methods are called as well.
$this->exceptionMessage = $message;
$exception = $this->getExpectedException();
$this->setExpectedException($exception, $message);
}
/**
* PHPUnit Polyfill: Asserts that a string haystack contains a needle.
*
* @param string $needle The string to search for.
* @param string $haystack The string to treat as the haystack.
* @param string $message Optional failure message to display.
*
* @return void
*/
public static function assertStringContainsStringPolyfill($needle, $haystack, $message = '')
{
if (\method_exists('\PHPUnit\Framework\Assert', 'assertStringContainsString')) {
// PHPUnit >= 7.5.0.
parent::assertStringContainsString($needle, $haystack, $message);
return;
}
// PHPUnit < 7.5.0.
if ($needle === '') {
static::assertSame($needle, $needle, $message);
return;
}
static::assertContains($needle, $haystack, $message);
}
}