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

Fix Laravel 11 compability #99

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

syntafin
Copy link

@syntafin syntafin commented Jul 6, 2024

Laravel 11 adds Carbon ^3.0, with this PR it works

@abdumu
Copy link
Member

abdumu commented Jul 6, 2024

have you tried the last release?

@syntafin
Copy link
Author

syntafin commented Jul 6, 2024

Yes, doesnt work as new L11 projects comes with Carbon 3.

@abdumu
Copy link
Member

abdumu commented Jul 6, 2024

tests failed with this PR, work on that and i'm ready to merge it

@syntafin
Copy link
Author

syntafin commented Jul 6, 2024

Yes, because of a deprecation notice (float -> int):

DEPRECATED Implicit conversion from float -2161878.318833 to int loses precision in vendor/awssat/laravel-visits/src/DataEngines/EloquentEngine.php on line 193.

still looking into this atm.

@abdumu
Copy link
Member

abdumu commented Jul 6, 2024

yes, since it's late now I'll be waiting for your fix, or i will look into it tomorrow by myself.

@syntafin
Copy link
Author

syntafin commented Jul 6, 2024

It's late here too :D will look into it tomorrow too!

@syntafin
Copy link
Author

syntafin commented Jul 7, 2024

I found the problem, its caused only if you use Carbon 3, as it changed the behaivour of diffIn to strict typing:

image

Changing the function newExpiration to how described in upgrade docs, only one (two) test fail: day_test.

protected function newExpiration($period)
    {
        try {
            $periodCarbon = $this->xHoursPeriod($period) ?? Carbon::now()->{'endOf' . Str::studly($period)}();
        } catch (Exception $e) {
            throw new Exception("Wrong period: `{$period}`! please update config/visits.php file.");
        }

        return (int) abs($periodCarbon->diffInSeconds()) + 1;
    }

Still ongoing to figure out that last problem.

Time: 00:11.637, Memory: 38.50 MB

There were 2 failures:

  1. Awssat\Visits\Tests\Feature\EloquentPeriodsTest::day_test
    Failed asserting that -1.000011574074074 matches expected 1.

/home/syntafin/projects/laravel-visits/tests/Feature/PeriodsTestCase.php:95

  1. Awssat\Visits\Tests\Feature\RedisPeriodsTest::day_test
    Failed asserting that -1.0034837962962964 matches expected 1.

/home/syntafin/projects/laravel-visits/tests/Feature/PeriodsTestCase.php:95

Changed the variable name from 'key' to 'search' in valueList method across the engine classes to be more descriptive about its functionality. Moreover, adjusted the data types for variables in setExpiration methods from float to integer to ensure consistency throughout the code. An enhancement in Periods class has been made to make sure the difference in seconds is always an absolute integer.
@syntafin
Copy link
Author

syntafin commented Jul 7, 2024

Tests now should all pass, I changed them and the return type of newExpiration to use absolute integers.
May you can check it on your side and see if I didnt oversee anything :)

@abdumu
Copy link
Member

abdumu commented Jul 7, 2024

i pushed the last change before seeing your last comment, i would've pulled it instead of changing this myself. absolutely right. thanks for debugging this.

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

Successfully merging this pull request may close these issues.

2 participants