Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update for PHPUnit 6 support
  • Loading branch information
mbabker committed Feb 19, 2017
1 parent 4292840 commit 4af30eb
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 10 deletions.
34 changes: 30 additions & 4 deletions Tests/RestRouterTest.php
Expand Up @@ -8,6 +8,7 @@

use Joomla\Router\RestRouter;
use Joomla\Test\TestHelper;
use PHPUnit\Framework\TestCase;

require_once __DIR__ . '/Stubs/GooGet.php';

Expand All @@ -16,7 +17,7 @@
*
* @since 1.0
*/
class RestRouterTest extends \PHPUnit_Framework_TestCase
class RestRouterTest extends TestCase
{
/**
* @var \Joomla\Router\RestRouter The object to be tested.
Expand Down Expand Up @@ -137,7 +138,15 @@ public function testFetchControllerSuffix($input, $expected, $method, $exception
// If we are expecting an exception set it.
if ($exception)
{
$this->setExpectedException('RuntimeException');
// expectException was added in PHPUnit 5.2 and setExpectedException removed in 6.0
if (method_exists($this, 'expectException'))
{
$this->expectException('RuntimeException');
}
else
{
$this->setExpectedException('RuntimeException');
}
}

// Execute the code to test.
Expand All @@ -159,7 +168,16 @@ public function testFetchControllerSuffixWithMissingSuffixMap()
{
$_SERVER['REQUEST_METHOD'] = 'FOOBAR';

$this->setExpectedException('RuntimeException');
// expectException was added in PHPUnit 5.2 and setExpectedException removed in 6.0
if (method_exists($this, 'expectException'))
{
$this->expectException('RuntimeException');
}
else
{
$this->setExpectedException('RuntimeException');
}

$suffix = TestHelper::invoke($this->instance, 'fetchControllerSuffix');
}

Expand Down Expand Up @@ -216,7 +234,15 @@ public function testParseRoute($m, $r, $c, $i)
// If we should expect an exception set that up.
if (is_null($c))
{
$this->setExpectedException('InvalidArgumentException');
// expectException was added in PHPUnit 5.2 and setExpectedException removed in 6.0
if (method_exists($this, 'expectException'))
{
$this->expectException('InvalidArgumentException');
}
else
{
$this->setExpectedException('InvalidArgumentException');
}
}

// Execute the route parsing.
Expand Down
48 changes: 43 additions & 5 deletions Tests/RouterTest.php
Expand Up @@ -8,6 +8,7 @@

use Joomla\Router\Router;
use Joomla\Test\TestHelper;
use PHPUnit\Framework\TestCase;

require_once __DIR__ . '/Stubs/Bar.php';
require_once __DIR__ . '/Stubs/Baz.php';
Expand All @@ -19,7 +20,7 @@
*
* @since 1.0
*/
class RouterTest extends \PHPUnit_Framework_TestCase
class RouterTest extends TestCase
{
/**
* An instance of the object to be tested.
Expand Down Expand Up @@ -255,7 +256,15 @@ public function testParseRoute($r, $e, $c, $i, $m)
// If we should expect an exception set that up.
if ($e)
{
$this->setExpectedException('InvalidArgumentException');
// expectException was added in PHPUnit 5.2 and setExpectedException removed in 6.0
if (method_exists($this, 'expectException'))
{
$this->expectException('InvalidArgumentException');
}
else
{
$this->setExpectedException('InvalidArgumentException');
}
}

// Execute the route parsing.
Expand Down Expand Up @@ -303,7 +312,17 @@ public function testSetDefaultController()
*/
public function testFetchControllerWithMissingClass()
{
$this->setExpectedException('RuntimeException', null, 404);
// expectException was added in PHPUnit 5.2 and setExpectedException removed in 6.0
if (method_exists($this, 'expectException'))
{
$this->expectException('RuntimeException');
$this->expectExceptionCode(404);
}
else
{
$this->setExpectedException('RuntimeException', null, 404);
}

$controller = TestHelper::invoke($this->instance, 'fetchController', 'goober');
}

Expand All @@ -317,7 +336,17 @@ public function testFetchControllerWithMissingClass()
*/
public function testFetchControllerWithNonController()
{
$this->setExpectedException('RuntimeException', null, 500);
// expectException was added in PHPUnit 5.2 and setExpectedException removed in 6.0
if (method_exists($this, 'expectException'))
{
$this->expectException('RuntimeException');
$this->expectExceptionCode(500);
}
else
{
$this->setExpectedException('RuntimeException', null, 500);
}

$controller = TestHelper::invoke($this->instance, 'fetchController', 'MyTestControllerBaz');
}

Expand Down Expand Up @@ -345,7 +374,16 @@ public function testFetchControllerWithPrefixSet()
*/
public function testFetchControllerWithoutPrefixSetThoughNecessary()
{
$this->setExpectedException('RuntimeException');
// expectException was added in PHPUnit 5.2 and setExpectedException removed in 6.0
if (method_exists($this, 'expectException'))
{
$this->expectException('RuntimeException');
}
else
{
$this->setExpectedException('RuntimeException');
}

$controller = TestHelper::invoke($this->instance, 'fetchController', 'foo');
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -12,7 +12,7 @@
},
"require-dev": {
"joomla/test": "~1.0",
"phpunit/phpunit": "~4.8|~5.0",
"phpunit/phpunit": "^4.8.35|^5.4.3|~6.0",
"squizlabs/php_codesniffer": "1.*"
},
"autoload": {
Expand Down

0 comments on commit 4af30eb

Please sign in to comment.