Cake shell 'test' works - prints help info.

This commit is contained in:
Kamil Wylegala 2021-12-21 23:29:35 +01:00
parent 58e843e981
commit deb8c8b305
6 changed files with 49 additions and 14 deletions

View file

@ -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`.

View file

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

View file

@ -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;

View file

@ -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

View file

@ -18,6 +18,9 @@
* @package Cake.TestSuite
*/
use PHPUnit\Runner\StandardTestSuiteLoader;
use PHPUnit\Runner\TestSuiteLoader;
/**
* TestLoader for CakePHP Test suite.
*
@ -25,7 +28,15 @@
*
* @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.
@ -34,9 +45,14 @@ class CakeTestLoader extends PHPUnit_Runner_StandardTestSuiteLoader {
* @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);
}
/**

View file

@ -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);
}
/**