Browse Source

Add support for PHPUnit6 in the Cake\TestSuite

antograssiot 9 years ago
parent
commit
a67e549203

+ 1 - 1
composer.json

@@ -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": {

+ 1 - 0
phpunit.xml.dist

@@ -6,6 +6,7 @@
     stopOnFailure="false"
     syntaxCheck="false"
     bootstrap="./tests/bootstrap.php"
+    backupGlobals="true"
     >
     <php>
         <ini name="memory_limit" value="-1"/>

+ 4 - 4
src/TestSuite/Constraint/EventFired.php

@@ -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
@@ -28,7 +28,7 @@ class EventFired extends PHPUnit_Framework_Constraint
         $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.');
         }
     }
 

+ 5 - 5
src/TestSuite/Constraint/EventFiredWith.php

@@ -3,15 +3,15 @@ namespace Cake\TestSuite\Constraint;
 
 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
@@ -49,7 +49,7 @@ class EventFiredWith extends PHPUnit_Framework_Constraint
         $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.');
         }
     }
 
@@ -81,7 +81,7 @@ class EventFiredWith extends PHPUnit_Framework_Constraint
         $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 */

+ 29 - 29
src/TestSuite/Fixture/FixtureInjector.php

@@ -16,17 +16,17 @@ namespace Cake\TestSuite\Fixture;
 
 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
 {
 
     /**
@@ -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;
 
@@ -61,10 +61,10 @@ class FixtureInjector implements PHPUnit_Framework_TestListener
      * 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;
@@ -75,10 +75,10 @@ class FixtureInjector implements PHPUnit_Framework_TestListener
      * 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();
@@ -88,70 +88,70 @@ class FixtureInjector implements PHPUnit_Framework_TestListener
     /**
      * 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) {
@@ -163,11 +163,11 @@ class FixtureInjector implements PHPUnit_Framework_TestListener
     /**
      * 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);
@@ -177,12 +177,12 @@ class FixtureInjector implements PHPUnit_Framework_TestListener
     /**
      * 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)
     {
     }
 }

+ 1 - 2
src/TestSuite/IntegrationTestCase.php

@@ -24,7 +24,6 @@ use Cake\Utility\Text;
 use Cake\View\Helper\SecureFieldTokenTrait;
 use Exception;
 use LogicException;
-use PHPUnit_Exception;
 
 /**
  * A test case class intended to make integration tests of
@@ -420,7 +419,7 @@ abstract class IntegrationTestCase extends TestCase
             $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;

+ 2 - 2
src/TestSuite/TestCase.php

@@ -24,12 +24,12 @@ use Cake\TestSuite\Constraint\EventFired;
 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
 {
 
     /**

+ 2 - 2
src/TestSuite/TestSuite.php

@@ -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
 {
 
     /**

+ 12 - 0
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');
+}