Skip to content

Commit

Permalink
⬆️ More Laravel 11 upgrades
Browse files Browse the repository at this point in the history
Signed-off-by: Julio Motol <julio.motol89@gmail.com>
  • Loading branch information
juliomotol committed Apr 1, 2024
1 parent 055be1f commit 71a05f8
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 93 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,31 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.6.0
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

compat-lookup: true

- name: Auto-merge Dependabot PRs for semver-minor updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Auto-merge Dependabot PRs for semver-patch updates
if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Auto-merge Dependabot PRs for Action major versions when compatibility is higher than 90%
if: ${{steps.metadata.outputs.package-ecosystem == 'github_actions' && steps.metadata.outputs.update-type == 'version-update:semver-major' && steps.metadata.outputs.compatibility-score >= 90}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
6 changes: 3 additions & 3 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:

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

- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@1.0.0
uses: aglipanci/laravel-pint-action@v2

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix styling
41 changes: 23 additions & 18 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
name: PHPStan

on:
push:
paths:
- '**.php'
- 'phpstan.neon.dist'
push:
paths:
- '**.php'
- 'phpstan.neon.dist'

jobs:
phpstan:
name: phpstan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
phpstan:
name: phpstan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- name: Install composer dependencies
uses: ramsey/composer-install@v2
- name: Install composer dependencies
uses: ramsey/composer-install@v3

- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
- name: Install larastan
run: |
composer require "larastan/larastan" --no-interaction --no-update
composer update --prefer-dist --no-interaction
- name: Run PHPStan
run: ./vendor/bin/phpstan --error-format=github
53 changes: 19 additions & 34 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,45 @@
name: run-tests
name: "Run Tests - Current"

on:
push:
branches:
- master
pull_request:
branches:
- master
on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}

runs-on: ubuntu-latest
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.2, 8.1]
laravel: ['9.*', '10.*', '11.*']
stability: [prefer-lowest, prefer-stable]
php: [8.3, 8.2, 8.1]
laravel: ["^11.0", "^10.0", "^9.0"]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 9.*
testbench: 7.*
carbon: ^2.63
- laravel: 10.*
- laravel: "^11.0"
testbench: 9.*
- laravel: "^10.0"
testbench: 8.*
carbon: ^2.63
- laravel: "^9.0"
testbench: 7.*
exclude:
- laravel: 11.*
php: 8.1
- laravel: "^11.0"
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: List Installed Dependencies
run: composer show -D
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "symfony/console:>=4.3.4" "mockery/mockery:^1.3.2" "nesbot/carbon:>=2.62.1" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/pest
4 changes: 2 additions & 2 deletions .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@v3
uses: actions/checkout@v4
with:
ref: main

Expand All @@ -21,7 +21,7 @@ jobs:
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: main
commit_message: Update CHANGELOG
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
"require-dev": {
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.0|^7.0|^8.0",
"nunomaduro/larastan": "^2.0.1",
"larastan/larastan": "^2.0.1",
"orchestra/testbench": "^7.0|^8.0|^9.0",
"pestphp/pest": "^1.21|^2.34",
"pestphp/pest-plugin-laravel": "^1.1|^2.3",
"pestphp/pest-plugin-mock": "^1.0|^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/AuthTimeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function init(): void
$this->hit();
}

public function check(string $guard = null): bool
public function check(?string $guard = null): bool
{
$user = $this->auth->guard($guard)->user();

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/AuthTimeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface AuthTimeout
{
public function init(): void;

public function check(string $guard = null): bool;
public function check(?string $guard = null): bool;

/** @deprecated Use `hit()` instead. */
public function reset(): void;
Expand Down
2 changes: 1 addition & 1 deletion src/Middlewares/CheckAuthTimeout.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CheckAuthTimeout
{
public static ?Closure $redirectToCallback = null;

public function handle(Request $request, Closure $next, string $guard = null): ?Response
public function handle(Request $request, Closure $next, ?string $guard = null): ?Response
{
if (Auth::guard($guard)->guest()) {
return $next($request);
Expand Down
64 changes: 38 additions & 26 deletions tests/AuthTimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

use Carbon\Carbon;
use Illuminate\Contracts\Auth\Factory;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Foundation\Auth\User;
use Illuminate\Session\Store;
use JulioMotol\AuthTimeout\AuthTimeout;
use Mockery;
use Mockery\MockInterface;
use function Pest\Laravel\mock as mockInContainer;

use function Pest\Laravel\mock;

it('won\'t initialize when already initialized', function () {
mockInContainer(Store::class, function (MockInterface $mock) {
mock(Store::class, function (MockInterface $mock) {
$mock->shouldReceive('get')->once()->andReturn(time());
$mock->shouldNotReceive('put');
});
Expand All @@ -21,7 +24,7 @@
});

it('can initialize', function () {
mockInContainer(Store::class, function (MockInterface $mock) {
mock(Store::class, function (MockInterface $mock) {
$mock->shouldReceive('get')->once()->andReturn(null);
$mock->shouldReceive('put')->once();
});
Expand All @@ -30,12 +33,16 @@
});

it('returns false when no user is logged in', function () {
mockInContainer(Factory::class, function (MockInterface $mock) {
mock(Factory::class, function (MockInterface $mock) {
$mock->shouldReceive('guard')
->once()
->andReturn(
mock(StatefulGuard::class)
->expect(user: fn () => null)
->andReturnUsing(
fn () => tap(
Mockery::mock(StatefulGuard::class),
fn (MockInterface $mock) => $mock->shouldReceive('user')
->once()
->andReturn(null)
)
);
});

Expand All @@ -49,22 +56,23 @@
config(['auth-timeout.event' => $event]);
}

mockInContainer(Factory::class, function (MockInterface $mock) {
mock(Factory::class, function (MockInterface $mock) {
$mock->shouldReceive('guard')
->twice()
->andReturn(
mock(StatefulGuard::class)
->expect(
user: fn () => new User(),
logout: fn () => null
)
->andReturnUsing(
fn () => tap(
Mockery::mock(StatefulGuard::class),
fn (MockInterface $mock) => $mock->shouldReceive('user')
->andReturn(new User())
->shouldReceive('logout')
)
);
});
mockInContainer(Store::class, function (MockInterface $mock) {
mock(Store::class, function (MockInterface $mock) {
$mock->shouldReceive('get')->once();
$mock->shouldReceive('forget')->once();
});
mockInContainer(Dispatcher::class, function (MockInterface $mock) use ($event) {
mock(Dispatcher::class, function (MockInterface $mock) use ($event) {
$mock->shouldReceive('dispatch')->once()->withArgs(function ($disptachedEvent) use ($event) {
if ($event) {
return $disptachedEvent::class === $event;
Expand All @@ -83,19 +91,23 @@
]);

it('returns true when user is not timed out', function () {
mockInContainer(Factory::class, function (MockInterface $mock) {
mock(Factory::class, function (MockInterface $mock) {
$mock->shouldReceive('guard')
->once()
->andReturn(
mock(StatefulGuard::class)
->expect(user: fn () => new User())
->andReturnUsing(
fn () => tap(
Mockery::mock(StatefulGuard::class),
fn (MockInterface $mock) => $mock->shouldReceive('user')
->once()
->andReturn(new User())
)
);
});
mockInContainer(Store::class, function (MockInterface $mock) {
mock(Store::class, function (MockInterface $mock) {
$mock->shouldReceive('get')->once()->andReturn(time());
$mock->shouldNotReceive('forget');
});
mockInContainer(Dispatcher::class, function (MockInterface $mock) {
mock(Dispatcher::class, function (MockInterface $mock) {
$mock->shouldNotReceive('dispatch');
});

Expand All @@ -105,15 +117,15 @@
});

it('can hit', function () {
mockInContainer(Store::class, function (MockInterface $mock) {
mock(Store::class, function (MockInterface $mock) {
$mock->shouldReceive('put')->once();
});

app(AuthTimeout::class)->hit();
});

it('can get last active at', function () {
mockInContainer(Store::class, function (MockInterface $mock) {
mock(Store::class, function (MockInterface $mock) {
$mock->shouldReceive('get')->once()->andReturn((string) Carbon::now());
});

Expand All @@ -123,7 +135,7 @@
});

it('can get last active at (legacy v2)', function () {
mockInContainer(Store::class, function (MockInterface $mock) {
mock(Store::class, function (MockInterface $mock) {
$mock->shouldReceive('get')->once()->andReturn(time());
});

Expand All @@ -133,7 +145,7 @@
});

it('returns null when getting last active at and not initialized', function () {
mockInContainer(Store::class, function (MockInterface $mock) {
mock(Store::class, function (MockInterface $mock) {
$mock->shouldReceive('get')->once()->andReturn(null);
});

Expand Down
Loading

0 comments on commit 71a05f8

Please sign in to comment.