Skip to content
This repository was archived by the owner on Jan 10, 2022. It is now read-only.

Commit fdc350c

Browse files
committed
compatibility with PHPUnit < 6.x
1 parent 21a07d3 commit fdc350c

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ cache:
1717

1818
install:
1919
- travis_retry composer self-update && composer --version
20-
- travis_retry composer global require "fxp/composer-asset-plugin:^1.2.0"
20+
- travis_retry composer global require "fxp/composer-asset-plugin:^1.3.1"
2121
- export PATH="$HOME/.composer/vendor/bin:$PATH"
2222
- travis_retry composer install --prefer-dist --no-interaction
2323

tests/MappingTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testSetupValue()
1717
$mapping->setValue($value);
1818
$this->assertSame($value, $mapping->getValue($owner));
1919

20-
$this->setExpectedException('yii\base\InvalidParamException');
20+
$this->expectException('yii\base\InvalidParamException');
2121
$mapping->setValue('foo');
2222
}
2323

@@ -36,7 +36,7 @@ public function testSetupMultipleValue()
3636
$actualValue = $mapping->getValue($owner);
3737
$this->assertTrue($actualValue instanceof \ArrayAccess);
3838

39-
$this->setExpectedException('yii\base\InvalidParamException');
39+
$this->expectException('yii\base\InvalidParamException');
4040
$mapping->setValue('foo');
4141
}
4242

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* Base class for the test cases.
1010
*/
11-
class TestCase extends \PHPUnit_Framework_TestCase
11+
class TestCase extends \PHPUnit\Framework\TestCase
1212
{
1313
protected function setUp()
1414
{

tests/bootstrap.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
1313

1414
Yii::setAlias('@yii2tech/tests/unit/embedded', __DIR__);
15-
Yii::setAlias('@yii2tech/embedded', dirname(__DIR__));
15+
Yii::setAlias('@yii2tech/embedded', dirname(__DIR__));
16+
17+
require_once(__DIR__ . '/compatibility.php');

tests/compatibility.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/*
3+
* Ensures compatibility with PHPUnit < 6.x
4+
*/
5+
6+
namespace PHPUnit\Framework\Constraint {
7+
if (!class_exists('PHPUnit\Framework\Constraint\Constraint') && class_exists('PHPUnit_Framework_Constraint')) {
8+
abstract class Constraint extends \PHPUnit_Framework_Constraint
9+
{
10+
}
11+
}
12+
}
13+
14+
namespace PHPUnit\Framework {
15+
if (!class_exists('PHPUnit\Framework\TestCase') && class_exists('PHPUnit_Framework_TestCase')) {
16+
abstract class TestCase extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @param string $exception
20+
*/
21+
public function expectException($exception)
22+
{
23+
$this->setExpectedException($exception);
24+
}
25+
26+
/**
27+
* @param string $message
28+
*/
29+
public function expectExceptionMessage($message)
30+
{
31+
$parentClassMethods = get_class_methods('PHPUnit_Framework_TestCase');
32+
if (in_array('expectExceptionMessage', $parentClassMethods)) {
33+
parent::expectExceptionMessage($message);
34+
return;
35+
}
36+
$this->setExpectedException($this->getExpectedException(), $message);
37+
}
38+
39+
/**
40+
* @param string $messageRegExp
41+
*/
42+
public function expectExceptionMessageRegExp($messageRegExp)
43+
{
44+
$parentClassMethods = get_class_methods('PHPUnit_Framework_TestCase');
45+
if (in_array('expectExceptionMessageRegExp', $parentClassMethods)) {
46+
parent::expectExceptionMessageRegExp($messageRegExp);
47+
return;
48+
}
49+
$this->setExpectedExceptionRegExp($this->getExpectedException(), $messageRegExp);
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)