forked from phpbb/phpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpbb_test_case.php
More file actions
138 lines (121 loc) · 3.6 KB
/
phpbb_test_case.php
File metadata and controls
138 lines (121 loc) · 3.6 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
use PHPUnit\Framework\TestCase;
class phpbb_test_case extends TestCase
{
protected $test_case_helpers;
static protected $phpunit_version;
public function __construct($name = NULL, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
self::$phpunit_version = PHPUnit\Runner\Version::id();
$backupStaticAttributesBlacklist = [
'SebastianBergmann\CodeCoverage\CodeCoverage' => ['instance'],
'SebastianBergmann\CodeCoverage\Filter' => ['instance'],
'SebastianBergmann\CodeCoverage\Util' => ['ignoredLines', 'templateMethods'],
'SebastianBergmann\Timer\Timer' => ['startTimes'],
'PHP_Token_Stream' => ['customTokens'],
'PHP_Token_Stream_CachingFactory' => ['cache'],
'phpbb_database_test_case' => ['already_connected', 'last_post_timestamp'],
];
$this->excludeBackupStaticAttributes($backupStaticAttributesBlacklist);
}
public function get_test_case_helpers()
{
if (!$this->test_case_helpers)
{
$this->test_case_helpers = new phpbb_test_case_helpers($this);
}
return $this->test_case_helpers;
}
public function setExpectedTriggerError($errno, $message = '')
{
$this->get_test_case_helpers()->setExpectedTriggerError($errno, $message);
}
/**
* PHPUnit deprecates several methods and properties in its recent versions
* Provide BC layer to be able to test in multiple environment settings
*/
public function excludeBackupStaticAttributes($attributes_array)
{
if (version_compare(self::$phpunit_version, '9.0', '>='))
{
$this->backupStaticAttributesExcludeList += $attributes_array;
}
else
{
$this->backupStaticAttributesBlacklist += $attributes_array;
}
}
/**
* PHPUnit deprecates several methods and properties in its recent versions
* Provide BC layer to be able to test in multiple environment settings
*/
public static function assertRegExp(string $pattern, string $string, string $message = ''): void
{
if (version_compare(self::$phpunit_version, '9.0', '>='))
{
parent::assertMatchesRegularExpression($pattern, $string, $message);
}
else
{
parent::assertRegExp($pattern, $string, $message);
}
}
/**
* PHPUnit deprecates several methods and properties in its recent versions
* Provide BC layer to be able to test in multiple environment settings
*/
public function expectException(string $exception): void
{
if (version_compare(self::$phpunit_version, '9.0', '>='))
{
switch ($exception) {
case PHPUnit\Framework\Error\Deprecated::class:
parent::expectDeprecation();
break;
case PHPUnit\Framework\Error\Error::class:
parent::expectError();
break;
case PHPUnit\Framework\Error\Notice::class:
parent::expectNotice();
break;
case PHPUnit\Framework\Error\Warning::class:
parent::expectWarning();
break;
default:
parent::expectException($exception);
break;
}
}
else
{
parent::expectException($exception);
}
}
/**
* PHPUnit deprecates several methods and properties in its recent versions
* Provide BC layer to be able to test in multiple environment settings
*/
public static function assertFileNotExists(string $filename, string $message = ''): void
{
if (version_compare(self::$phpunit_version, '9.0', '>='))
{
parent::assertFileDoesNotExist($filename, $message);
}
else
{
parent::assertFileNotExists($filename, $message);
}
}
}