|
7 | 7 | */
|
8 | 8 | namespace Magento\Framework\Filesystem\Driver;
|
9 | 9 |
|
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; |
11 | 14 |
|
12 | 15 | class FileTest extends \PHPUnit\Framework\TestCase
|
13 | 16 | {
|
@@ -80,4 +83,44 @@ public function testCreateDirectory()
|
80 | 83 | $this->assertTrue($this->driver->createDirectory($generatedPath));
|
81 | 84 | $this->assertTrue(is_dir($generatedPath));
|
82 | 85 | }
|
| 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 | + } |
83 | 126 | }
|
0 commit comments