1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- declare(strict_types = 1);
- 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');
- }
- }
|