Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions system/CLI/CommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,14 @@ public function __construct()
* so we have the chance to look for a Command first.
*
* @param string $method
* @param array ...$params
* @param array $params
*
* @throws ReflectionException
*
* @return mixed
*/
public function _remap($method, ...$params)
public function _remap($method, $params)
{
// The first param is usually empty, so scrap it.
if (empty($params[0])) {
array_shift($params);
}

return $this->index($params);
}

Expand Down
10 changes: 6 additions & 4 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -884,14 +884,16 @@ protected function runController($class)
/** @var CLIRequest $request */
$request = $this->request;
$params = $request->getArgs();

$output = $class->_remap($this->method, $params);
} else {
// This is a Web request or PHP CLI request
$params = $this->router->params();
}

$output = method_exists($class, '_remap')
? $class->_remap($this->method, ...$params)
: $class->{$this->method}(...$params);
$output = method_exists($class, '_remap')
? $class->_remap($this->method, ...$params)
: $class->{$this->method}(...$params);
}

$this->benchmark->stop('controller');

Expand Down
12 changes: 0 additions & 12 deletions tests/system/CLI/CommandRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,4 @@ public function testBadCommand()
// make sure the result looks like a command list
$this->assertStringContainsString('Command "bogus" not found', CITestStreamFilter::$buffer);
}

/**
* @TODO When the first param is empty? Use case?
*/
public function testRemapEmptyFirstParams()
{
self::$runner->_remap('anyvalue', null, 'list');
$result = CITestStreamFilter::$buffer;

// make sure the result looks like a command list
$this->assertStringContainsString('Lists the available commands.', $result);
}
}
29 changes: 29 additions & 0 deletions tests/system/SparkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter;

use CodeIgniter\Test\CIUnitTestCase;

/**
* @internal
*/
final class SparkTest extends CIUnitTestCase
{
public function testCanUseOption()
{
ob_start();
passthru('php spark list --simple');
$output = ob_get_clean();

$this->assertStringContainsString('cache:clear', $output);
}
}
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ BREAKING
- The ``CodeIgniter\CodeIgniter`` class has a new property ``$context`` and it must have the correct context at runtime. So the following files have been changed:
- ``public/index.php``
- ``spark``
- The method signature of ``CodeIgniter\CLI\CommandRunner::_remap()`` has been changed to fix a bug.

Enhancements
************
Expand Down