From deb8c8b305ce572e2fe0d0b623f3f4bbbf1ec3e8 Mon Sep 17 00:00:00 2001 From: Kamil Wylegala Date: Tue, 21 Dec 2021 23:29:35 +0100 Subject: [PATCH] Cake shell 'test' works - prints help info. --- README.md | 9 +++++++ composer.json | 2 +- lib/Cake/Console/Shell.php | 12 ++++++--- lib/Cake/TestSuite/CakeTestCase.php | 2 +- lib/Cake/TestSuite/CakeTestLoader.php | 26 +++++++++++++++---- .../TestSuite/CakeTestSuiteDispatcher.php | 12 ++++++--- 6 files changed, 49 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 2b22d9a06..d1258e48c 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,12 @@ It means that composer will look at `master` branch of repository configured und ### 2021-02-24 - Fixed ErrorHandler accordingly to PHP8 migration guide. Otherwise, error handler is logging too much and doesn't respect configured `error_reporting`. + +## Debugging cake console in PHPStorm + +Make sure PHP and XDebug extension are installed. + +1. Find `cake.php` in `lib/Cake/Console`. +2. Click with right mouse button and choose "Debug". +3. Go to debug configurations and edit this configuration. +4. Add argument e.g. `test`. diff --git a/composer.json b/composer.json index 23617dbf8..b87374646 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "ext-mcrypt": "You need to install ext-openssl or ext-mcrypt to use AES-256 encryption" }, "require-dev": { - "phpunit/phpunit": "^3.7", + "phpunit/phpunit": "^8.0", "cakephp/cakephp-codesniffer": "^1.0.0" }, "config": { diff --git a/lib/Cake/Console/Shell.php b/lib/Cake/Console/Shell.php index c8033e695..ada1c691f 100644 --- a/lib/Cake/Console/Shell.php +++ b/lib/Cake/Console/Shell.php @@ -355,6 +355,10 @@ class Shell extends CakeObject { */ public function hasMethod($name) { try { + if ($name === null) { + return false; + } + $method = new ReflectionMethod($this, $name); if (!$method->isPublic() || substr($name, 0, 1) === '_') { return false; @@ -983,7 +987,7 @@ class Shell extends CakeObject { /** * Configure the stdout logger - * + * * @return void */ protected function _configureStdOutLogger() { @@ -996,7 +1000,7 @@ class Shell extends CakeObject { /** * Configure the stderr logger - * + * * @return void */ protected function _configureStdErrLogger() { @@ -1009,8 +1013,8 @@ class Shell extends CakeObject { /** * Checks if the given logger is configured - * - * @param string $logger The name of the logger to check + * + * @param string $logger The name of the logger to check * @return bool */ protected function _loggerIsConfigured($logger) { diff --git a/lib/Cake/TestSuite/CakeTestCase.php b/lib/Cake/TestSuite/CakeTestCase.php index 11e022052..a2e96b551 100644 --- a/lib/Cake/TestSuite/CakeTestCase.php +++ b/lib/Cake/TestSuite/CakeTestCase.php @@ -24,7 +24,7 @@ App::uses('CakeTestFixture', 'TestSuite/Fixture'); * * @package Cake.TestSuite */ -abstract class CakeTestCase extends PHPUnit_Framework_TestCase { +abstract class CakeTestCase extends \PHPUnit\Framework\TestCase { /** * The class responsible for managing the creation, loading and removing of fixtures diff --git a/lib/Cake/TestSuite/CakeTestLoader.php b/lib/Cake/TestSuite/CakeTestLoader.php index 0599e1cb4..bd421b602 100644 --- a/lib/Cake/TestSuite/CakeTestLoader.php +++ b/lib/Cake/TestSuite/CakeTestLoader.php @@ -18,6 +18,9 @@ * @package Cake.TestSuite */ +use PHPUnit\Runner\StandardTestSuiteLoader; +use PHPUnit\Runner\TestSuiteLoader; + /** * TestLoader for CakePHP Test suite. * @@ -25,21 +28,34 @@ * * @package Cake.TestSuite */ -class CakeTestLoader extends PHPUnit_Runner_StandardTestSuiteLoader { +class CakeTestLoader implements TestSuiteLoader { -/** + + private TestSuiteLoader $testSuiteLoader; + + public function __construct() + { + $this->testSuiteLoader = new StandardTestSuiteLoader(); + } + + /** * Load a file and find the first test case / suite in that file. * * @param string $filePath The file path to load * @param string $params Additional parameters * @return ReflectionClass */ - public function load($filePath, $params = '') { + public function load(string $filePath, string $params = '') : ReflectionClass { $file = $this->_resolveTestFile($filePath, $params); - return parent::load('', $file); + return $this->testSuiteLoader->load('', $file); } -/** + public function reload(ReflectionClass $aClass) : ReflectionClass + { + return $this->testSuiteLoader->reload($aClass); + } + + /** * Convert path fragments used by CakePHP's test runner to absolute paths that can be fed to PHPUnit. * * @param string $filePath The file path to load. diff --git a/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php b/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php index 4f997c078..344fbb820 100644 --- a/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php +++ b/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php @@ -19,6 +19,9 @@ /** * Path to the tests directory of the app. */ + +use PHPUnit\Framework\TestCase; + if (!defined('TESTS')) { define('TESTS', APP . 'Test' . DS); } @@ -149,7 +152,7 @@ class CakeTestSuiteDispatcher { * @return bool true if found, false otherwise */ public function loadTestFramework() { - if (class_exists('PHPUnit_Framework_TestCase')) { + if (class_exists(TestCase::class)) { return true; } $phpunitPath = 'phpunit' . DS . 'phpunit'; @@ -177,8 +180,11 @@ class CakeTestSuiteDispatcher { return $included; } } - include 'PHPUnit' . DS . 'Autoload.php'; - return class_exists('PHPUnit_Framework_TestCase'); + + //TODO: Remove code above. It should be enough to go directly to composer directory and get php unit. + include $vendor . DS . "autoload.php"; + + return class_exists(TestCase::class); } /**