Skip to content

Commit

Permalink
feat: Add full support for Laravel 11 (#12)
Browse files Browse the repository at this point in the history
* feat: Add full support for Laravel 11

Signed-off-by: Natsuki Ikeguchi <me@s6n.jp>

* ci: Use the dedicated PHPUnit version for each PHP versions

Signed-off-by: Natsuki Ikeguchi <me@s6n.jp>

---------

Signed-off-by: Natsuki Ikeguchi <me@s6n.jp>
  • Loading branch information
siketyan committed Mar 13, 2024
1 parent 0a36dd0 commit 759382f
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 11 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,36 @@ jobs:
strategy:
matrix:
php: ['8.0', 8.1, 8.2]
lib:
- { laravel: ^11.0 }
- { laravel: ^10.0 }
- { laravel: ^9.0 }
laravel: [11, 10, 9]
include:
- { laravel: 11, phpunit: 11 }
- { laravel: 10, phpunit: 10 }
- { laravel: 9, phpunit: 9 }
exclude:
- { php: 8.0, lib: { laravel: ^10.0 } }
- { php: 8.0, lib: { laravel: ^11.0 } }
- { php: 8.1, lib: { laravel: ^11.0 } }
- { php: 8.0, laravel: 10 }
- { php: 8.0, laravel: 11 }
- { php: 8.1, laravel: 11 }

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug

- run: composer require "laravel/framework:${{ matrix.lib.laravel }}" --dev
- run: composer require "laravel/framework:^${{ matrix.laravel }}" --dev
- run: composer require "phpunit/phpunit:^${{ matrix.phpunit }}" --dev
- run: mkdir -p build/logs
- run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- run: vendor/bin/phpunit -c 'phpunit${{ matrix.phpunit }}.xml' --coverage-clover build/logs/clover.xml

- name: Upload Coverage
uses: nick-invision/retry@v2
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_PARALLEL: 'true'
COVERALLS_FLAG_NAME: 'laravel:${{ matrix.lib.laravel }}'
COVERALLS_FLAG_NAME: 'laravel:${{ matrix.laravel }}'
with:
timeout_minutes: 1
max_attempts: 3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.idea/
/vendor/
.php_cs.cache
.phpunit.result.cache
/.phpunit.cache/
composer.lock
File renamed without changes.
13 changes: 13 additions & 0 deletions phpunit11.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
13 changes: 13 additions & 0 deletions phpunit9.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd" cacheResultFile=".phpunit.result.cache" backupStaticAttributes="false">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
7 changes: 7 additions & 0 deletions src/Concerns/ProvidesNothing.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ public function validateCredentials(Authenticatable $user, array $credentials):
{
return false;
}

/**
* Rehash the user's password if required and supported.
*/
public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false)
{
}
}
8 changes: 8 additions & 0 deletions src/GenericNullAuthenticatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public function getAuthPassword(): string
return '';
}

/**
* Get the name of the password attribute for the user.
*/
public function getAuthPasswordName(): string
{
return '';
}

/**
* Get the token value for the "remember me" session.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/GenericStrictNullAuthenticatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ public function getAuthPassword(): string
throw new BadMethodCallException('Not implemented');
}

/**
* Get the name of the password attribute for the user.
*/
public function getAuthPasswordName(): string
{
throw new BadMethodCallException('Not implemented');
}

/**
* Get the token value for the "remember me" session.
*/
Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/NullAuthenticatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BadMethodCallException;
use Illuminate\Auth\GenericUser;
use Illuminate\Contracts\Auth\Authenticatable;
use Mpyw\NullAuth\NullAuthenticatable;
use Mpyw\NullAuth\StrictNullAuthenticatable;
use Mpyw\NullAuth\Tests\TestCase;
Expand Down Expand Up @@ -51,6 +52,15 @@ public function getKeyName()
};
}

public function testSatisfiesAuthenticatableInterface(): void
{
$user = new class() implements Authenticatable {
use NullAuthenticatable;
};

$this->assertInstanceOf(Authenticatable::class, $user);
}

public function testGetAuthIdentifierName(): void
{
$this->assertSame('id', $this->user->getAuthIdentifierName());
Expand All @@ -72,6 +82,15 @@ public function testGetAuthPassword(): void
$this->strict->getAuthPassword();
}

public function testGetAuthPasswordName(): void
{
$this->assertSame('', $this->user->getAuthPasswordName());

$this->expectException(BadMethodCallException::class);
$this->expectExceptionMessage('Not implemented');
$this->strict->getAuthPasswordName();
}

public function testGetRememberToken(): void
{
$this->assertSame('', $this->user->getRememberToken());
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/NullUserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ public function testValidateCredentials(): void
$this->provider = new NullUserProvider();
$this->assertFalse($this->provider->validateCredentials(new GenericUser([[]]), ['email' => 'xxx@example.com', 'password' => 'abc123']));
}

public function testRehashPasswordIfRequired(): void
{
$this->provider = new NullUserProvider();
$this->provider->rehashPasswordIfRequired(new GenericUser([]), []);
$this->assertTrue(true);
}
}

0 comments on commit 759382f

Please sign in to comment.