diff --git a/composer.json b/composer.json index f2ec616e..49f63960 100644 --- a/composer.json +++ b/composer.json @@ -31,10 +31,10 @@ "psr/http-server-middleware": "^1.0" }, "require-dev": { - "cakephp/cakephp": "^5.0", + "cakephp/cakephp": "dev-5.next as 5.1.0", "cakephp/cakephp-codesniffer": "^5.0", "firebase/php-jwt": "^6.2", - "phpunit/phpunit": "^10.1.0" + "phpunit/phpunit": "^10.5.5 || ^11.1.3" }, "suggest": { "ext-ldap": "Make sure this php extension is installed and enabled on your system if you want to use the built-in LDAP adapter for \"LdapIdentifier\".", diff --git a/tests/TestCase/Authenticator/AbstractAuthenticatorTest.php b/tests/TestCase/Authenticator/AbstractAuthenticatorTest.php index 5738f994..90b2bcdc 100644 --- a/tests/TestCase/Authenticator/AbstractAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/AbstractAuthenticatorTest.php @@ -17,6 +17,8 @@ namespace Authentication\Test\TestCase\Authenticator; use Authentication\Authenticator\AbstractAuthenticator; +use Authentication\Authenticator\Result; +use Authentication\Authenticator\ResultInterface; use Authentication\Identifier\IdentifierInterface; use Authentication\Test\TestCase\AuthenticationTestCase as TestCase; @@ -30,7 +32,12 @@ class AbstractAuthenticatorTest extends TestCase public function testGetIdentifier() { $identifier = $this->createMock(IdentifierInterface::class); - $authenticator = $this->getMockForAbstractClass(AbstractAuthenticator::class, [$identifier]); + $authenticator = new class ($identifier) extends AbstractAuthenticator { + public function authenticate($request): Result + { + return new Result([], ResultInterface::SUCCESS); + } + }; $this->assertSame($identifier, $authenticator->getIdentifier()); } @@ -42,11 +49,17 @@ public function testGetIdentifier() */ public function testSetIdentifier() { - $authenticator = $this->getMockForAbstractClass(AbstractAuthenticator::class, [], '', false); - $identifier = $this->createMock(IdentifierInterface::class); - $authenticator->setIdentifier($identifier); + $authenticator = new class ($identifier) extends AbstractAuthenticator { + public function authenticate($request): Result + { + return new Result([], ResultInterface::SUCCESS); + } + }; - $this->assertSame($identifier, $authenticator->getIdentifier()); + $otherIdentifier = $this->createMock(IdentifierInterface::class); + $authenticator->setIdentifier($otherIdentifier); + + $this->assertSame($otherIdentifier, $authenticator->getIdentifier()); } } diff --git a/tests/TestCase/Authenticator/JwtAuthenticatorTest.php b/tests/TestCase/Authenticator/JwtAuthenticatorTest.php index e10dd65a..c5ae8b0c 100644 --- a/tests/TestCase/Authenticator/JwtAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/JwtAuthenticatorTest.php @@ -226,7 +226,7 @@ public function testAuthenticateInvalidPayloadEmpty() $authenticator->expects($this->once()) ->method('getPayLoad') - ->will($this->returnValue(new stdClass())); + ->willReturn(new stdClass()); $result = $authenticator->authenticate($request); $this->assertInstanceOf(Result::class, $result); diff --git a/tests/TestCase/Authenticator/SessionAuthenticatorTest.php b/tests/TestCase/Authenticator/SessionAuthenticatorTest.php index 95cb711b..d534f498 100644 --- a/tests/TestCase/Authenticator/SessionAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/SessionAuthenticatorTest.php @@ -80,10 +80,10 @@ public function testAuthenticateSuccess() $this->sessionMock->expects($this->once()) ->method('read') ->with('Auth') - ->will($this->returnValue([ + ->willReturn([ 'username' => 'mariano', 'password' => 'password', - ])); + ]); $request = $request->withAttribute('session', $this->sessionMock); @@ -106,7 +106,7 @@ public function testAuthenticateFailure() $this->sessionMock->expects($this->once()) ->method('read') ->with('Auth') - ->will($this->returnValue(null)); + ->willReturn(null); $request = $request->withAttribute('session', $this->sessionMock); @@ -129,10 +129,10 @@ public function testVerifyByDatabaseSuccess() $this->sessionMock->expects($this->once()) ->method('read') ->with('Auth') - ->will($this->returnValue([ + ->willReturn([ 'username' => 'mariano', 'password' => 'h45h', - ])); + ]); $request = $request->withAttribute('session', $this->sessionMock); @@ -157,10 +157,10 @@ public function testVerifyByDatabaseFailure() $this->sessionMock->expects($this->once()) ->method('read') ->with('Auth') - ->will($this->returnValue([ + ->willReturn([ 'username' => 'does-not', 'password' => 'exist', - ])); + ]); $request = $request->withAttribute('session', $this->sessionMock); diff --git a/tests/TestCase/Identifier/Resolver/ResolverAwareTraitTest.php b/tests/TestCase/Identifier/Resolver/ResolverAwareTraitTest.php index 050bd27b..5d9612ae 100644 --- a/tests/TestCase/Identifier/Resolver/ResolverAwareTraitTest.php +++ b/tests/TestCase/Identifier/Resolver/ResolverAwareTraitTest.php @@ -25,13 +25,14 @@ class ResolverAwareTraitTest extends TestCase { public function testBuildResolverFromClassName() { - $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->addMethods(['getConfig']) - ->getMockForTrait(); + $object = new class { + use ResolverAwareTrait; - $object->expects($this->once()) - ->method('getConfig') - ->willReturn('Test'); + public function getConfig() + { + return 'Test'; + } + }; $resolver = $object->getResolver(); $this->assertInstanceOf(TestResolver::class, $resolver); @@ -39,15 +40,16 @@ public function testBuildResolverFromClassName() public function testBuildResolverFromArray() { - $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->addMethods(['getConfig']) - ->getMockForTrait(); + $object = new class { + use ResolverAwareTrait; - $object->expects($this->once()) - ->method('getConfig') - ->willReturn([ - 'className' => 'Test', - ]); + public function getConfig() + { + return [ + 'className' => 'Test', + ]; + } + }; $resolver = $object->getResolver(); $this->assertInstanceOf(TestResolver::class, $resolver); @@ -57,13 +59,14 @@ public function testBuildResolverInvalid() { $this->expectException('RuntimeException'); $this->expectExceptionMessage('Resolver must implement `Authentication\Identifier\Resolver\ResolverInterface`.'); - $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->addMethods(['getConfig']) - ->getMockForTrait(); + $object = new class { + use ResolverAwareTrait; - $object->expects($this->once()) - ->method('getConfig') - ->willReturn('Invalid'); + public function getConfig() + { + return 'Invalid'; + } + }; $object->getResolver(); } @@ -72,13 +75,14 @@ public function testBuildResolverMissing() { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Resolver class `Missing` does not exist.'); - $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->addMethods(['getConfig']) - ->getMockForTrait(); + $object = new class { + use ResolverAwareTrait; - $object->expects($this->once()) - ->method('getConfig') - ->willReturn('Missing'); + public function getConfig() + { + return 'Missing'; + } + }; $object->getResolver(); } @@ -87,13 +91,14 @@ public function testBuildResolverMissingClassNameOption() { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Option `className` is not present.'); - $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->addMethods(['getConfig']) - ->getMockForTrait(); + $object = new class { + use ResolverAwareTrait; - $object->expects($this->once()) - ->method('getConfig') - ->willReturn([]); + public function getConfig() + { + return []; + } + }; $object->getResolver(); } @@ -102,22 +107,23 @@ public function testGetResolverNotSet() { $this->expectException('RuntimeException'); $this->expectExceptionMessage('Resolver has not been set.'); - $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->addMethods(['getConfig']) - ->getMockForTrait(); + $object = new class { + use ResolverAwareTrait; - $object->expects($this->once()) - ->method('getConfig') - ->willReturn(null); + public function getConfig() + { + return null; + } + }; $object->getResolver(); } public function testSetResolver() { - $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->addMethods(['getConfig']) - ->getMockForTrait(); + $object = new class { + use ResolverAwareTrait; + }; $resolver = $this->createMock(ResolverInterface::class); diff --git a/tests/TestCase/PasswordHasher/PasswordHasherTraitTest.php b/tests/TestCase/PasswordHasher/PasswordHasherTraitTest.php index 720d6e46..576ac971 100644 --- a/tests/TestCase/PasswordHasher/PasswordHasherTraitTest.php +++ b/tests/TestCase/PasswordHasher/PasswordHasherTraitTest.php @@ -32,7 +32,9 @@ class PasswordHasherTraitTest extends TestCase */ public function testGetPasswordHasher() { - $object = $this->getMockForTrait(PasswordHasherTrait::class); + $object = new class { + use PasswordHasherTrait; + }; $defaultHasher = $object->getPasswordHasher(); $this->assertInstanceOf(DefaultPasswordHasher::class, $defaultHasher); @@ -46,7 +48,9 @@ public function testGetPasswordHasher() public function testSetPasswordHasher() { $hasher = $this->createMock(PasswordHasherInterface::class); - $object = $this->getMockForTrait(PasswordHasherTrait::class); + $object = new class { + use PasswordHasherTrait; + }; $object->setPasswordHasher($hasher); $passwordHasher = $object->getPasswordHasher();