Skip to content
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

Carbon::isBefore() TypeError in tests using inactive factory state #298

Open
chrisrhymes opened this issue Nov 13, 2024 · 0 comments
Open

Comments

@chrisrhymes
Copy link

Hi,

This is using Laravel v11, Carbon v3 and short-url v8.1.2

I am using the default factories in my test but when I create an inactive short url using the inactive() factory state and test getting the short url it returns a 500 type error. It seems this is because the Carbon\Carbon::isBefore() only allows a DateInterface or string and not null.

I have just upgraded to Laravel 11 which is now including Carbon v3 instead of v2.

TypeError: Carbon\Carbon::isBefore(): Argument #1 ($date) must be of type DateTimeInterface|string, null given, called in /my-app/vendor/ashallendesign/short-url/src/Classes/Resolver.php on line 59 and defined in /my-app/vendor/nesbot/carbon/src/Carbon/Traits/Comparison.php:239
use AshAllenDesign\ShortURL\Models\ShortURL;

it('returns 404 for inactive url', function () {
    $inactiveShortURL = ShortURL::factory()->inactive()->create();

    get(config('short-url.prefix').'/'.$inactiveShortURL->url_key)
        ->assertStatus(404);
});

This calls the class Resolver.php and fails on line 59:

if (now()->isBefore($shortURL->activated_at)) {
        return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant