From 46e67d7ed07c534cbdc18ddc1b88eb660f64ea12 Mon Sep 17 00:00:00 2001 From: Paramtamtam <7326800+tarampampam@users.noreply.github.com> Date: Thu, 10 Jun 2021 17:24:39 +0500 Subject: [PATCH] Fix Symfony File::move() (#46) --- CHANGELOG.md | 8 +++ composer.json | 2 +- fixes/fix-symfony-file-moving.php | 36 ++++++++++++++ fixes/fix-symfony-file-validation.php | 9 ++-- src/Defaults.php | 1 + .../FixSymfonyFileMovingListener.php | 21 ++++++++ .../FixSymfonyFileMovingListenerTest.php | 49 +++++++++++++++++++ 7 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 fixes/fix-symfony-file-moving.php create mode 100644 src/Listeners/FixSymfonyFileMovingListener.php create mode 100644 tests/Unit/Listeners/FixSymfonyFileMovingListenerTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 4125567..5d9b3ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver]. +## UNRELEASED + +### Fixed + +- Symfony uploaded file moving (`FixSymfonyFileMovingListener` was added for this) [#43] + +[#43]:https://github.com/spiral/roadrunner-laravel/issues/43 + ## v5.0.0 ### Added diff --git a/composer.json b/composer.json index c5e46ce..c147dd1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "spiral/roadrunner-laravel", "type": "library", - "description": "RoadRunner bridge for Laravel applications", + "description": "RoadRunner: Bridge for Laravel applications", "keywords": [ "laravel", "bridge", diff --git a/fixes/fix-symfony-file-moving.php b/fixes/fix-symfony-file-moving.php new file mode 100644 index 0000000..e6f04a9 --- /dev/null +++ b/fixes/fix-symfony-file-moving.php @@ -0,0 +1,36 @@ +assertFalse(\function_exists($function_location)); + $this->assertFalse(\is_uploaded_file('foo')); + + $this->listenerFactory()->handle(new \stdClass()); + + $this->assertTrue(\function_exists($function_location)); + + $tmp_dir = $this->createTemporaryDirectory(); + $old_file_path = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); + $new_file_path = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); + \file_put_contents($old_file_path, ''); + $this->assertFileExists($old_file_path); + $this->assertTrue($function_location($old_file_path, $new_file_path)); + $this->assertFileExists($new_file_path); + $this->assertFileNotExists($old_file_path); + $rnd_file_path1 = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); + $rnd_file_path2 = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); + $this->assertFalse($function_location($rnd_file_path1, $rnd_file_path2)); + } + + /** + * @return FixSymfonyFileMovingListener + */ + protected function listenerFactory(): FixSymfonyFileMovingListener + { + return new FixSymfonyFileMovingListener(); + } +}