Skip to content

Commit 9447e45

Browse files
author
Oleksii Korshenko
authored
MAGETWO-85290: 7467: File Put Contents file with empty content. #962
2 parents 5e0bb4a + 78afd24 commit 9447e45

File tree

2 files changed

+45
-2
lines changed
  • dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver
  • lib/internal/Magento/Framework/Filesystem/Driver

2 files changed

+45
-2
lines changed

dev/tests/integration/testsuite/Magento/Framework/Filesystem/Driver/FileTest.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
*/
88
namespace Magento\Framework\Filesystem\Driver;
99

10-
use Magento\Framework\Filesystem\DriverInterface;
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Filesystem;
12+
use Magento\Framework\Filesystem\Directory\WriteInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
1114

1215
class FileTest extends \PHPUnit\Framework\TestCase
1316
{
@@ -80,4 +83,44 @@ public function testCreateDirectory()
8083
$this->assertTrue($this->driver->createDirectory($generatedPath));
8184
$this->assertTrue(is_dir($generatedPath));
8285
}
86+
87+
/**
88+
* Check, driver can create file with content or without one.
89+
*
90+
* @dataProvider createFileDataProvider
91+
* @param int $result
92+
* @param string $fileName
93+
* @param string $fileContent
94+
* @return void
95+
* @throws \Magento\Framework\Exception\FileSystemException
96+
*/
97+
public function testCreateFile(int $result, string $fileName, string $fileContent)
98+
{
99+
/** @var WriteInterface $directory */
100+
$directory = Bootstrap::getObjectManager()->get(Filesystem::class)->getDirectoryWrite(DirectoryList::VAR_DIR);
101+
$filePath = $directory->getAbsolutePath() . '/' . $fileName;
102+
$this->assertSame($result, $this->driver->filePutContents($filePath, $fileContent));
103+
$this->assertTrue($this->driver->deleteFile($filePath));
104+
}
105+
106+
/**
107+
* Provides test data for testCreateFile().
108+
*
109+
* @return array
110+
*/
111+
public function createFileDataProvider()
112+
{
113+
return [
114+
'file_with_content' => [
115+
'result' => 11,
116+
'fileName' => 'test.txt',
117+
'fileContent' => 'testContent',
118+
],
119+
'empty_file' => [
120+
'result' => 0,
121+
'filePath' => 'test.txt',
122+
'fileContent' => '',
123+
]
124+
];
125+
}
83126
}

lib/internal/Magento/Framework/Filesystem/Driver/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ public function touch($path, $modificationTime = null)
528528
public function filePutContents($path, $content, $mode = null)
529529
{
530530
$result = @file_put_contents($this->getScheme() . $path, $content, $mode);
531-
if (!$result) {
531+
if ($result === false) {
532532
throw new FileSystemException(
533533
new \Magento\Framework\Phrase(
534534
'The specified "%1" file could not be written %2',

0 commit comments

Comments
 (0)