Navigation Menu

Skip to content

Commit

Permalink
Add support for PHPUnit6 in the Cake\TestSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
antograssiot committed Feb 14, 2017
1 parent 6d380fe commit a67e549
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 45 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -31,7 +31,7 @@
"ext-openssl": "To use Security::encrypt() or have secure CSRF token generation."
},
"require-dev": {
"phpunit/phpunit": "<6.0",
"phpunit/phpunit": "*",
"cakephp/cakephp-codesniffer": "~2.1"
},
"autoload": {
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Expand Up @@ -6,6 +6,7 @@
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
backupGlobals="true"
>
<php>
<ini name="memory_limit" value="-1"/>
Expand Down
8 changes: 4 additions & 4 deletions src/TestSuite/Constraint/EventFired.php
Expand Up @@ -2,13 +2,13 @@
namespace Cake\TestSuite\Constraint;

use Cake\Event\EventManager;
use PHPUnit_Framework_AssertionFailedError;
use PHPUnit_Framework_Constraint;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Constraint\Constraint;

/**
* EventFired constraint
*/
class EventFired extends PHPUnit_Framework_Constraint
class EventFired extends Constraint
{
/**
* Array of fired events
Expand All @@ -28,7 +28,7 @@ public function __construct($eventManager)
$this->_eventManager = $eventManager;

if ($this->_eventManager->getEventList() === null) {
throw new PHPUnit_Framework_AssertionFailedError('The event manager you are asserting against is not configured to track events.');
throw new AssertionFailedError('The event manager you are asserting against is not configured to track events.');
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/TestSuite/Constraint/EventFiredWith.php
Expand Up @@ -3,15 +3,15 @@

use Cake\Event\Event;
use Cake\Event\EventManager;
use PHPUnit_Framework_AssertionFailedError;
use PHPUnit_Framework_Constraint;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Constraint\Constraint;

/**
* EventFiredWith constraint
*
* Another glorified in_array check
*/
class EventFiredWith extends PHPUnit_Framework_Constraint
class EventFiredWith extends Constraint
{
/**
* Array of fired events
Expand Down Expand Up @@ -49,7 +49,7 @@ public function __construct($eventManager, $dataKey, $dataValue)
$this->_dataValue = $dataValue;

if ($this->_eventManager->getEventList() === null) {
throw new PHPUnit_Framework_AssertionFailedError('The event manager you are asserting against is not configured to track events.');
throw new AssertionFailedError('The event manager you are asserting against is not configured to track events.');
}
}

Expand Down Expand Up @@ -81,7 +81,7 @@ public function matches($other)
$events = $eventGroup[$other];

if (count($events) > 1) {
throw new PHPUnit_Framework_AssertionFailedError(sprintf('Event "%s" was fired %d times, cannot make data assertion', $other, count($events)));
throw new AssertionFailedError(sprintf('Event "%s" was fired %d times, cannot make data assertion', $other, count($events)));
}

/* @var \Cake\Event\Event $event */
Expand Down
58 changes: 29 additions & 29 deletions src/TestSuite/Fixture/FixtureInjector.php
Expand Up @@ -16,17 +16,17 @@

use Cake\TestSuite\TestCase;
use Exception;
use PHPUnit_Framework_AssertionFailedError;
use PHPUnit_Framework_Test;
use PHPUnit_Framework_TestListener;
use PHPUnit_Framework_TestSuite;
use PHPUnit_Framework_Warning;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestSuite;
use PHPUnit\Framework\Warning;

/**
* Test listener used to inject a fixture manager in all tests that
* are composed inside a Test Suite
*/
class FixtureInjector implements PHPUnit_Framework_TestListener
class FixtureInjector implements TestListener
{

/**
Expand All @@ -39,7 +39,7 @@ class FixtureInjector implements PHPUnit_Framework_TestListener
/**
* Holds a reference to the container test suite
*
* @var \PHPUnit_Framework_TestSuite
* @var \PHPUnit\Framework\TestSuite
*/
protected $_first;

Expand All @@ -61,10 +61,10 @@ public function __construct(FixtureManager $manager)
* Iterates the tests inside a test suite and creates the required fixtures as
* they were expressed inside each test case.
*
* @param \PHPUnit_Framework_TestSuite $suite The test suite
* @param \PHPUnit\Framework\TestSuite $suite The test suite
* @return void
*/
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
public function startTestSuite(TestSuite $suite)
{
if (empty($this->_first)) {
$this->_first = $suite;
Expand All @@ -75,10 +75,10 @@ public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
* Destroys the fixtures created by the fixture manager at the end of the test
* suite run
*
* @param \PHPUnit_Framework_TestSuite $suite The test suite
* @param \PHPUnit\Framework\TestSuite $suite The test suite
* @return void
*/
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
public function endTestSuite(TestSuite $suite)
{
if ($this->_first === $suite) {
$this->_fixtureManager->shutDown();
Expand All @@ -88,70 +88,70 @@ public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
/**
* Not Implemented
*
* @param \PHPUnit_Framework_Test $test The test to add errors from.
* @param \PHPUnit\Framework\Test $test The test to add errors from.
* @param \Exception $e The exception
* @param float $time current time
* @return void
*/
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
public function addError(Test $test, Exception $e, $time)
{
}

/**
* Not Implemented
*
* @param \PHPUnit_Framework_Test $test The test to add warnings from.
* @param \PHPUnit_Framework_Warning $e The warning
* @param \PHPUnit\Framework\Test $test The test to add warnings from.
* @param \PHPUnit\Framework\Warning $e The warning
* @param float $time current time
* @return void
*/
public function addWarning(PHPUnit_Framework_Test $test, PHPUnit_Framework_Warning $e, $time)
public function addWarning(Test $test, Warning $e, $time)
{
}

/**
* Not Implemented
*
* @param \PHPUnit_Framework_Test $test The test case
* @param \PHPUnit_Framework_AssertionFailedError $e The failed assertion
* @param \PHPUnit\Framework\Test $test The test case
* @param \PHPUnit\Framework\AssertionFailedError $e The failed assertion
* @param float $time current time
* @return void
*/
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
public function addFailure(Test $test, AssertionFailedError $e, $time)
{
}

/**
* Not Implemented
*
* @param \PHPUnit_Framework_Test $test The test case
* @param \PHPUnit\Framework\Test $test The test case
* @param \Exception $e The incomplete test error.
* @param float $time current time
* @return void
*/
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
public function addIncompleteTest(Test $test, Exception $e, $time)
{
}

/**
* Not Implemented
*
* @param \PHPUnit_Framework_Test $test The test case
* @param \PHPUnit\Framework\Test $test The test case
* @param \Exception $e Skipped test exception
* @param float $time current time
* @return void
*/
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
public function addSkippedTest(Test $test, Exception $e, $time)
{
}

/**
* Adds fixtures to a test case when it starts.
*
* @param \PHPUnit_Framework_Test $test The test case
* @param \PHPUnit\Framework\Test $test The test case
* @return void
*/
public function startTest(PHPUnit_Framework_Test $test)
public function startTest(Test $test)
{
$test->fixtureManager = $this->_fixtureManager;
if ($test instanceof TestCase) {
Expand All @@ -163,11 +163,11 @@ public function startTest(PHPUnit_Framework_Test $test)
/**
* Unloads fixtures from the test case.
*
* @param \PHPUnit_Framework_Test $test The test case
* @param \PHPUnit\Framework\Test $test The test case
* @param float $time current time
* @return void
*/
public function endTest(PHPUnit_Framework_Test $test, $time)
public function endTest(Test $test, $time)
{
if ($test instanceof TestCase) {
$this->_fixtureManager->unload($test);
Expand All @@ -177,12 +177,12 @@ public function endTest(PHPUnit_Framework_Test $test, $time)
/**
* Not Implemented
*
* @param \PHPUnit_Framework_Test $test The test case
* @param \PHPUnit\Framework\Test $test The test case
* @param \Exception $e The exception to track
* @param float $time current time
* @return void
*/
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time)
public function addRiskyTest(Test $test, Exception $e, $time)
{
}
}
3 changes: 1 addition & 2 deletions src/TestSuite/IntegrationTestCase.php
Expand Up @@ -24,7 +24,6 @@
use Cake\View\Helper\SecureFieldTokenTrait;
use Exception;
use LogicException;
use PHPUnit_Exception;

/**
* A test case class intended to make integration tests of
Expand Down Expand Up @@ -420,7 +419,7 @@ protected function _sendRequest($url, $method, $data = [])
$response = $dispatcher->execute($request);
$this->_requestSession = $request['session'];
$this->_response = $response;
} catch (PHPUnit_Exception $e) {
} catch (\PHPUnit\Exception $e) {
throw $e;
} catch (DatabaseException $e) {
throw $e;
Expand Down
4 changes: 2 additions & 2 deletions src/TestSuite/TestCase.php
Expand Up @@ -24,12 +24,12 @@
use Cake\TestSuite\Constraint\EventFiredWith;
use Cake\Utility\Inflector;
use Exception;
use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase as BaseTestCase;

/**
* Cake TestCase class
*/
abstract class TestCase extends PHPUnit_Framework_TestCase
abstract class TestCase extends BaseTestCase
{

/**
Expand Down
4 changes: 2 additions & 2 deletions src/TestSuite/TestSuite.php
Expand Up @@ -17,12 +17,12 @@
namespace Cake\TestSuite;

use Cake\Filesystem\Folder;
use PHPUnit_Framework_TestSuite;
use PHPUnit\Framework\TestSuite as BaseTestSuite;

/**
* A class to contain test cases and run them with shared fixtures
*/
class TestSuite extends PHPUnit_Framework_TestSuite
class TestSuite extends BaseTestSuite
{

/**
Expand Down
12 changes: 12 additions & 0 deletions src/TestSuite/phpunit-forward-compat.php
@@ -0,0 +1,12 @@
<?php

if (!class_exists('PHPUnit\Runner\Version')) {
class_alias('PHPUnit_Framework_TestSuite', 'PHPUnit\Framework\TestSuite');
class_alias('PHPUnit_Framework_Test', 'PHPUnit\Framework\Test');
class_alias('PHPUnit_Framework_TestResult', 'PHPUnit\Framework\TestResult');
class_alias('PHPUnit_Framework_AssertionFailedError', 'PHPUnit\Framework\AssertionFailedError');
class_alias('PHPUnit_Framework_Error', 'PHPUnit\Framework\Error\Error');
class_alias('PHPUnit_Framework_Error_Warning', 'PHPUnit\Framework\Error\Warning');
class_alias('PHPUnit_Framework_Constraint', 'PHPUnit\Framework\Constraint\Constraint');
class_alias('PHPUnit_Framework_ExpectationFailedException', 'PHPUnit\Framework\ExpectationFailedException');
}

0 comments on commit a67e549

Please sign in to comment.