<?php
-require_once 'application/FileUtils.php';
+namespace Shaarli;
+
+use Exception;
/**
* Class FileUtilsTest
*
* Test file utility class.
*/
-class FileUtilsTest extends PHPUnit_Framework_TestCase
+class FileUtilsTest extends \Shaarli\TestCase
{
/**
* @var string Test file path.
/**
* Delete test file after every test.
*/
- public function tearDown()
+ protected function tearDown(): void
{
@unlink(self::$file);
}
/**
* File not writable: raise an exception.
- *
- * @expectedException IOException
- * @expectedExceptionMessage Error accessing "sandbox/flat.db"
*/
public function testWriteWithoutPermission()
{
+ $this->expectException(\Shaarli\Exceptions\IOException::class);
+ $this->expectExceptionMessage('Error accessing "sandbox/flat.db"');
+
touch(self::$file);
chmod(self::$file, 0440);
FileUtils::writeFlatDB(self::$file, null);
/**
* Folder non existent: raise an exception.
- *
- * @expectedException IOException
- * @expectedExceptionMessage Error accessing "nopefolder"
*/
public function testWriteFolderDoesNotExist()
{
+ $this->expectException(\Shaarli\Exceptions\IOException::class);
+ $this->expectExceptionMessage('Error accessing "nopefolder"');
+
FileUtils::writeFlatDB('nopefolder/file', null);
}
/**
* Folder non writable: raise an exception.
- *
- * @expectedException IOException
- * @expectedExceptionMessage Error accessing "sandbox"
*/
public function testWriteFolderPermission()
{
+ $this->expectException(\Shaarli\Exceptions\IOException::class);
+ $this->expectExceptionMessage('Error accessing "sandbox"');
+
chmod(dirname(self::$file), 0555);
try {
FileUtils::writeFlatDB(self::$file, null);