|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Spiral\RoadRunnerLaravel\Tests\Unit\Listeners; |
| 6 | + |
| 7 | +use Illuminate\Support\Str; |
| 8 | +use Spiral\RoadRunnerLaravel\Listeners\FixSymfonyFileMovingListener; |
| 9 | + |
| 10 | +/** |
| 11 | + * @covers \Spiral\RoadRunnerLaravel\Listeners\FixSymfonyFileMovingListener |
| 12 | + */ |
| 13 | +class FixSymfonyFileMovingListenerTest extends AbstractListenerTestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * {@inheritdoc} |
| 17 | + */ |
| 18 | + public function testHandle(): void |
| 19 | + { |
| 20 | + $function_location = '\\Symfony\\Component\\HttpFoundation\\File\\move_uploaded_file'; |
| 21 | + |
| 22 | + $this->assertFalse(\function_exists($function_location)); |
| 23 | + $this->assertFalse(\is_uploaded_file('foo')); |
| 24 | + |
| 25 | + $this->listenerFactory()->handle(new \stdClass()); |
| 26 | + |
| 27 | + $this->assertTrue(\function_exists($function_location)); |
| 28 | + |
| 29 | + $tmp_dir = $this->createTemporaryDirectory(); |
| 30 | + $old_file_path = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); |
| 31 | + $new_file_path = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); |
| 32 | + \file_put_contents($old_file_path, ''); |
| 33 | + $this->assertFileExists($old_file_path); |
| 34 | + $this->assertTrue($function_location($old_file_path, $new_file_path)); |
| 35 | + $this->assertFileExists($new_file_path); |
| 36 | + $this->assertFileNotExists($old_file_path); |
| 37 | + $rnd_file_path1 = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); |
| 38 | + $rnd_file_path2 = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); |
| 39 | + $this->assertFalse($function_location($rnd_file_path1, $rnd_file_path2)); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @return FixSymfonyFileMovingListener |
| 44 | + */ |
| 45 | + protected function listenerFactory(): FixSymfonyFileMovingListener |
| 46 | + { |
| 47 | + return new FixSymfonyFileMovingListener(); |
| 48 | + } |
| 49 | +} |
0 commit comments