From bb5088cda3edea9f2361599f65a6ba02ba5523cd Mon Sep 17 00:00:00 2001 From: Lawrence Barsanti Date: Mon, 24 Nov 2014 14:51:36 -0500 Subject: [PATCH] PHPUnit can be included as a phar file. No need to install phpunit in order to run unit tests. Simply place 'phpunit.phar' in the vendors folder. --- lib/Cake/TestSuite/CakeTestRunner.php | 4 +++- lib/Cake/TestSuite/CakeTestSuiteCommand.php | 4 +++- lib/Cake/TestSuite/CakeTestSuiteDispatcher.php | 6 ++++++ lib/Cake/TestSuite/Reporter/CakeBaseReporter.php | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/Cake/TestSuite/CakeTestRunner.php b/lib/Cake/TestSuite/CakeTestRunner.php index 8e2fc4730..3aafdc198 100644 --- a/lib/Cake/TestSuite/CakeTestRunner.php +++ b/lib/Cake/TestSuite/CakeTestRunner.php @@ -15,7 +15,9 @@ * @license http://www.opensource.org/licenses/mit-license.php MIT License */ -require_once 'PHPUnit/TextUI/TestRunner.php'; +if (!defined('__PHPUNIT_PHAR__')) { + require_once 'PHPUnit/TextUI/TestRunner.php'; +} App::uses('CakeFixtureManager', 'TestSuite/Fixture'); diff --git a/lib/Cake/TestSuite/CakeTestSuiteCommand.php b/lib/Cake/TestSuite/CakeTestSuiteCommand.php index 363a0057a..c4134c535 100644 --- a/lib/Cake/TestSuite/CakeTestSuiteCommand.php +++ b/lib/Cake/TestSuite/CakeTestSuiteCommand.php @@ -16,7 +16,9 @@ * @license http://www.opensource.org/licenses/mit-license.php MIT License */ -require_once 'PHPUnit/TextUI/Command.php'; +if (!defined('__PHPUNIT_PHAR__')) { + require_once 'PHPUnit/TextUI/Command.php'; +} App::uses('CakeTestRunner', 'TestSuite'); App::uses('CakeTestLoader', 'TestSuite'); diff --git a/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php b/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php index 725df5eb1..8b8b1e3ca 100644 --- a/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php +++ b/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php @@ -151,6 +151,12 @@ class CakeTestSuiteDispatcher { } elseif (is_dir($vendor . DS . 'PHPUnit')) { ini_set('include_path', $vendor . PATH_SEPARATOR . ini_get('include_path')); break; + } elseif (is_file($vendor . DS . 'phpunit.phar')) { + $backup = $GLOBALS['_SERVER']['SCRIPT_NAME']; + $GLOBALS['_SERVER']['SCRIPT_NAME'] = '-'; + $included = include_once $vendor . DS . 'phpunit.phar'; + $GLOBALS['_SERVER']['SCRIPT_NAME'] = $backup; + return $included; } } include 'PHPUnit' . DS . 'Autoload.php'; diff --git a/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php b/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php index 3974bee2b..8cd1ca7a4 100644 --- a/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php +++ b/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php @@ -15,7 +15,9 @@ * @license http://www.opensource.org/licenses/mit-license.php MIT License */ -require_once 'PHPUnit/TextUI/ResultPrinter.php'; + if (!defined('__PHPUNIT_PHAR__')) { + require_once 'PHPUnit/TextUI/ResultPrinter.php'; +} /** * CakeBaseReporter contains common reporting features used in the CakePHP Test suite