Skip to content

Commit

Permalink
Support PHP 8.2+ (#2586)
Browse files Browse the repository at this point in the history
* Support PHP 8.2+

* Changes

* Fix PHP Stan

* Set connection to sync

* Fix styling

* Fix PHP Stan Install

---------

Co-authored-by: arthurkirkosa <[email protected]>
  • Loading branch information
arthurkirkosa and arthurkirkosa authored Jul 3, 2024
1 parent a7553a4 commit 83d589b
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: main

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 5 additions & 1 deletion src/Console/Commands/PruneMailatorLogsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
}
}
7 changes: 6 additions & 1 deletion src/Console/Commands/PruneMailatorScheduleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
}
}
27 changes: 21 additions & 6 deletions src/Constraints/AfterConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,44 @@ 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) {
if (now()->floorSeconds()->lt($schedule->timestampTarget()->addHours($schedule->toHours()))) {
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;
}
}
27 changes: 20 additions & 7 deletions src/Constraints/BeforeConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,41 @@ 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) {
if (now()->floorSeconds()->gt($schedule->timestampTarget()->addHours($schedule->toHours()))) {
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();
}
}
2 changes: 1 addition & 1 deletion src/LaravelMailatorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
7 changes: 5 additions & 2 deletions src/Models/Concerns/WithPrune.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Replacers/Concerns/ReplaceModelAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function replaceModelAttributes(string $text, string $replaceText, Model
?? '';
}, $model);

return $replace ?? $match;
return $replace ?: $match;
}, $text);
}
}
2 changes: 1 addition & 1 deletion src/Replacers/ModelAttributesReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ModelAttributesReplacer implements Replacer
{
use ReplaceModelAttributes;

/** * @var Model */
/** @var Model */
protected $model;

public function replace(string $html, MailTemplateable $template): string
Expand Down
2 changes: 1 addition & 1 deletion src/Support/WithMailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function template(MailTemplateable $template)

$this->template = $template;

/** * @var PersonalizeMailAction $replacerAction */
/** @var PersonalizeMailAction $replacerAction */
$replacerAction = app(PersonalizeMailAction::class);

// replace placehlders
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand All @@ -45,6 +47,7 @@ protected function getEnvironmentSetUp($app)
'prefix' => '',
]);


include_once __DIR__.'/../database/migrations/create_mailator_tables.php.stub';
(new \CreateMailatorTables())->up();
}
Expand Down
20 changes: 20 additions & 0 deletions tests/database/migrations/2017_10_10_000000_create_jobs_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
public function up(): void
{
Schema::create('jobs', function (Blueprint $table): void {
$table->id();
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
};
16 changes: 3 additions & 13 deletions tests/database/migrations/2017_10_10_000000_create_posts_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -20,12 +15,7 @@ public function up()
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('posts');
}
Expand Down
19 changes: 4 additions & 15 deletions tests/database/migrations/2017_10_10_000000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -24,13 +18,8 @@ public function up()
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists('users');
}
}
};

0 comments on commit 83d589b

Please sign in to comment.