Skip to content

Commit cfed253

Browse files
authored
Fix Filesystem tests failing in Windows (#32975)
* testPutWithStreamInterface() leaves an fopen() stream resource that must be explicitly closed before temp directories can be deleted in Windows. * testReplaceStoresFiles() fails for multiple reasons under Windows. chmod() / umask() write permissions don't change and symlink() attempts fail in most Windows environments.
1 parent a4f74b8 commit cfed253

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

tests/Filesystem/FilesystemAdapterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ public function testPutWithStreamInterface()
236236
$spy = m::spy($this->filesystem);
237237

238238
$filesystemAdapter = new FilesystemAdapter($spy);
239-
$stream = new Stream(fopen($this->tempDir.'/foo.txt', 'r'));
240-
$filesystemAdapter->put('bar.txt', $stream);
239+
$stream = fopen($this->tempDir.'/foo.txt', 'r');
240+
$guzzleStream = new Stream($stream);
241+
$filesystemAdapter->put('bar.txt', $guzzleStream);
242+
fclose($stream);
241243

242244
$spy->shouldHaveReceived('putStream');
243245
$this->assertEquals('some-data', $filesystemAdapter->get('bar.txt'));

tests/Filesystem/FilesystemTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,22 @@ public function testPutStoresFiles()
4343
$this->assertStringEqualsFile($this->tempDir.'/file.txt', 'Hello World');
4444
}
4545

46-
public function testReplaceStoresFiles()
46+
public function testReplaceCreatesFile()
4747
{
48+
$tempFile = "{$this->tempDir}/file.txt";
49+
50+
$filesystem = new Filesystem;
51+
52+
$filesystem->replace($tempFile, 'Hello World');
53+
$this->assertStringEqualsFile($tempFile, 'Hello World');
54+
}
55+
56+
public function testReplaceWhenUnixSymlinkExists()
57+
{
58+
if (windows_os()) {
59+
$this->markTestSkipped('Skipping since operating system is Windows');
60+
}
61+
4862
$tempFile = "{$this->tempDir}/file.txt";
4963
$symlinkDir = "{$this->tempDir}/symlink_dir";
5064
$symlink = "{$symlinkDir}/symlink.txt";

0 commit comments

Comments
 (0)