Skip to content

Commit 08501fe

Browse files
committed
refactoring test case
1 parent 82fdde1 commit 08501fe

File tree

3 files changed

+52
-40
lines changed

3 files changed

+52
-40
lines changed

tests/Php56TestCase.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase as BaseTestCase;
4+
5+
class Php56TestCase extends BaseTestCase
6+
{
7+
protected function setUp()
8+
{
9+
if (method_exists($this, '_setUp')) {
10+
$this->_setUp();
11+
}
12+
}
13+
14+
protected function tearDown()
15+
{
16+
if (method_exists($this, '_tearDown')) {
17+
$this->_tearDown();
18+
}
19+
}
20+
}

tests/Php71TestCase.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase as BaseTestCase;
4+
5+
class Php71TestCase extends BaseTestCase
6+
{
7+
protected function setUp(): void
8+
{
9+
if (method_exists($this, '_setUp')) {
10+
$this->_setUp();
11+
}
12+
}
13+
14+
protected function tearDown(): void
15+
{
16+
if (method_exists($this, '_tearDown')) {
17+
$this->_tearDown();
18+
}
19+
}
20+
21+
public static function assertRegExp(string $pattern, string $string, string $message = ''): void
22+
{
23+
self::assertMatchesRegularExpression($pattern, $string, $message);
24+
}
25+
26+
public static function assertNotRegExp(string $pattern, string $string, string $message = ''): void
27+
{
28+
self::assertDoesNotMatchRegularExpression($pattern, $string, $message);
29+
}
30+
}

tests/TestCase.php

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,11 @@
11
<?php
22

3-
use PHPUnit\Framework\TestCase as BaseTestCase;
4-
53
if (version_compare(PHP_VERSION, '7.1.0', '>=')) {
6-
class TestCase extends BaseTestCase
4+
class TestCase extends Php71TestCase
75
{
8-
protected function setUp(): void
9-
{
10-
if (method_exists($this, '_setUp')) {
11-
$this->_setUp();
12-
}
13-
}
14-
15-
protected function tearDown(): void
16-
{
17-
if (method_exists($this, '_tearDown')) {
18-
$this->_tearDown();
19-
}
20-
}
21-
22-
public static function assertRegExp(string $pattern, string $string, string $message = ''): void
23-
{
24-
self::assertMatchesRegularExpression($pattern, $string, $message);
25-
}
26-
27-
public static function assertNotRegExp(string $pattern, string $string, string $message = ''): void
28-
{
29-
self::assertDoesNotMatchRegularExpression($pattern, $string, $message);
30-
}
316
}
327
} else {
33-
class TestCase extends BaseTestCase
8+
class TestCase extends Php56TestCase
349
{
35-
protected function setUp()
36-
{
37-
if (method_exists($this, '_setUp')) {
38-
$this->_setUp();
39-
}
40-
}
41-
42-
protected function tearDown()
43-
{
44-
if (method_exists($this, '_tearDown')) {
45-
$this->_tearDown();
46-
}
47-
}
4810
}
4911
}

0 commit comments

Comments
 (0)