Fixed failing tests after conversion changes

This commit is contained in:
Dan Brown 2022-06-19 18:44:34 +01:00
parent ba25dda031
commit 388343aeb0
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
3 changed files with 6 additions and 4 deletions

View file

@ -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));

View file

@ -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')) {

View file

@ -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);
}