From 388343aeb0e618ee379b8197eafce83ad632290b Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sun, 19 Jun 2022 18:44:34 +0100 Subject: [PATCH] Fixed failing tests after conversion changes --- app/Entities/Tools/Cloner.php | 7 +++---- app/Http/Controllers/BookshelfController.php | 2 ++ tests/Entity/BookTest.php | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Entities/Tools/Cloner.php b/app/Entities/Tools/Cloner.php index 000f28a05..ad9ec01ec 100644 --- a/app/Entities/Tools/Cloner.php +++ b/app/Entities/Tools/Cloner.php @@ -99,8 +99,7 @@ class Cloner // Add a cover to the data if existing on the original entity if ($entity->cover instanceof Image) { - $tmpImgFile = tmpfile(); - $uploadedFile = $this->imageToUploadedFile($entity->cover, $tmpImgFile); + $uploadedFile = $this->imageToUploadedFile($entity->cover); $inputData['image'] = $uploadedFile; } @@ -123,10 +122,10 @@ class Cloner * Convert an image instance to an UploadedFile instance to mimic * a file being uploaded. */ - protected function imageToUploadedFile(Image $image, &$tmpFile): ?UploadedFile + protected function imageToUploadedFile(Image $image,): ?UploadedFile { $imgData = $this->imageService->getImageData($image); - $tmpImgFilePath = stream_get_meta_data($tmpFile)['uri']; + $tmpImgFilePath = tempnam(sys_get_temp_dir(), 'bs_cover_clone_'); file_put_contents($tmpImgFilePath, $imgData); return new UploadedFile($tmpImgFilePath, basename($image->path)); diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php index 121110e83..a294bf731 100644 --- a/app/Http/Controllers/BookshelfController.php +++ b/app/Http/Controllers/BookshelfController.php @@ -87,6 +87,7 @@ class BookshelfController extends Controller 'name' => ['required', 'string', 'max:255'], 'description' => ['string', 'max:1000'], 'image' => array_merge(['nullable'], $this->getImageValidationRules()), + 'tags' => ['array'], ]); $bookIds = explode(',', $request->get('books', '')); @@ -163,6 +164,7 @@ class BookshelfController extends Controller 'name' => ['required', 'string', 'max:255'], 'description' => ['string', 'max:1000'], 'image' => array_merge(['nullable'], $this->getImageValidationRules()), + 'tags' => ['array'], ]); if ($request->has('image_reset')) { diff --git a/tests/Entity/BookTest.php b/tests/Entity/BookTest.php index 7f102a17e..8b2702b46 100644 --- a/tests/Entity/BookTest.php +++ b/tests/Entity/BookTest.php @@ -290,6 +290,7 @@ class BookTest extends TestCase /** @var Book $copy */ $copy = Book::query()->where('name', '=', 'My copy book')->first(); + $this->assertNotNull($copy->cover); $this->assertNotEquals($book->cover->id, $copy->cover->id); }