spout/tests/Spout/Common/Helper/FileSystemHelperTest.php
Antoine Lamirault 540667870a Merge branch 'master' of github.com:box/spout into add-phpstan
 Conflicts:
	.travis.yml
	CONTRIBUTING.md
	composer.json
	src/Spout/Common/Entity/Cell.php
	tests/Spout/Writer/ODS/WriterTest.php
2021-09-18 18:14:45 +02:00

66 lines
2.0 KiB
PHP

<?php
namespace Box\Spout\Common\Helper;
use Box\Spout\Common\Exception\IOException;
use PHPUnit\Framework\TestCase;
/**
* Class FileSystemHelperTest
*/
class FileSystemHelperTest extends TestCase
{
/** @var FileSystemHelper */
protected $fileSystemHelper;
/**
* @return void
*/
public function setUp() : void
{
$baseFolder = \sys_get_temp_dir();
$this->fileSystemHelper = new FileSystemHelper($baseFolder);
}
/**
* @return void
*/
public function testCreateFolderShouldThrowExceptionIfOutsideOfBaseFolder()
{
$this->expectException(IOException::class);
$this->expectExceptionMessage('Cannot perform I/O operation outside of the base folder');
$this->fileSystemHelper->createFolder('/tmp/folder_outside_base_folder', 'folder_name');
}
/**
* @return void
*/
public function testCreateFileWithContentsShouldThrowExceptionIfOutsideOfBaseFolder()
{
$this->expectException(IOException::class);
$this->expectExceptionMessage('Cannot perform I/O operation outside of the base folder');
$this->fileSystemHelper->createFileWithContents('/tmp/folder_outside_base_folder', 'file_name', 'contents');
}
/**
* @return void
*/
public function testDeleteFileShouldThrowExceptionIfOutsideOfBaseFolder()
{
$this->expectException(IOException::class);
$this->expectExceptionMessage('Cannot perform I/O operation outside of the base folder');
$this->fileSystemHelper->deleteFile('/tmp/folder_outside_base_folder/file_name');
}
/**
* @return void
*/
public function testDeleteFolderRecursivelyShouldThrowExceptionIfOutsideOfBaseFolder()
{
$this->expectException(IOException::class);
$this->expectExceptionMessage('Cannot perform I/O operation outside of the base folder');
$this->fileSystemHelper->deleteFolderRecursively('/tmp/folder_outside_base_folder');
}
}