Skip to content
Snippets Groups Projects
Commit b42712ef authored by magento-engcom-team's avatar magento-engcom-team
Browse files

7467: File Put Contents file with empty content.

parent 276c690d
No related merge requests found
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
*/ */
namespace Magento\Framework\Filesystem\Driver; namespace Magento\Framework\Filesystem\Driver;
use Magento\Framework\Filesystem\DriverInterface; use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\TestFramework\Helper\Bootstrap;
class FileTest extends \PHPUnit\Framework\TestCase class FileTest extends \PHPUnit\Framework\TestCase
{ {
...@@ -80,4 +83,44 @@ class FileTest extends \PHPUnit\Framework\TestCase ...@@ -80,4 +83,44 @@ class FileTest extends \PHPUnit\Framework\TestCase
$this->assertTrue($this->driver->createDirectory($generatedPath)); $this->assertTrue($this->driver->createDirectory($generatedPath));
$this->assertTrue(is_dir($generatedPath)); $this->assertTrue(is_dir($generatedPath));
} }
/**
* Check, driver can create file with content or without one.
*
* @dataProvider createFileDataProvider
* @param int $result
* @param string $fileName
* @param string $fileContent
* @return void
* @throws \Magento\Framework\Exception\FileSystemException
*/
public function testCreateFile(int $result, string $fileName, string $fileContent)
{
/** @var WriteInterface $directory */
$directory = Bootstrap::getObjectManager()->get(Filesystem::class)->getDirectoryWrite(DirectoryList::VAR_DIR);
$filePath = $directory->getAbsolutePath() . '/' . $fileName;
$this->assertSame($result, $this->driver->filePutContents($filePath, $fileContent));
$this->assertTrue($this->driver->deleteFile($filePath));
}
/**
* Provides test data for testCreateFile().
*
* @return array
*/
public function createFileDataProvider()
{
return [
'file_with_content' => [
'result' => 11,
'fileName' => 'test.txt',
'fileContent' => 'testContent',
],
'empty_file' => [
'result' => 0,
'filePath' => 'test.txt',
'fileContent' => '',
]
];
}
} }
...@@ -528,7 +528,7 @@ class File implements DriverInterface ...@@ -528,7 +528,7 @@ class File implements DriverInterface
public function filePutContents($path, $content, $mode = null) public function filePutContents($path, $content, $mode = null)
{ {
$result = @file_put_contents($this->getScheme() . $path, $content, $mode); $result = @file_put_contents($this->getScheme() . $path, $content, $mode);
if (!$result) { if ($result === false) {
throw new FileSystemException( throw new FileSystemException(
new \Magento\Framework\Phrase( new \Magento\Framework\Phrase(
'The specified "%1" file could not be written %2', 'The specified "%1" file could not be written %2',
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment