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.

Comments

ProFire created an issue. See original summary.

ProFire’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, fix-for-unit-test-windows.patch, failed testing. View results

ProFire’s picture

Issue tags: +Unit tests
StatusFileSize
new9.02 KB
ProFire’s picture

Status: Needs work » Needs review
michaellenahan’s picture

Issue tags: +Novice
michaellenahan’s picture

Issue tags: +Vienna2017
a.dmitriiev’s picture

The test results on Windows 10, PHP version 7.0.2

PS C:\xampp\htdocs\d8\core> php ..\vendor\phpunit\phpunit\phpunit .\tests\Drupal\Tests\Component\FileCache\FileCacheFactoryTest.php
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\Component\FileCache\FileCacheFactoryTest
...........

Time: 8.69 seconds, Memory: 6.00MB

OK (11 tests, 13 assertions)

PS C:\xampp\htdocs\d8\core> php ..\vendor\phpunit\phpunit\phpunit .\tests\Drupal\Tests\Component\ClassFinder\ClassFinderTest.php
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\Component\ClassFinder\ClassFinderTest
.

Time: 8.67 seconds, Memory: 6.00MB

OK (1 test, 4 assertions)

PS C:\xampp\htdocs\d8\core> php ..\vendor\phpunit\phpunit\phpunit .\tests\Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest.php
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest
....

Time: 8.77 seconds, Memory: 6.00MB

OK (4 tests, 16 assertions)

a.dmitriiev’s picture

Status: Needs review » Reviewed & tested by the community

Works on Windows.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: 2911377-fix-for-unit-test.patch, failed testing. View results

a.dmitriiev’s picture

Status: Needs work » Reviewed & tested by the community

Just resave the issue, because the test failed on missing CI Job

xjm’s picture

Since this is a change that impacts the test runner, let's make sure we have a passing test run. I am re-queuing the test to make sure the missing job was unrelated.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs review
  1. +++ b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
    @@ -80,18 +80,18 @@ public function testDiscovery() {
    -    $this->assertSame(['id' => 'item1', 'name' => 'test1 item 1', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/subdir1/item_1.test.yml'], $data['test_1']['item1']);
    -    $this->assertSame(['id' => 'item2', 'name' => 'test1 item 2', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/subdir2/item_2.test.yml'], $data['test_1']['item2']);
    +    $this->assertSame(['id' => 'item1', 'name' => 'test1 item 1', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/subdir1' . DIRECTORY_SEPARATOR . 'item_1.test.yml'], $data['test_1']['item1']);
    +    $this->assertSame(['id' => 'item2', 'name' => 'test1 item 2', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/subdir2' . DIRECTORY_SEPARATOR . 'item_2.test.yml'], $data['test_1']['item2']);
    ...
    -    $this->assertSame(['id' => 'item3', 'name' => 'test2 item 3', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_2/subdir1/item_3.test.yml'], $data['test_2']['item3']);
    +    $this->assertSame(['id' => 'item3', 'name' => 'test2 item 3', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_2/subdir1' . DIRECTORY_SEPARATOR . 'item_3.test.yml'], $data['test_2']['item3']);
    ...
    -    $this->assertSame(['id' => 'item4', 'name' => 'test4 item 4', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1/item_4.test.yml'], $data['test_4']['item4']);
    -    $this->assertSame(['id' => 'item5', 'name' => 'test4 item 5', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1/item_5.test.yml'], $data['test_4']['item5']);
    -    $this->assertSame(['id' => 'item6', 'name' => 'test4 item 6', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1/item_6.test.yml'], $data['test_4']['item6']);
    +    $this->assertSame(['id' => 'item4', 'name' => 'test4 item 4', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1' . DIRECTORY_SEPARATOR . 'item_4.test.yml'], $data['test_4']['item4']);
    +    $this->assertSame(['id' => 'item5', 'name' => 'test4 item 5', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1' . DIRECTORY_SEPARATOR . 'item_5.test.yml'], $data['test_4']['item5']);
    +    $this->assertSame(['id' => 'item6', 'name' => 'test4 item 6', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1' . DIRECTORY_SEPARATOR . 'item_6.test.yml'], $data['test_4']['item6']);
    
    @@ -113,7 +113,7 @@ public function testDiscoveryAlternateId() {
    -    $this->assertSame(['alt_id' => 'item1', 'id' => 'ignored', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/item_1.test.yml'], $data['test_1']['item1']);
    +    $this->assertSame(['alt_id' => 'item1', 'id' => 'ignored', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1' . DIRECTORY_SEPARATOR . 'item_1.test.yml'], $data['test_1']['item1']);
    

    Why is it that only some slashes need to be converted/fixed in these?

  2. +++ b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
    @@ -124,7 +124,7 @@ public function testDiscoveryAlternateId() {
    -    $this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1/item_1.test.yml contains no data in the identifier key \'id\'');
    +    $this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1' . DIRECTORY_SEPARATOR . 'item_1.test.yml contains no data in the identifier key \'id\'');
    
    @@ -144,7 +144,7 @@ public function testDiscoveryNoIdException() {
    -    $this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1/item_1.test.yml contains invalid YAML');
    +    $this->setExpectedException(DiscoveryException::class, 'The vfs://modules/test_1' . DIRECTORY_SEPARATOR . 'item_1.test.yml contains invalid YAML');
    

    Do we need to make the change in the test messages?

ProFire’s picture

1) Only some slashes are converted because from Line 60 to Line 78, the slashes are defined statically as forward slash. Thus the output of YamlDirectoryDiscovery($directories, 'test') at Line 80 will output exactly as statically defined.

Only the slashes that are not statically defined is using the DIRECTORY_SEPARATOR constant.

2) Yes. Similar to (1), on Line 135 and Line 155, the slashes are statically defined. The exception messages will look like these on Windows respectively:
The vfs://modules/test_1\item_1.test.yml contains no data in the identifier key 'id'
The vfs://modules/test_1\item_1.test.yml contains invalid YAML

Only the slashes that are not statically defined is using the DIRECTORY_SEPARATOR constant.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

neclimdul’s picture

Status: Needs review » Needs work

At the very least don't touch the VFS entries. If those are failing we need a more detailed report because those do not touch the file system and are handled entirely in code through streams not by the operating system.

I'd like more information on what the errors are specifically being reported are so I can try to recreate them since Windows should handle the forward slashes just fine.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

MerryHamster’s picture

Version: 8.6.x-dev » 8.7.x-dev
MerryHamster’s picture

StatusFileSize
new7.91 KB

Only reroll #4 patch for 8.7.x

MerryHamster’s picture

Status: Needs work » Needs review

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

ranjith_kumar_k_u’s picture

StatusFileSize
new7.91 KB

Re-rolled #19 for 9.4.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

medha kumari’s picture

Issue tags: -Needs reroll
StatusFileSize
new7.92 KB

Reroll the path #28 with 10.1.x.

spokje’s picture

Issue summary: View changes
spokje’s picture

Status: Needs review » Needs work

Running the tests mentioned in the IS on Windows 11 _with_ the patch on 10.1.x:

- Both FileCacheTes and ClassFinderTest now pass.
- YamlDirectoryDiscoveryTest now fails with:

$ ../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
..FF                                                                4 / 4 (100%)

Time: 00:00.385, Memory: 10.00 MB

There were 2 failures:

1) 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

2) 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
spokje’s picture

Basically I think the / between The vfs://modules/test_1 and item_1.test.yml ... needs to be replaced with '. DIRECTORY_SEPARATOR . ' in both $this->expectExceptionMessages in YamlDirectoryDiscoveryTest::testDiscoveryNoIdException and ::testDiscoveryInvalidYamlException.

After that all tests should pass on Windows and TestBot.

smustgrave’s picture

Adding to my queue to address issues #34

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new1.43 KB
new9.13 KB

Like this?

spokje’s picture

Status: Needs review » Needs work
StatusFileSize
new1.48 KB

@smustgrave: I was thinking more along the lines of the attached interdiff against your last patch.

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new1.48 KB
new8.99 KB

Sorry for the delay.

Updated based on #37

spokje’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @smustgrave.

After applying patch #38, all three tests mentioned in the IS now pass on my local Windows 11 install:

sheet@LAPTOP-EMEOAUGS MINGW64 /d/htdocs/drupal (3123216-10.1-replace-non-test-usages)
$ patch -p1 < 2911377
bash: 2911377: No such file or directory

sheet@LAPTOP-EMEOAUGS MINGW64 /d/htdocs/drupal (10.1.x)
$ patch -p1 < 2911377-38.patch
patching file core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php
patching file core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
patching file core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php

sheet@LAPTOP-EMEOAUGS MINGW64 /d/htdocs/drupal (10.1.x)
$ vendor/bin/phpunit -c core --stop-on-failure core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php
PHPUnit 9.5.26 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\Component\ClassFinder\ClassFinderTest
.                                                                   1 / 1 (100%)

Time: 00:00.050, Memory: 10.00 MB

OK (1 test, 4 assertions)

sheet@LAPTOP-EMEOAUGS MINGW64 /d/htdocs/drupal (10.1.x)
$ vendor/bin/phpunit -c core --stop-on-failure core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
PHPUnit 9.5.26 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest
....                                                                4 / 4 (100%)

Time: 00:00.100, Memory: 10.00 MB

OK (4 tests, 16 assertions)

sheet@LAPTOP-EMEOAUGS MINGW64 /d/htdocs/drupal (10.1.x)
$ vendor/bin/phpunit -c core --stop-on-failure core/tests/Drupal/Tests/Component/FileCache/FileCacheTest.php
PHPUnit 9.5.26 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\Component\FileCache\FileCacheTest
....                                                                4 / 4 (100%)

Time: 00:00.057, Memory: 10.00 MB

Seeing that those tests also pass on (non-Windows) TestBot, I'm going to mark this RTBC.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

Why is it only these tests that fail?

I think we can make these changes easier to read (maintain). And they also need a comment explaining why the path is being altered.

  1. +++ b/core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php
    @@ -20,7 +20,7 @@ public function testFindFile() {
    +    $this->assertStringEndsWith('core' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'Drupal' . DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR . 'Component' . DIRECTORY_SEPARATOR . 'ClassFinder' . DIRECTORY_SEPARATOR . 'ClassFinderTest.php', $finder->findFile(ClassFinderTest::class));
    
    @@ -30,7 +30,7 @@ public function testFindFile() {
    +    $this->assertStringEndsWith('core' . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'Drupal' . DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR . 'Component' . DIRECTORY_SEPARATOR . 'ClassFinder' . DIRECTORY_SEPARATOR . 'ClassFinderTest.php', $finder->findFile(ClassFinderTest::class));
    

    I'm thinking a simple str_replace, with a comment, is easier to read.

        // comment to be added
        $path = str_replace('/', DIRECTORY_SEPARATOR, 'core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php');
        $this->assertStringEndsWith($path, $finder->findFile(ClassFinderTest::class));
  2. +++ b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
    @@ -80,18 +80,18 @@ public function testDiscovery() {
    +    $this->assertSame(['id' => 'item1', 'name' => 'test1 item 1', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_1/subdir1' . DIRECTORY_SEPARATOR . 'item_1.test.yml'], $data['test_1']['item1']);
    ...
    +    $this->assertSame(['id' => 'item3', 'name' => 'test2 item 3', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_2/subdir1' . DIRECTORY_SEPARATOR . 'item_3.test.yml'], $data['test_2']['item3']);
    ...
    +    $this->assertSame(['id' => 'item4', 'name' => 'test4 item 4', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1' . DIRECTORY_SEPARATOR . 'item_4.test.yml'], $data['test_4']['item4']);
    

    Why is the separator only changed in the middle of the path? This question applies to other lines in the patch as well. And like above let's make it easier to read.

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new1.62 KB
new8.68 KB

@quietone updated #40.1

but #40.2 not sure how str_replace helps here as DIRECTORY_SEPARATOR is only used once per line

As to the reason why, I'm not going to pretend I understand windows but looking at the failure from #33

vfs://modules/test_1\item_1.test.yml

Seems the last separator is reversed in windows?

quietone’s picture

Status: Needs review » Needs work
+++ b/core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php
@@ -20,7 +20,8 @@
+    $path = str_replace('/', DIRECTORY_SEPARATOR, 'core/tests/Drupal/Tests/Component/ClassFinder/ClassFinderTest.php');

Ah, this would be even better as $expected_path. Sorry, I should have thought of that.

As for a comment, how about "The file path is dependent on the operating system, so we adjust the directory separator." ? This comment, or similar, could before the first assertSame in YamDirectoryDiscorveryTest.

neclimdul’s picture

str_replace probably isn't a great option. it replaces things that might not be directory separators.

The reason the tests fail is because despite php handling file magic when talking to the filesystem, if you ask the file system what the path is it will use Windows broken separators. It might be more readable to do an implode in some cases.

To understand consider the following contrived example. I don't have a windows system to validate but it should be conceptually correct.


var_export(file_exists('/foo/bar.txt')); //true
var_export(real_path('/foo/bar.txt')); // C:\foo\bar.txt

The patch doesn't capture the problem very well but you should be able to find some similar calculation around most of them. Occasionally libraries might has something like $base . DIRECTORY_SEPERATOR . $part which might be what VFS is doing. Generally this shouldn't be necessary (why we're only looking at tests) but it could happen.

Practically this sort of munging should be transparent during normal runtime. But for tests asserting specific string values for a path they're different and fails.

edit: Woops, I missed the question was specific to vfs... leaving explanation in case it helps someone but sorry.

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new2.32 KB
new8.8 KB

Addressed comments in #42

spokje’s picture

Status: Needs review » Reviewed & tested by the community

Just ran all three changed test classes successfully on a Windows 11 machine using XAMPP and using MINGW64 as bash shell.

neclimdul’s picture

Still not plused about the str_replace use. I guess I'll need to write a different patch though to get it addressed. Does anyone have steps to recreate these failures?

neclimdul’s picture

Sorry, that was a genuine request. I don't know how to recreate this to test this and try some alternate approaches.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Moving this back to needs review. Pinged @Spokje in slack to see if he checked the failure case (which I understand to be just running these unit tests on a windows machine, but have no way to validate).

The obvious alternative to str_replace() would be a big concat of the string which was in earlier patches - which is guaranteed not to replace anything it shouldn't since it'd all be hardcoded. But also given the string we're runnign str_replace() in is a hard-coded string in a test anyway, I don't see how the end result could possibly be different.

spokje’s picture

Status: Needs review » Reviewed & tested by the community

Pinged @Spokje in slack to see if he checked the failure case (which I understand to be just running these unit tests on a windows machine, but have no way to validate).

Yep, the test failures in the IS is me running the tests on the 10.1.x branch without any patches: https://www.drupal.org/node/2911377/revisions/view/12852063/12894061

Back to RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 44: 2911377-44.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Seemed random

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 44: 2911377-44.patch, failed testing. View results

spokje’s picture

Status: Needs work » Reviewed & tested by the community

Random Failure, back to RTBC.

larowlan’s picture

larowlan’s picture

Version: 10.1.x-dev » 9.5.x-dev
Priority: Normal » Minor
Status: Reviewed & tested by the community » Fixed

Committed to 10.1.x and backported to 10.0.x and 9.5.x to keep things consistent

Posthumously updating the priority to minor.

  • larowlan committed 5b91abc9 on 10.0.x
    Issue #2911377 by smustgrave, ProFire, MerryHamster, ranjith_kumar_k_u,...

  • larowlan committed e1f56ada on 10.1.x
    Issue #2911377 by smustgrave, ProFire, MerryHamster, ranjith_kumar_k_u,...

  • larowlan committed 8ec568f2 on 9.5.x
    Issue #2911377 by smustgrave, ProFire, MerryHamster, ranjith_kumar_k_u,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.