. // }}} namespace App\Tests\Util; use App\Util\Exception\TemporaryFileException; use App\Util\TemporaryFile; use Jchook\AssertThrows\AssertThrows; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class TemporaryFileTest extends WebTestCase { use AssertThrows; public function testRegular() { $temp = new TemporaryFile(); static::assertNotNull($temp->getResource()); $filepath = uniqid(sys_get_temp_dir() . '/'); $temp->commit($filepath); static::assertFileExists($filepath); @unlink($filepath); } public function testError() { $temp = new TemporaryFile(); $filepath = $temp->getRealPath(); static::assertThrows(TemporaryFileException::class, fn () => $temp->commit($filepath)); static::assertThrows(TemporaryFileException::class, fn () => $temp->commit('/root/not-a-folder/cannot_write_here')); } public function testCreateDirectory() { $temp = new TemporaryFile(); @unlink('/tmp/social-test-folder/test'); $temp->move('/tmp/social-test-folder/', 'test'); static::assertFileExists('/tmp/social-test-folder/test'); } }