Problem
The following Unit Test does not pass in Windows environment due to hardcoded use of directory separator.
- www/core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php
- www/core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php
- www/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
Running the tests mentioned in the IS on Windows 11 _without_ the patch on 10.1.x
:
$ ../vendor/bin/phpunit tests/Drupal/Tests/Component/FileCache/FileCacheTest.php
PHPUnit 9.5.26 by Sebastian Bergmann and contributors.
Testing Drupal\Tests\Component\FileCache\FileCacheTest
F.F. 4 / 4 (100%)
Time: 00:30.572, Memory: 10.00 MB
There were 2 failures:
1) Drupal\Tests\Component\FileCache\FileCacheTest::testGet
Failed asserting that null matches expected 42.
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Equality\IsEqual.php:96
D:\htdocs\drupal\core\tests\Drupal\Tests\Component\FileCache\FileCacheTest.php:60
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestResult.php:728
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestSuite.php:673
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:661
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:144
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:97
2) Drupal\Tests\Component\FileCache\FileCacheTest::testSet
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
'prefix:test:D:\htdocs\drupal\core\tests\Drupal\Tests\Component\FileCache\Fixtures\llama-23.txt' => Array (
'mtime' => 1661603362
- 'filepath' => 'D:\htdocs\drupal\core\tests\Drupal\Tests\Component\FileCache\Fixtures\llama-23.txt'
+ 'filepath' => 'D:\htdocs\drupal\core\tests\Drupal\Tests\Component\FileCache/Fixtures/llama-23.txt'
'data' => 23
)
)
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Equality\IsEqual.php:96
D:\htdocs\drupal\core\tests\Drupal\Tests\Component\FileCache\FileCacheTest.php:116
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestResult.php:728
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestSuite.php:673
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:661
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:144
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:97
FAILURES!
Tests: 4, Assertions: 8, Failures: 2.
$ ../vendor/bin/phpunit tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php
PHPUnit 9.5.26 by Sebastian Bergmann and contributors.
Testing Drupal\Tests\Component\ClassFinder\ClassFinderTest
F 1 / 1 (100%)
Time: 00:00.253, Memory: 10.00 MB
There was 1 failure:
1) Drupal\Tests\Component\ClassFinder\ClassFinderTest::testFindFile
Failed asserting that 'D:\htdocs\drupal\core\tests\Drupal\Tests\Component\ClassFinder\ClassFinderTest.php' ends with "core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php".
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Constraint.php:122
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Constraint.php:55
D:\htdocs\drupal\core\tests\Drupal\Tests\Component\ClassFinder\ClassFinderTest.php:23
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestResult.php:728
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestSuite.php:673
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:661
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:144
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:97
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
$ ../vendor/bin/phpunit tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
PHPUnit 9.5.26 by Sebastian Bergmann and contributors.
Testing Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest
FFFF 4 / 4 (100%)
Time: 00:00.416, Memory: 10.00 MB
There were 4 failures:
1) Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest::testDiscovery
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
Array &0 (
'id' => 'item1'
'name' => 'test1 item 1'
- '_discovered_file_path' => 'vfs://modules/test_1/subdir1/item_1.test.yml'
+ '_discovered_file_path' => 'vfs://modules/test_1/subdir1\item_1.test.yml'
)
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Constraint.php:122
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\IsIdentical.php:79
D:\htdocs\drupal\core\tests\Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest.php:83
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestResult.php:728
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestSuite.php:673
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:661
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:144
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:97
2) Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest::testDiscoveryAlternateId
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
Array &0 (
'alt_id' => 'item1'
'id' => 'ignored'
- '_discovered_file_path' => 'vfs://modules/test_1/item_1.test.yml'
+ '_discovered_file_path' => 'vfs://modules/test_1\item_1.test.yml'
)
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Constraint.php:122
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\IsIdentical.php:79
D:\htdocs\drupal\core\tests\Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest.php:116
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestResult.php:728
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestSuite.php:673
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:661
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:144
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:97
3) Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest::testDiscoveryNoIdException
Failed asserting that exception message 'The vfs://modules/test_1\item_1.test.yml contains no data in the identifier key 'id'' contains 'The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key 'id''.
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Constraint.php:122
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Constraint.php:55
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestResult.php:728
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestSuite.php:673
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:661
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:144
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:97
4) Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest::testDiscoveryInvalidYamlException
Failed asserting that exception message 'The vfs://modules/test_1\item_1.test.yml contains invalid YAML' contains 'The vfs://modules/test_1/item_1.test.yml contains invalid YAML'.
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Constraint.php:122
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\Constraint\Constraint.php:55
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestResult.php:728
D:\htdocs\drupal\vendor\phpunit\phpunit\src\Framework\TestSuite.php:673
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:661
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:144
D:\htdocs\drupal\vendor\phpunit\phpunit\src\TextUI\Command.php:97
FAILURES!
Tests: 4, Assertions: 6, Failures: 4.
Proposed resolution
Use of DIRECTORY_SEPARATOR constant value instead of the hardcoding the directory separator in paths.
Attached in the patch file.