diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml index 62f6106ac43c..f0beab368979 100644 --- a/.github/workflows/php-cs-fixer.yml +++ b/.github/workflows/php-cs-fixer.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 0323ffc4fb6e..122a5bd2870f 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -11,12 +11,12 @@ jobs: name: phpstan runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none - name: Install composer dependencies diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e1d83a2067a5..3ea054473c93 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,8 @@ jobs: if: github.event.pull_request.merged == true runs-on: "ubuntu-latest" steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - uses: ncipollo/release-action@v1 with: name: ${{ github.event.pull_request.title }} diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 3e4f87802467..b3ca5a568d86 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,34 +1,28 @@ name: run-tests -on: - - push - - pull_request +on: [push, pull_request] jobs: test: runs-on: ${{ matrix.os }} - strategy: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.1, '8.2'] - laravel: ['11.0', ^10.0] + php: [8.3, 8.2] + laravel: [10.*, 11.*] stability: [prefer-stable] include: - - laravel: ^10.0 - testbench: ^8.0 - - laravel: '11.0' - testbench: ^9.0 - exclude: - - laravel: '11.0' - php: 8.1 + - laravel: 10.* + testbench: 8.* + - laravel: 11.* + testbench: 9.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -47,5 +41,11 @@ jobs: composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction + - name: Clear Composer cache + run: composer clear-cache + + - name: Wait for a few seconds + run: sleep 5 + - name: Execute tests - run: ./vendor/bin/testbench package:test + run: ./vendor/bin/testbench package:test --no-coverage diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml index 6c58564a807f..3bc87c45db4d 100644 --- a/.github/workflows/update-changelog.yml +++ b/.github/workflows/update-changelog.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: ref: main diff --git a/composer.json b/composer.json index 5c5d4908c328..54df3167e77f 100644 --- a/composer.json +++ b/composer.json @@ -17,17 +17,17 @@ } ], "require": { - "php": "^8.0|^8.1", - "illuminate/support": "^9.0|^10.0|^11.0", + "php": "^8.2", + "illuminate/support": "^10.0|^11.0", "opis/closure": "^3.6" }, "require-dev": { - "brianium/paratest": "^6.2|^7.0.6", - "nunomaduro/collision": "^5.3|^6.1|^7.0|^8.0", + "brianium/paratest": "^7.0.6", + "nunomaduro/collision": "^7.0|^8.0", "nunomaduro/larastan": "^2.0", "orchestra/testbench": "^8.0|^9.0", "phpstan/extension-installer": "^1.1", - "phpunit/phpunit": "^10.0", + "phpunit/phpunit": "^10.0|^11.0", "spatie/laravel-ray": "^1.9", "spatie/test-time": "^1.2" }, diff --git a/src/Console/Commands/PruneMailatorLogsCommand.php b/src/Console/Commands/PruneMailatorLogsCommand.php index 074ab39cb02c..a8328df86636 100644 --- a/src/Console/Commands/PruneMailatorLogsCommand.php +++ b/src/Console/Commands/PruneMailatorLogsCommand.php @@ -13,6 +13,10 @@ class PruneMailatorLogsCommand extends Command public function handle(): void { - $this->info(MailatorLog::prune(now()->subDays((int)$this->option('days'))) . ' entries pruned.'); + $this->info( + MailatorLog::prune( + now()->subDays((int)$this->option('days')) + ) . ' entries pruned.' + ); } } diff --git a/src/Console/Commands/PruneMailatorScheduleCommand.php b/src/Console/Commands/PruneMailatorScheduleCommand.php index c3ce2ad2815e..1fb724406d78 100644 --- a/src/Console/Commands/PruneMailatorScheduleCommand.php +++ b/src/Console/Commands/PruneMailatorScheduleCommand.php @@ -13,6 +13,11 @@ class PruneMailatorScheduleCommand extends Command public function handle(): void { - $this->info(MailatorSchedule::prune(now()->subDays((int)$this->option('days'))) . ' entries pruned.'); + $this->info( + MailatorSchedule::prune( + now()->subDays((int)$this->option('days')), + ['logs'] + ) . ' entries pruned.' + ); } } diff --git a/src/Constraints/AfterConstraint.php b/src/Constraints/AfterConstraint.php index cafcc999fd95..9305932ece99 100644 --- a/src/Constraints/AfterConstraint.php +++ b/src/Constraints/AfterConstraint.php @@ -22,9 +22,14 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool return false; } + $diff = (int) $schedule->timestamp_target->diffInDays( + now()->floorSeconds(), + absolute: true + ); + return $schedule->isOnce() - ? $schedule->timestamp_target->diffInDays(now()->floorSeconds()) === $schedule->toDays() - : $schedule->timestamp_target->diffInDays(now()->floorSeconds()) > $schedule->toDays(); + ? $diff === $schedule->toDays() + : $diff > $schedule->toDays(); } if ($schedule->toHours() > 0) { @@ -32,19 +37,29 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool return false; } + $diff = (int) $schedule->timestamp_target->diffInHours( + now()->floorSeconds(), + absolute: true + ); + //till ends we should have at least toDays days return $schedule->isOnce() - ? $schedule->timestamp_target->diffInHours(now()->floorSeconds()) === $schedule->toHours() - : $schedule->timestamp_target->diffInHours(now()->floorSeconds()) > $schedule->toHours(); + ? $diff === $schedule->toHours() + : $diff > $schedule->toHours(); } if (now()->floorSeconds()->lte($schedule->timestampTarget()->addMinutes($schedule->delay_minutes))) { return false; } + $diff = (int) $schedule->timestamp_target->diffInHours( + now()->floorSeconds(), + absolute: true + ); + //till ends we should have at least toDays days return $schedule->isOnce() - ? $schedule->timestamp_target->diffInHours(now()->floorSeconds()) === $schedule->delay_minutes - : $schedule->timestamp_target->diffInHours(now()->floorSeconds()) > $schedule->delay_minutes; + ? $diff === $schedule->delay_minutes + : $diff > $schedule->delay_minutes; } } diff --git a/src/Constraints/BeforeConstraint.php b/src/Constraints/BeforeConstraint.php index ae10d7f5eded..60a9ce476d18 100644 --- a/src/Constraints/BeforeConstraint.php +++ b/src/Constraints/BeforeConstraint.php @@ -27,10 +27,15 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool return false; } + $diff = (int) $schedule->timestampTarget()->diffInDays( + now()->floorSeconds(), + absolute: true + ); + //till ends we should have at least toDays days return $schedule->isOnce() - ? $schedule->timestampTarget()->diffInDays(now()->floorSeconds()) === $schedule->toDays() - : $schedule->timestampTarget()->diffInDays(now()->floorSeconds()) < $schedule->toDays(); + ? $diff === $schedule->toDays() + : $diff < $schedule->toDays(); } if ($schedule->toHours() > 0) { @@ -38,17 +43,25 @@ public function canSend(MailatorSchedule $schedule, Collection $logs): bool return false; } + $diff = (int) $schedule->timestamp_target->diffInHours( + now()->floorSeconds(), + absolute: true + ); + //till ends we should have at least toHours days return $schedule->isOnce() - ? $schedule->timestamp_target->diffInHours(now()->floorSeconds()) === $schedule->toHours() - : $schedule->timestamp_target->diffInHours(now()->floorSeconds()) < $schedule->toHours(); + ? $diff === $schedule->toHours() + : $diff < $schedule->toHours(); } - + $diff = (int) $schedule->timestampTarget()->diffInDays( + now()->floorSeconds(), + absolute: true + ); //till ends we should have at least toDays days return $schedule->isOnce() - ? $schedule->timestampTarget()->diffInDays(now()->floorSeconds()) === $schedule->toDays() - : $schedule->timestampTarget()->diffInDays(now()->floorSeconds()) < $schedule->toDays(); + ? $diff === $schedule->toDays() + : $diff < $schedule->toDays(); } } diff --git a/src/LaravelMailatorServiceProvider.php b/src/LaravelMailatorServiceProvider.php index 0df291d12bd6..6735e93f8270 100644 --- a/src/LaravelMailatorServiceProvider.php +++ b/src/LaravelMailatorServiceProvider.php @@ -50,7 +50,7 @@ public function boot() if (! class_exists('CreateMailatorTables')) { $this->publishes([ - __DIR__ . '/../database/migrations/create_mailator_tables.php.stub' => database_path('migrations/' . date('Y_m_d_His', now()->subMinute(1)->timestamp) . '_create_mailator_tables.php'), + __DIR__ . '/../database/migrations/create_mailator_tables.php.stub' => database_path('migrations/' . date('Y_m_d_His', now()->subMinute()->timestamp) . '_create_mailator_tables.php'), ], 'mailator-migrations'); } diff --git a/src/Models/Concerns/WithPrune.php b/src/Models/Concerns/WithPrune.php index a66a4581420e..1bc66355402c 100644 --- a/src/Models/Concerns/WithPrune.php +++ b/src/Models/Concerns/WithPrune.php @@ -10,10 +10,13 @@ */ trait WithPrune { - public static function prune(DateTimeInterface $before) + public static function prune(DateTimeInterface $before, array $with = []) { $query = static::query() - ->with('logs') + ->when( + $with !== [], + fn ($query) => $query->with($with) + ) ->where('created_at', '<', $before); $totalDeleted = 0; diff --git a/src/Replacers/Concerns/ReplaceModelAttributes.php b/src/Replacers/Concerns/ReplaceModelAttributes.php index 841030a57602..a7e5d8b41138 100644 --- a/src/Replacers/Concerns/ReplaceModelAttributes.php +++ b/src/Replacers/Concerns/ReplaceModelAttributes.php @@ -30,7 +30,7 @@ public function replaceModelAttributes(string $text, string $replaceText, Model ?? ''; }, $model); - return $replace ?? $match; + return $replace ?: $match; }, $text); } } diff --git a/src/Replacers/ModelAttributesReplacer.php b/src/Replacers/ModelAttributesReplacer.php index 301c1ad49298..58535b0328c3 100644 --- a/src/Replacers/ModelAttributesReplacer.php +++ b/src/Replacers/ModelAttributesReplacer.php @@ -10,7 +10,7 @@ class ModelAttributesReplacer implements Replacer { use ReplaceModelAttributes; - /** * @var Model */ + /** @var Model */ protected $model; public function replace(string $html, MailTemplateable $template): string diff --git a/src/Support/WithMailTemplate.php b/src/Support/WithMailTemplate.php index c030d5415eb4..ca8d8703d559 100644 --- a/src/Support/WithMailTemplate.php +++ b/src/Support/WithMailTemplate.php @@ -25,7 +25,7 @@ public function template(MailTemplateable $template) $this->template = $template; - /** * @var PersonalizeMailAction $replacerAction */ + /** @var PersonalizeMailAction $replacerAction */ $replacerAction = app(PersonalizeMailAction::class); // replace placehlders diff --git a/tests/TestCase.php b/tests/TestCase.php index 33f20daff98c..fc2d5be05c5b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -37,6 +37,8 @@ protected function getPackageProviders($app) protected function getEnvironmentSetUp($app) { + $app['config']->set('queue.default', 'sync'); + $app['config']->set('database.default', 'sqlite'); $app['config']->set('database.connections.sqlite', [ @@ -45,6 +47,7 @@ protected function getEnvironmentSetUp($app) 'prefix' => '', ]); + include_once __DIR__.'/../database/migrations/create_mailator_tables.php.stub'; (new \CreateMailatorTables())->up(); } diff --git a/tests/database/migrations/2017_10_10_000000_create_jobs_table.php b/tests/database/migrations/2017_10_10_000000_create_jobs_table.php new file mode 100644 index 000000000000..fe16e3de11ea --- /dev/null +++ b/tests/database/migrations/2017_10_10_000000_create_jobs_table.php @@ -0,0 +1,20 @@ +id(); + $table->string('queue')->index(); + $table->longText('payload'); + $table->unsignedTinyInteger('attempts'); + $table->unsignedInteger('reserved_at')->nullable(); + $table->unsignedInteger('available_at'); + $table->unsignedInteger('created_at'); + }); + } +}; diff --git a/tests/database/migrations/2017_10_10_000000_create_posts_table.php b/tests/database/migrations/2017_10_10_000000_create_posts_table.php index 33d6e1c23b87..653ba2a1d656 100644 --- a/tests/database/migrations/2017_10_10_000000_create_posts_table.php +++ b/tests/database/migrations/2017_10_10_000000_create_posts_table.php @@ -4,13 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { - /** - * Run the migrations. - * - * @return void - */ - public function up() +return new class() extends Migration { + public function up(): void { Schema::create('posts', function (Blueprint $table) { $table->increments('id'); @@ -20,12 +15,7 @@ public function up() }); } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() + public function down(): void { Schema::dropIfExists('posts'); } diff --git a/tests/database/migrations/2017_10_10_000000_create_users_table.php b/tests/database/migrations/2017_10_10_000000_create_users_table.php index 97e7b2bb36ce..2a5bc24e7ecc 100644 --- a/tests/database/migrations/2017_10_10_000000_create_users_table.php +++ b/tests/database/migrations/2017_10_10_000000_create_users_table.php @@ -4,14 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateUsersTable extends Migration -{ - /** - * Run the migrations. - * - * @return void - */ - public function up() +return new class() extends Migration { + public function up(): void { Schema::create('users', function (Blueprint $table) { $table->increments('id'); @@ -24,13 +18,8 @@ public function up() }); } - /** - * Reverse the migrations. - * - * @return void - */ - public function down() + public function down(): void { Schema::dropIfExists('users'); } -} +};