-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Huge delay with imageMeta when running tests #25
Comments
Hey Hassan! Thanks a lot for your detailed and thoughtful issue. I totally agree testsuites should be fast and this should not take 5-6 seconds. 🙂 I think that it has to do with the function
$category->getFirstMedia(Disk::CategoryPictures)->getPath();
<?php
namespace RalphJSmit\Laravel\SEO\Support;
use Exception;
class ImageMeta
{
public ?int $width = null;
public ?int $height = null;
public function __construct(string $path)
{
$publicPath = public_path($path);
if ( ! is_file($publicPath) ) {
dump("Not a file");
report(new Exception("Path {$publicPath} is not a file."));
return;
}
[$width, $height] = getimagesize($publicPath);
dump($width, $height);
$this->width = $width;
$this->height = $height;
}
} Thanks! |
Hey! Thanks for your quick reply. 😄 I want to point out that As for now, I found a workaround for this problem. I did some investigations and found out So I added a second parameter to the Storage::fake(Disk::CategoryPictures, [
'url' => config('app.url') . '/storage',
]); Now the test will run fine with normal speeds ✅ |
Hey @HassanZahirnia! Hmm, I guess a good solution, but indeed slightly hacky. But it is a good fake. For now I guess that it would be nice, but I could add a method that would allow you to generate URLs based on paths (and vice versa). I don't have time to do that this year, so you might want to use the current solution for now. Thanks! 🙂 |
Hey 👋
I use
spatie/laravel-medialibrary
for managing files including images. And I noticed when I'm running tests there is a huge stall (around 5-6seconds) on theimageMeta
creation. I pass thegetFirstMediaUrl
to theSEOData
and it works fine in browser since it returns a full url to the image (like:http://www....
)But during tests since the storage is faked, the
getFirstMediaUrl
returns a local path like/storage/1/....
and this seem to confuse this package'simageMeta()
insideSEOData
class and the test would get delayed for many seconds until it finally passes.I wonder if this is something that can be fixed or taken into account for such scenario ?
Or is there a different approach I should take for passing the image path. I'm asking this since
spatie/laravel-medialibrary
is a popular package and people probably might end up with same pitfall.Thanks in advance and thank you for your great package 😊🙌
The text was updated successfully, but these errors were encountered: