diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d0b0ace..0ace6e9 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,12 +14,16 @@ jobs: matrix: os: [ubuntu-latest, windows-latest] php: [8.3, 8.2, 8.1] - laravel: [10.*] + laravel: [11.*, 10.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 10.* testbench: 8.* - carbon: ^2.63 + - laravel: 11.* + testbench: 9.* + exclude: + - laravel: 11.* + php: 8.1 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} @@ -41,7 +45,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Execute tests diff --git a/.gitignore b/.gitignore index 83c9b9f..a7f372d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .idea -.phpunit.result.cache +.phpunit.cache build composer.lock coverage diff --git a/LICENSE.md b/LICENSE.md index 43c44ab..3b09b56 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2023 MAIZE SRL +Copyright (c) 2024 MAIZE SRL Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index d1e0842..d619b60 100644 --- a/composer.json +++ b/composer.json @@ -23,24 +23,24 @@ ], "require": { "php": "^8.1", - "illuminate/console": "^10.0", - "illuminate/database": "^10.0", - "illuminate/notifications": "^10.0", - "illuminate/support": "^10.0", + "illuminate/console": "^10.0|^11.0", + "illuminate/database": "^10.0|^11.0", + "illuminate/notifications": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", "spatie/laravel-package-tools": "^1.14.1" }, "require-dev": { "laravel/pint": "^1.0", - "nunomaduro/collision": "^6.0", + "nunomaduro/collision": "^7.8|^8.1", "nunomaduro/larastan": "^2.0.1", - "orchestra/testbench": "^8.0", - "pestphp/pest": "^1.21", - "pestphp/pest-plugin-laravel": "^1.1", - "phpstan/extension-installer": "^1.1", + "orchestra/testbench": "^8.0|^9.0", + "pestphp/pest": "^2.34", + "pestphp/pest-plugin-arch": "^2.7", + "pestphp/pest-plugin-laravel": "^2.3", + "phpstan/extension-installer": "^1.3", "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^9.5", - "spatie/pest-plugin-test-time": "^1.1" + "phpstan/phpstan-phpunit": "^1.3", + "spatie/pest-plugin-test-time": "^2.1" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 290f954..c9e0daf 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,32 +1,11 @@ - + tests - - ./src - @@ -36,4 +15,9 @@ + + + ./src + + diff --git a/src/HasExpiration.php b/src/HasExpiration.php index 4cebbf3..785d845 100755 --- a/src/HasExpiration.php +++ b/src/HasExpiration.php @@ -97,11 +97,9 @@ public function getDaysLeftToExpiration(): ?int return 0; } - return $expiresAt - ->startOfDay() - ->diffInDays( - now()->startOfDay() - ); + return now()->startOfDay()->diffInDays( + $expiresAt->startOfDay() + ); } public function getDaysLeftToDeletion(): ?int diff --git a/tests/ArchTest.php b/tests/ArchTest.php new file mode 100644 index 0000000..ccc19b2 --- /dev/null +++ b/tests/ArchTest.php @@ -0,0 +1,5 @@ +expect(['dd', 'dump', 'ray']) + ->each->not->toBeUsed(); diff --git a/tests/HasExpirationTest.php b/tests/HasExpirationTest.php index a24dc0b..21b7a90 100644 --- a/tests/HasExpirationTest.php +++ b/tests/HasExpirationTest.php @@ -8,7 +8,7 @@ use function Spatie\PestPluginTestTime\testTime; -it('can create model with default expiration', function ($model, $expiresAt, $deletesAt) { +it('can create model with default expiration', function (string $model, ?int $expiresAt, ?int $deletesAt) { testTime()->freeze(); $model::factory()->count(5)->create(); @@ -39,7 +39,7 @@ ], ]); -it('can set expires_at', function ($model, $index, $days, $default) { +it('can set expires_at', function (string $model, int $index, int $days, ?Carbon $default) { $users = $model::factory()->count(3)->create(); $expirations = Expiration::get(); @@ -70,7 +70,7 @@ ['model' => Tenant::class, 'index' => 2, 'days' => -10, 'default' => fn () => now()->startOfDay()->addDays(365)], ]); -it('can get expires_at', function ($model, $index, $days, $default) { +it('can get expires_at', function (string $model, int $index, int $days, ?Carbon $default) { testTime()->freeze(); $users = $model::factory()->count(3)->create(); @@ -100,7 +100,7 @@ ['model' => Tenant::class, 'index' => 2, 'days' => -10, 'default' => fn () => now()->startOfDay()->addDays(365)], ]); -it('can get isExpired', function ($model, $index, $months) { +it('can get isExpired', function (string $model, int $index, int $months) { testTime()->freeze(); $users = $model::factory()->count(3)->create(); @@ -128,7 +128,7 @@ ['model' => Tenant::class, 'index' => 2, 'months' => 10], ]); -it('can get getDaysLeftToExpiration', function ($model, $index, $days, $default, $remainingIndex, $remaining) { +it('can get getDaysLeftToExpiration', function (string $model, int $index, int $days, ?int $default, int $remainingIndex, ?int $remaining) { testTime()->freeze(); $users = $model::factory()->count(3)->create(); @@ -155,7 +155,7 @@ ['model' => Tenant::class, 'index' => 2, 'days' => 10, 'default' => 365, 'remaining' => 6, 'remainingIndex' => fn () => 361], ]); -it('can get canExpire', function ($model, $index, $days, $default) { +it('can get canExpire', function (string $model, int $index, int $days, bool $default) { testTime()->freeze(); $users = $model::factory()->count(3)->create();