codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.4k stars 1.9k forks source link

Bug: The unit test of `tests/system/Cache/Handlers/FileHandlerTest` cannot pass. #6882

Closed ping-yee closed 1 year ago

ping-yee commented 2 years ago

PHP Version

8.1

CodeIgniter4 Version

4.2.10

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

cli-server (PHP built-in webserver)

Database

No response

What happened?

$ ./vendor/bin/phpunit tests/system/Cache/Handlers/FileHandlerTest.php 
PHPUnit 9.5.25 #StandWithUkraine

Runtime:       PHP 8.1.12
Configuration: /mnt/d/CodeIgniter4/phpunit.xml.dist
Warning:       No code coverage driver available

.F...F..........FFF....                                                                                      23 / 23 (100%)

Nexus\PHPUnit\Extension\Tachycardia identified these 2 slow tests:
⚠  Took 0.72s from 0.50s limit to run CodeIgniter\\Cache\\Handlers\\FileHandlerTest::testDeleteMatchingSuffix
⚠  Took 0.71s from 0.50s limit to run CodeIgniter\\Cache\\Handlers\\FileHandlerTest::testDeleteMatchingPrefix

Time: 00:09.449, Memory: 10.00 MB

There were 5 failures:

1) CodeIgniter\Cache\Handlers\FileHandlerTest::testNewWithNonWritablePath
Failed asserting that exception of type "CodeIgniter\Cache\Exceptions\CacheException" is thrown.

2) CodeIgniter\Cache\Handlers\FileHandlerTest::testSave
Failed asserting that true is false.

/mnt/d/CodeIgniter4/tests/system/Cache/Handlers/FileHandlerTest.php:140

3) CodeIgniter\Cache\Handlers\FileHandlerTest::testSaveMode with data set #0 (416, '640')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'640'
+'777'

/mnt/d/CodeIgniter4/tests/system/Cache/Handlers/FileHandlerTest.php:285

4) CodeIgniter\Cache\Handlers\FileHandlerTest::testSaveMode with data set #1 (384, '600')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'600'
+'777'

/mnt/d/CodeIgniter4/tests/system/Cache/Handlers/FileHandlerTest.php:285

5) CodeIgniter\Cache\Handlers\FileHandlerTest::testSaveMode with data set #2 (432, '660')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'660'
+'777'

/mnt/d/CodeIgniter4/tests/system/Cache/Handlers/FileHandlerTest.php:285

FAILURES!
Tests: 23, Assertions: 55, Failures: 5.

Steps to Reproduce

Run ./vendor/bin/phpunit tests/system/Cache/Handlers/FileHandlerTest.php

Expected Output

All passed.

Anything else?

No response

kenjis commented 2 years ago

Cannot reproduce in develop.

$ ./vendor/bin/phpunit tests/system/Cache/Handlers/FileHandlerTest.php 
PHPUnit 9.5.26 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.12
Configuration: /Users/kenji/work/codeigniter/official/CodeIgniter4/phpunit.xml

.......................                                                                               23 / 23 (100%)

Time: 00:06.308, Memory: 14.00 MB

OK (23 tests, 55 assertions)
paulbalandan commented 2 years ago

chmod does not work as expected for Windows, as far as I know. that's why the failures occur:

$ vendor/bin/phpunit --filter FileHandlerTest --no-coverage       
PHPUnit 9.5.26 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.12
Configuration: C:\Users\P\Desktop\Web Dev\CodeIgniter4\phpunit.xml.dist

...F...F..........FFFF.......                                                                                      29 / 29 (100%)

Time: 00:07.399, Memory: 48.00 MB

There were 6 failures:

1) CodeIgniter\Cache\Handlers\FileHandlerTest::testNewWithNonWritablePath
Failed asserting that exception of type "CodeIgniter\Cache\Exceptions\CacheException" is thrown.

2) CodeIgniter\Cache\Handlers\FileHandlerTest::testSave
Failed asserting that true is false.

C:\Users\P\Desktop\Web Dev\CodeIgniter4\tests\system\Cache\Handlers\FileHandlerTest.php:140

3) CodeIgniter\Cache\Handlers\FileHandlerTest::testSaveMode with data set #0 (416, '640')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'640'
+'666'

C:\Users\P\Desktop\Web Dev\CodeIgniter4\tests\system\Cache\Handlers\FileHandlerTest.php:285

4) CodeIgniter\Cache\Handlers\FileHandlerTest::testSaveMode with data set #1 (384, '600')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'600'
+'666'

C:\Users\P\Desktop\Web Dev\CodeIgniter4\tests\system\Cache\Handlers\FileHandlerTest.php:285

5) CodeIgniter\Cache\Handlers\FileHandlerTest::testSaveMode with data set #2 (432, '660')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'660'
+'666'

C:\Users\P\Desktop\Web Dev\CodeIgniter4\tests\system\Cache\Handlers\FileHandlerTest.php:285

6) CodeIgniter\Cache\Handlers\FileHandlerTest::testSaveMode with data set #3 (511, '777')
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'777'
+'666'

C:\Users\P\Desktop\Web Dev\CodeIgniter4\tests\system\Cache\Handlers\FileHandlerTest.php:285

FAILURES!
Tests: 29, Assertions: 65, Failures: 6.
paulbalandan commented 2 years ago

The best way here is to have $this->markTestSkipped(...) for chmod related tests when running on Windows.

ping-yee commented 2 years ago

@paulbalandan Thank you! I'll follow what you say and sent a PR.

ping-yee commented 2 years ago

Does the condition work in WSL2?

if ('\\' === DIRECTORY_SEPARATOR) {
    $this->markTestSkipped('chmod does not work as expected on Windows');
}

I test the test case CodeIgniter\Commands\GeneratorsTest::testGenerateFileFailsOnUnwritableDirectory that use this condition but I still get the failure occurred.

$ ./vendor/bin/phpunit tests/system/Commands/GeneratorsTest.php 
PHPUnit 9.5.25 #StandWithUkraine

Runtime:       PHP 8.1.12
Configuration: /mnt/d/CodeIgniter4/phpunit.xml.dist
Warning:       No code coverage driver available

...F...                                                                                                          7 / 7 (100%)

Nexus\PHPUnit\Extension\Tachycardia identified this sole slow test:
⚠  Took 0.87s from 0.50s limit to run CodeIgniter\\Commands\\GeneratorsTest::testGenerateFileCreated

Time: 00:02.210, Memory: 10.00 MB

There was 1 failure:

1) CodeIgniter\Commands\GeneratorsTest::testGenerateFileFailsOnUnwritableDirectory
Failed asserting that 'File created: APPPATH/Filters/Permissions.php\n
\n
' contains "Error while creating file: ".

/mnt/d/CodeIgniter4/tests/system/Commands/GeneratorsTest.php:84

FAILURES!
Tests: 7, Assertions: 11, Failures: 1.
paulbalandan commented 2 years ago

When running on WSL, DIRECTORY_SEPARATOR is '/'

paulbalandan commented 2 years ago

@ping-yee I've added a PR for is_windows() function. Can you try if it correctly skips the test?

ping-yee commented 2 years ago

@paulbalandan Got it. I'll try it later.

ping-yee commented 2 years ago

@paulbalandan It work! it skip the test case in fileHandlerTest correctly. Waiting for your brench get merged, then I'll sent PR for this issue. Appreciated for your help!

paulbalandan commented 2 years ago

@ping-yee #6884 got merged but no specific WSL support. Please check https://github.com/codeigniter4/CodeIgniter4/pull/6884#issuecomment-1323676629 on how to make chmod work on your WSL

ping-yee commented 2 years ago

@paulbalandan Got it. I'll try it later.