Skip to content

Commit aac4603

Browse files
committed
minor #62362 [FrameworkBundle] run test using a read-only directory on Windows too (xabbuh)
This PR was merged into the 7.4 branch. Discussion ---------- [FrameworkBundle] run test using a read-only directory on Windows too | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | see symfony/symfony#62137 (comment) | License | MIT Commits ------- d96afe2d501 run test using a read-only directory on Windows too
2 parents c8e24a8 + 4b47dd6 commit aac4603

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

Tests/DependencyInjection/Compiler/PhpConfigReferenceDumpPassTest.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,31 @@
2626

2727
class PhpConfigReferenceDumpPassTest extends TestCase
2828
{
29+
private string $readOnlyDir;
2930
private string $tempDir;
3031

3132
protected function setUp(): void
3233
{
3334
$this->tempDir = sys_get_temp_dir().'/sf_test_config_reference';
3435
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+
}
3545
}
3646

3747
protected function tearDown(): void
3848
{
3949
if (is_dir($this->tempDir)) {
50+
if ('\\' === \DIRECTORY_SEPARATOR) {
51+
exec('attrib -r '.escapeshellarg($this->readOnlyDir));
52+
}
53+
4054
$fs = new Filesystem();
4155
$fs->remove($this->tempDir);
4256
}
@@ -64,23 +78,15 @@ public function testProcessWithConfigDir()
6478

6579
public function testProcessIgnoresFileWriteErrors()
6680
{
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-
7581
$container = new ContainerBuilder();
7682
$container->setParameter('.container.known_envs', ['dev', 'prod', 'test']);
7783

78-
$pass = new PhpConfigReferenceDumpPass($readOnlyDir.'/reference.php', [
84+
$pass = new PhpConfigReferenceDumpPass($this->readOnlyDir.'/reference.php', [
7985
TestBundle::class => ['all' => true],
8086
]);
8187

8288
$pass->process($container);
83-
$this->assertFileDoesNotExist($readOnlyDir.'/reference.php');
89+
$this->assertFileDoesNotExist($this->readOnlyDir.'/reference.php');
8490
$this->assertEmpty($container->getResources());
8591
}
8692

0 commit comments

Comments
 (0)