Unneccessary bitwise operation for file permissions check on Windows

Created on 25 September 2017, about 7 years ago
Updated 30 March 2023, over 1 year ago

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

  1. The value of $expected_mode is already the same as $actual_mode before 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 ).
  2. Also the "Magic Things" currently causes assertFilePermissions to fail on Windows OS:
  3. 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
      
  4. 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.
🐛 Bug report
Status

Fixed

Version

9.5

Component
PHPUnit 

Last updated about 19 hours ago

Created by

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024