Skip to content

Conversation

@kenjis
Copy link
Member

@kenjis kenjis commented Oct 16, 2021

Description
Fixes #3400

When you run the following command:

$ php spark test param1 param2 -opt1 opt1val

$params of the Test command would be:

Array
(
    [0] => param1
    [1] => param2
    [opt1] => opt1val
)

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis marked this pull request as draft October 16, 2021 05:45
@kenjis kenjis force-pushed the fix-command-params branch 4 times, most recently from 8db6a57 to a8dd95e Compare October 16, 2021 08:04
@kenjis kenjis marked this pull request as ready for review October 16, 2021 08:42
@kenjis kenjis changed the title fix: options are not passed to Command $params Fix options are not passed to Command $params Oct 16, 2021
@kenjis
Copy link
Member Author

kenjis commented Oct 17, 2021

I can't fix the test: https://github.com/codeigniter4/CodeIgniter4/pull/5206/files#diff-547eef440769bc0c1aac5c4f0a08ee7a180baa78a52bf5eb6d624fb0a77c04aaL81
It causes the error: Serialization of 'Closure' is not allowed

@kenjis
Copy link
Member Author

kenjis commented Oct 17, 2021

Another test error:

There was 1 error:

1) CodeIgniter\CodeIgniterTest::testControllersRunFilterByClassName
ErrorException: Undefined property: CodeIgniter\HTTP\IncomingRequest::$url

/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/CodeIgniterTest.php:186
/home/runner/work/CodeIgniter4/CodeIgniter4/system/CodeIgniter.php:780
/home/runner/work/CodeIgniter4/CodeIgniter4/system/CodeIgniter.php:397
/home/runner/work/CodeIgniter4/CodeIgniter4/system/CodeIgniter.php:318
/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/CodeIgniterTest.php:193

It is true, IncomingRequest::$url is not defined.

@paulbalandan
Copy link
Member

Use runTestInSeparateProcess or runTestsInSeparateProcess (for class level) to fix Serialization error

@kenjis kenjis force-pushed the fix-command-params branch from a2220f0 to 61c5960 Compare October 18, 2021 00:07
@kenjis
Copy link
Member Author

kenjis commented Oct 18, 2021

@paulbalandan

Use runTestInSeparateProcess or runTestsInSeparateProcess (for class level) to fix Serialization error

No, this is the opposite case. Adding @runInSeparateProcess caused the Serialization error.

I separated the test method to another test case, and fixed it.

@paulbalandan
Copy link
Member

I meant @runTestInSeparateProcess.

diff --git a/tests/system/CLI/ConsoleTest.php b/tests/system/CLI/ConsoleTest.php
index a5b3dd1e9..389bbe129 100644
--- a/tests/system/CLI/ConsoleTest.php
+++ b/tests/system/CLI/ConsoleTest.php
@@ -78,6 +78,9 @@ final class ConsoleTest extends CIUnitTestCase
         $this->assertSame('', $result);
     }

+    /**
+     * @runTestInSeparateProcess
+     */
     public function testRun()
     {
         $request = new CLIRequest(config('App'));
PS C:\Users\P\Desktop\Web Dev\CodeIgniter4> vendor/bin/phpunit --filter ConsoleTest
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.0.11 with Xdebug 3.0.4
Configuration: C:\Users\P\Desktop\Web Dev\CodeIgniter4\phpunit.xml.dist

....                                                                4 / 4 (100%)

Time: 00:05.281, Memory: 74.00 MB

OK (4 tests, 5 assertions)

Generating code coverage report in Clover XML format ... done [00:06.127]

@kenjis kenjis force-pushed the fix-command-params branch from 61c5960 to fc45e5a Compare October 18, 2021 12:54
@kenjis
Copy link
Member Author

kenjis commented Oct 18, 2021

In my understanding @runTestsInSeparateProcesses is class level.
https://phpunit.readthedocs.io/en/9.5/annotations.html#runtestsinseparateprocesses
So I put it in the class phpdoc.

As you say, @runTestsInSeparateProcesses can solve the Serialization error.

@paulbalandan
Copy link
Member

Yes. runTests is class level. but runTest (singular) is per test level.

@kenjis
Copy link
Member Author

kenjis commented Oct 18, 2021

No, it wasn't.

There are only @runTestsInSeparateProcesses and @runInSeparateProcess.
And @runTestsInSeparateProcesses is valid only in class doc comment.
@runInSeparateProcess is valid only in method doc comment.

They are just comment, so if we have one typo, it is just ignored.

Without them, all tests in ConsoleTest pass, but the constant SPARKED is defined.
To remove the constant, we have to separate the process.

@kenjis kenjis force-pushed the fix-command-params branch from fc45e5a to 9348899 Compare October 19, 2021 00:51
@kenjis
Copy link
Member Author

kenjis commented Oct 19, 2021

When I put only @runTestsInSeparateProcesses in ConsoleTest, Serialization of 'Closure' is not allowed.
Because global $routes contains Closure.

When I put @runTestsInSeparateProcesses and @preserveGlobalState disabled, stty: stdin isn't a terminal.
On GitHub Action:

There was 1 error:

1) CodeIgniter\CLI\ConsoleTest::testRun
PHPUnit\Framework\Exception: stty: 'standard input': Inappropriate ioctl for device

I can't write test for this PR.

@MGatner
Copy link
Member

MGatner commented Oct 20, 2021

Paul has much more recent experience with this but I can hop in and take a look if needed.

@kenjis
Copy link
Member Author

kenjis commented Oct 20, 2021

The problem is running ConsoleTest::testRun() in separate process causes stty: 'standard input': Inappropriate ioctl for device or stty: stdin isn't a terminal error.

I have no idea to solve it.

@paulbalandan
Copy link
Member

As far as I remember, calling script -e -c in GHA already solved that ioctl problem. It seems either adding the SPARKED constant or mocking the request caused this. Have you tried enabling only one at a time to see which is the problem?

@kenjis
Copy link
Member Author

kenjis commented Oct 20, 2021

@paulbalandan

It seems either adding the SPARKED constant or mocking the request caused this.

No. The request is not a mock. I just changed $this->app->setRequest() to Services::injectMock().
Adding @runTestsInSeparateProcesses caused this.

Adding @runTestsInSeparateProcesses and @preserveGlobalState disabled to
ConsoleTest on develop causes this error.

@kenjis kenjis added the help wanted More help is needed for the proper resolution of an issue or pull request label Oct 29, 2021
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 9, 2021
@kenjis kenjis force-pushed the fix-command-params branch from 1fbcd24 to a28e215 Compare January 30, 2022 11:18
@kenjis kenjis marked this pull request as draft February 20, 2022 00:51
@kenjis kenjis force-pushed the fix-command-params branch 3 times, most recently from 01081e8 to f488904 Compare February 20, 2022 01:24
@kenjis kenjis removed the help wanted More help is needed for the proper resolution of an issue or pull request label Feb 20, 2022
@kenjis kenjis marked this pull request as ready for review February 20, 2022 01:45
@kenjis kenjis force-pushed the fix-command-params branch from f488904 to 21a21cc Compare February 20, 2022 01:48
@kenjis
Copy link
Member Author

kenjis commented Feb 20, 2022

Updated completely.

@kenjis kenjis requested a review from paulbalandan February 20, 2022 01:52
@MGatner
Copy link
Member

MGatner commented Feb 20, 2022

Looks like maybe this needs to be rebased? Showing some of the work from the Context PR, unless I'm mistaken.

@kenjis
Copy link
Member Author

kenjis commented Feb 20, 2022

No, this is up to date.

@MGatner
Copy link
Member

MGatner commented Feb 22, 2022

Gotcha. The context comment on CodeIgniter threw me off.

@kenjis kenjis merged commit bb97748 into codeigniter4:develop Feb 23, 2022
@kenjis kenjis deleted the fix-command-params branch February 23, 2022 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: CLI options not present in $params when run through spark via terminal

4 participants