Skip to content

Commit cbc6637

Browse files
committed
Test case created for the github issue #27866
1 parent ea7af78 commit cbc6637

File tree

1 file changed

+45
-0
lines changed
  • lib/internal/Magento/Framework/Filesystem/Test/Unit/Io

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
namespace Magento\Framework\Filesystem\Test\Unit\Io;
3+
4+
use Magento\Framework\Exception\LocalizedException;
5+
use Magento\Framework\Filesystem\Io\File;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class FileTest extends TestCase
9+
{
10+
protected function setUp()
11+
{
12+
13+
}
14+
15+
private function getTmpDir()
16+
{
17+
$tmpDir = '/tmp/magento-' . \microtime(true);
18+
if (!\file_exists($tmpDir)) {
19+
\mkdir($tmpDir, 0777, true);
20+
}
21+
return $tmpDir;
22+
}
23+
24+
/**
25+
* To cover the issue on GitHub: #27866
26+
* @test
27+
* @throws LocalizedException
28+
*/
29+
public function read_should_copy_the_source_file_to_the_given_file_resource()
30+
{
31+
$content = \mt_rand();
32+
$sourceFileName = "source-file.txt";
33+
$tmpDir = $this->getTmpDir();
34+
\file_put_contents("{$tmpDir}/{$sourceFileName}", $content);
35+
36+
$file = new File();
37+
$targetFileName = "target-file.txt";
38+
$targetFileHandle = \fopen("{$tmpDir}/{$targetFileName}" , 'w');
39+
$file->cd($tmpDir);
40+
$result = $file->read($sourceFileName, $targetFileHandle);
41+
42+
$targetContent = file_get_contents("{$tmpDir}/{$targetFileName}");
43+
$this->assertEquals($content, $targetContent);
44+
}
45+
}

0 commit comments

Comments
 (0)