Skip to content

Commit

Permalink
fix: spark can't use options in PHP 7.4
Browse files Browse the repository at this point in the history
Cannot unpack array with string keys
at SYSTEMPATH/CodeIgniter.php:893
  • Loading branch information
kenjis committed Mar 28, 2022
1 parent 7107e78 commit a5dbddd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
4 changes: 2 additions & 2 deletions system/CLI/CommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ 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])) {
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
2 changes: 1 addition & 1 deletion tests/system/CLI/CommandRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function testBadCommand()
*/
public function testRemapEmptyFirstParams()
{
self::$runner->_remap('anyvalue', null, 'list');
self::$runner->_remap('anyvalue', [null, 'list']);
$result = CITestStreamFilter::$buffer;

// make sure the result looks like a command list
Expand Down
31 changes: 31 additions & 0 deletions tests/system/SparkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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;

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

0 comments on commit a5dbddd

Please sign in to comment.