Skip to content

Commit

Permalink
Support PHP 7, PHPUnit 6 & DBUnit 3
Browse files Browse the repository at this point in the history
  • Loading branch information
maxleaver committed Sep 27, 2017
1 parent ddbb54a commit e0519da
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 19 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"require": {
"slim/slim": "~3.1",
"phpunit/phpunit": "^4.8|5.*",
"phpunit/dbunit": "2.*",
"phpunit/phpunit": "^4.8|5.*|6.*",
"phpunit/dbunit": "2.*|3.*",
"illuminate/database": ">=4.0"
},
"require-dev": {
Expand Down
14 changes: 9 additions & 5 deletions src/There4/Slim/Test/WebDbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace There4\Slim\Test;

class WebDbTestCase extends \PHPUnit_Extensions_Database_TestCase
use PDO;
use PHPUnit\DbUnit\TestCase;
use PHPUnit\DbUnit\DataSet\QueryDataSet;

class WebDbTestCase extends TestCase
{
/** @var \Slim\App */
protected $app;
Expand Down Expand Up @@ -33,16 +37,16 @@ public function getSlimInstance()
public function getConnection()
{
if ($this->conn === null) {
$pdo = new \PDO('sqlite::memory:');
$pdo = new PDO('sqlite::memory:');
$this->conn = $this->createDefaultDBConnection($pdo, ':memory:');
}
return $this->conn;
}

public function getDataSet()
{
return new \PHPUnit_Extensions_Database_DataSet_QueryDataSet(
$this->getConnection()
);
return new QueryDataSet(
$this->getConnection()
);
}
}
2 changes: 1 addition & 1 deletion src/There4/Slim/Test/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace There4\Slim\Test;

class WebTestCase extends \PHPUnit_Framework_TestCase
class WebTestCase extends \PHPUnit\Framework\TestCase
{
/** @var \Slim\App */
protected $app;
Expand Down
15 changes: 8 additions & 7 deletions tests/There4Test/Slim/Test/WebDbTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace There4Test\Slim\Test;

use PHPUnit\Framework\TestCase;
use There4\Slim\Test\WebDbTestCase;

class WebDbTestCaseTest extends \PHPUnit_Framework_TestCase
class WebDbTestCaseTest extends TestCase
{
public function testExtendsDbUnit()
{
$testCase = new WebDbTestCase();
self::assertInstanceOf(
'\PHPUnit_Extensions_Database_TestCase',
'\PHPUnit\DbUnit\TestCase',
$testCase
);
}
Expand Down Expand Up @@ -46,10 +47,10 @@ public function testGetSlimInstance()

public function testGetDataset()
{
$testCase = new WebDbTestCase();
$actualDataSet = get_class($testCase->getDataSet());
$expectedDataSet = 'PHPUnit_Extensions_Database_DataSet_QueryDataSet';

self::assertEquals($expectedDataSet, $actualDataSet);
$testCase = new WebDbTestCase();
self::assertInstanceOf(
'\PHPUnit\DbUnit\DataSet\QueryDataSet',
$testCase->getDataSet()
);
}
}
3 changes: 2 additions & 1 deletion tests/There4Test/Slim/Test/WebTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace There4Test\Slim\Test;

use PHPUnit\Framework\TestCase;
use There4\Slim\Test\WebTestCase;

class WebTestCaseTest extends \PHPUnit_Framework_TestCase
class WebTestCaseTest extends TestCase
{
public function testSetup()
{
Expand Down
6 changes: 4 additions & 2 deletions tests/There4Test/Slim/Test/WebTestClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace There4Test\Slim\Test;

use Exception;
use PHPUnit\Framework\TestCase;
use Slim\App;
use There4\Slim\Test\WebTestCase;
use There4\Slim\Test\WebTestClient;

class WebTestClientTest extends \PHPUnit_Framework_TestCase
class WebTestClientTest extends TestCase
{
/**
* @var App
Expand Down Expand Up @@ -144,7 +146,7 @@ private function getValidUri()
public function testInternalError()
{
$this->getSlimInstance()->get('/internalerror', function ($request, $response, $args) {
throw new \Exception('Testing /internalerror.');
throw new Exception('Testing /internalerror.');
return $response;
});

Expand Down
13 changes: 12 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,16 @@ class_alias('\PHPUnit_Framework_TestCase', 'PHPUnit\Framework\TestCase');
// Backward compatibility for DBUnit 2
if (!class_exists('\PHPUnit\DbUnit\TestCase') &&
class_exists('\PHPUnit_Extensions_Database_TestCase')) {
class_alias('\PHPUnit_Extensions_Database_TestCase', 'PHPUnit\DbUnit\TestCase');
class_alias(
'\PHPUnit_Extensions_Database_TestCase',
'PHPUnit\DbUnit\TestCase'
);
}

if (!class_exists('\PHPUnit\DbUnit\DataSet\QueryDataSet') &&
class_exists('\PHPUnit_Extensions_Database_DataSet_QueryDataSet')) {
class_alias(
'\PHPUnit_Extensions_Database_DataSet_QueryDataSet',
'PHPUnit\DbUnit\DataSet\QueryDataSet'
);
}

0 comments on commit e0519da

Please sign in to comment.