diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f39ca0f..cf6759c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,17 +9,18 @@ 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 @@ -27,16 +28,17 @@ jobs: 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 diff --git a/.gitignore b/.gitignore index cd68c1b..b09f2ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.idea/ /vendor/ .php_cs.cache +.phpunit.result.cache /.phpunit.cache/ composer.lock diff --git a/phpunit.xml b/phpunit10.xml similarity index 100% rename from phpunit.xml rename to phpunit10.xml diff --git a/phpunit11.xml b/phpunit11.xml new file mode 100644 index 0000000..fd9e1f4 --- /dev/null +++ b/phpunit11.xml @@ -0,0 +1,13 @@ + + + + + src + + + + + ./tests/ + + + diff --git a/phpunit9.xml b/phpunit9.xml new file mode 100644 index 0000000..06da286 --- /dev/null +++ b/phpunit9.xml @@ -0,0 +1,13 @@ + + + + + src + + + + + ./tests/ + + + diff --git a/src/Concerns/ProvidesNothing.php b/src/Concerns/ProvidesNothing.php index 1a7c248..0f31a7e 100644 --- a/src/Concerns/ProvidesNothing.php +++ b/src/Concerns/ProvidesNothing.php @@ -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) + { + } } diff --git a/src/GenericNullAuthenticatable.php b/src/GenericNullAuthenticatable.php index 5453f15..50a823e 100644 --- a/src/GenericNullAuthenticatable.php +++ b/src/GenericNullAuthenticatable.php @@ -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. */ diff --git a/src/GenericStrictNullAuthenticatable.php b/src/GenericStrictNullAuthenticatable.php index 48c73ac..6a71788 100644 --- a/src/GenericStrictNullAuthenticatable.php +++ b/src/GenericStrictNullAuthenticatable.php @@ -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. */ diff --git a/tests/Unit/NullAuthenticatableTest.php b/tests/Unit/NullAuthenticatableTest.php index 8f427c6..7d6ae77 100644 --- a/tests/Unit/NullAuthenticatableTest.php +++ b/tests/Unit/NullAuthenticatableTest.php @@ -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; @@ -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()); @@ -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()); diff --git a/tests/Unit/NullUserProviderTest.php b/tests/Unit/NullUserProviderTest.php index d1a1389..f0de9e9 100644 --- a/tests/Unit/NullUserProviderTest.php +++ b/tests/Unit/NullUserProviderTest.php @@ -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); + } }