Problem
The unit test for /core/tests/Drupal/Tests/Core/File/FileSystemTest.php has a set of bitwise operations performed during test on Windows platform. These operations is causing the unit test to fail unexpectedly. The operations does not seem to do anything useful. Removal of it allows the test to pass.
======Output of Unit Test======
Drupal\Tests\Core\File\FileSystemTest::testChmodFile
Failed asserting that 436 is identical to 438.
\core\tests\Drupal\Tests\Core\File\FileSystemTest.php:176
\core\tests\Drupal\Tests\Core\File\FileSystemTest.php:51
========================
The system I'm testing on:
PHP 7.1.4 32bit
Apache 2.4.25
Windows 7
Drupal 8.4.x
Proposed resolution
The description for this operations seems to hint on compatibility issues that doesn't exists on Windows. The fileperms is returning the integer values accurately on Windows. Thus, I recommend removal of an obsolete function that causes Unit Test to fail on Windows.
[Edit Apr. 9, 2022]:
I agree with the removing of the code that does "Magic Things" for Windows only in \Drupal\Tests\Core\File\FileSystemTest::assertFilePermissions for three reasons
- The value of
$expected_modeis already the same as$actual_modebefore the "Magic Things" happen so there's no need for it (See screenshot here: https://www.drupal.org/files/issues/2022-04-09/2022-04-09_12-51-52.png ). - Also the "Magic Things" currently causes
assertFilePermissionsto fail on Windows OS: - The fact that I need to post a screenshot and the test output, and can't give you a fail-test patch also is another reason for removal: The "Magic Things" code-path is never tested by TestBot since it doesn't run Windows OS. I think since there's no way to test it currently, it shouldn't be in a test in the first place.
Testing Drupal\Tests\Core\File\FileSystemTest
FF...... 8 / 8 (100%)
Time: 00:00.083, Memory: 10.00 MB
There were 2 failures:
1) Drupal\Tests\Core\File\FileSystemTest::testChmodFile
Failed asserting that 436 is identical to 438.
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Constraint.php:121
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\IsIdentical.php:94
D:\htdocs\drupal\core\tests\Drupal\Tests\Core\File\FileSystemTest.php:159
D:\htdocs\drupal\core\tests\Drupal\Tests\Core\File\FileSystemTest.php:59
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestResult.php:726
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestSuite.php:678
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:670
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:143
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:96
2) Drupal\Tests\Core\File\FileSystemTest::testChmodDir
Failed asserting that 509 is identical to 511.
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Constraint.php:121
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\IsIdentical.php:94
D:\htdocs\drupal\core\tests\Drupal\Tests\Core\File\FileSystemTest.php:159
D:\htdocs\drupal\core\tests\Drupal\Tests\Core\File\FileSystemTest.php:73
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestResult.php:726
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestSuite.php:678
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:670
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:143
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:96
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | windows-php-version.png | 31.06 KB | mstrelan |
| #24 | windows-php-head.png | 77.15 KB | mstrelan |
| #17 | 2022-04-09_12-51-52.png | 195.31 KB | spokje |
| #23 | windows-php-2911379.png | 60.43 KB | mstrelan |
| #23 | windows-php-HEAD.png | 60.61 KB | mstrelan |
Issue fork drupal-2911379
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
ProFire commentedComment #4
michaellenahan commentedComment #5
michaellenahan commentedComment #6
joshmillerComment #11
spokjeComment #12
spokjeComment #13
spokjeUsed patch #3 (
2911379-fix-for-fileperm.patch) as base for the newly created MR.Comment #15
spokjeComment #16
spokjeUpdated IS with my rationale why removing this code is OK.
Comment #17
spokjeComment #18
spokjeComment #19
spokjeComment #20
smustgrave commentedSeems like a simple fix.
Comment #21
quietone commentedHas this had manual testing on windows?
Comment #22
spokjeCan't remember, so officially that would be a No, I guess.
Comment #23
mstrelan commentedTested on Windows 10 with PHP 8.2.4 VS16 x64 Non Thread Safe (2023-Mar-14 18:22:42)
Can confirm the test was broken before and is fixed after.
Comment #24
mstrelan commentedApologies, I forgot to run composer install for the second screenshot in the previous comment. Here is the failing test.
Comment #25
larowlanCrediting mstrelan for manual testing. Booting into windows and installing PHP is a massive effort 🙌
Comment #29
larowlanCommitted to 10.1.x and backported to 10.0.x and 9.5.x for consistency