|
26 | 26 |
|
27 | 27 | class PhpConfigReferenceDumpPassTest extends TestCase |
28 | 28 | { |
| 29 | + private string $readOnlyDir; |
29 | 30 | private string $tempDir; |
30 | 31 |
|
31 | 32 | protected function setUp(): void |
32 | 33 | { |
33 | 34 | $this->tempDir = sys_get_temp_dir().'/sf_test_config_reference'; |
34 | 35 | mkdir($this->tempDir, 0o777, true); |
| 36 | + |
| 37 | + // Create a read-only directory to simulate write errors |
| 38 | + $this->readOnlyDir = $this->tempDir.'/readonly'; |
| 39 | + mkdir($this->readOnlyDir, 0o444, true); |
| 40 | + |
| 41 | + // Make the directory read-only on Windows |
| 42 | + if ('\\' === \DIRECTORY_SEPARATOR) { |
| 43 | + exec('attrib +r '.escapeshellarg($this->readOnlyDir)); |
| 44 | + } |
35 | 45 | } |
36 | 46 |
|
37 | 47 | protected function tearDown(): void |
38 | 48 | { |
39 | 49 | if (is_dir($this->tempDir)) { |
| 50 | + if ('\\' === \DIRECTORY_SEPARATOR) { |
| 51 | + exec('attrib -r '.escapeshellarg($this->readOnlyDir)); |
| 52 | + } |
| 53 | + |
40 | 54 | $fs = new Filesystem(); |
41 | 55 | $fs->remove($this->tempDir); |
42 | 56 | } |
@@ -64,23 +78,15 @@ public function testProcessWithConfigDir() |
64 | 78 |
|
65 | 79 | public function testProcessIgnoresFileWriteErrors() |
66 | 80 | { |
67 | | - if ('\\' === \DIRECTORY_SEPARATOR) { |
68 | | - self::markTestSkipped('Cannot reliably make directory read-only on Windows.'); |
69 | | - } |
70 | | - |
71 | | - // Create a read-only directory to simulate write errors |
72 | | - $readOnlyDir = $this->tempDir.'/readonly'; |
73 | | - mkdir($readOnlyDir, 0o444, true); |
74 | | - |
75 | 81 | $container = new ContainerBuilder(); |
76 | 82 | $container->setParameter('.container.known_envs', ['dev', 'prod', 'test']); |
77 | 83 |
|
78 | | - $pass = new PhpConfigReferenceDumpPass($readOnlyDir.'/reference.php', [ |
| 84 | + $pass = new PhpConfigReferenceDumpPass($this->readOnlyDir.'/reference.php', [ |
79 | 85 | TestBundle::class => ['all' => true], |
80 | 86 | ]); |
81 | 87 |
|
82 | 88 | $pass->process($container); |
83 | | - $this->assertFileDoesNotExist($readOnlyDir.'/reference.php'); |
| 89 | + $this->assertFileDoesNotExist($this->readOnlyDir.'/reference.php'); |
84 | 90 | $this->assertEmpty($container->getResources()); |
85 | 91 | } |
86 | 92 |
|
|
0 commit comments