diff --git a/.gitignore b/.gitignore index afd585a4..6b22f8f8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ /tmp /tools /vendor -.phpunit.result.cache +.phpunit.cache # OS generated files # ###################### diff --git a/composer.json b/composer.json index d7edad6e..bcea7f76 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "cakephp/cakephp": "5.x-dev", "cakephp/cakephp-codesniffer": "^5.0", "firebase/php-jwt": "^6.2", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^10.1.0" }, "suggest": { "cakephp/orm": "To use \"OrmResolver\" (Not needed separately if using full CakePHP framework).", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9b2aea87..2ee68e66 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,33 +1,33 @@ - - - - src/ - - - src/Identifier/Ldap/ExtensionAdapter.php - - + - - - - + + + tests/TestCase/ + + - - - tests/TestCase/ - - + + + - - - + + + src/ + + + src/Identifier/Ldap/ExtensionAdapter.php + + + + + + + diff --git a/src/UrlChecker/UrlCheckerTrait.php b/src/UrlChecker/UrlCheckerTrait.php index 36139a24..fba0043b 100644 --- a/src/UrlChecker/UrlCheckerTrait.php +++ b/src/UrlChecker/UrlCheckerTrait.php @@ -62,9 +62,9 @@ protected function _getUrlChecker(): UrlCheckerInterface throw new RuntimeException(sprintf('URL checker class `%s` was not found.', $options['className'])); } - $checker = new $className(); + $interfaces = class_implements($className); - if (!($checker instanceof UrlCheckerInterface)) { + if (!isset($interfaces[UrlCheckerInterface::class])) { throw new RuntimeException(sprintf( 'The provided URL checker class `%s` does not implement the `%s` interface.', $options['className'], @@ -72,6 +72,9 @@ protected function _getUrlChecker(): UrlCheckerInterface )); } - return $checker; + /** @var \Authentication\UrlChecker\UrlCheckerInterface $obj */ + $obj = new $className(); + + return $obj; } } diff --git a/tests/TestCase/Authenticator/HttpDigestAuthenticatorTest.php b/tests/TestCase/Authenticator/HttpDigestAuthenticatorTest.php index c04a81d9..c76c4083 100644 --- a/tests/TestCase/Authenticator/HttpDigestAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/HttpDigestAuthenticatorTest.php @@ -26,7 +26,6 @@ use Cake\I18n\DateTime; use Cake\ORM\TableRegistry; use Cake\TestSuite\TestCase; -use PHPUnit\Framework\Constraint\RegularExpression; use function Cake\Core\env; /** @@ -517,19 +516,4 @@ protected function generateNonce($secret = null, $expires = 300, $time = null) return base64_encode($nonceValue); } - - /** - * Asserts that a string matches a given regular expression. - * - * @param string $pattern Regex pattern - * @param string $string String to test - * @param string $message Message - * @return void - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @codeCoverageIgnore - */ - public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void - { - static::assertThat($string, new RegularExpression($pattern), $message); - } } diff --git a/tests/TestCase/Authenticator/JwtAuthenticatorTest.php b/tests/TestCase/Authenticator/JwtAuthenticatorTest.php index 05e616ff..155d4100 100644 --- a/tests/TestCase/Authenticator/JwtAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/JwtAuthenticatorTest.php @@ -183,7 +183,7 @@ public function testAuthenticateInvalidPayloadNotAnObject() ->setConstructorArgs([ $this->identifiers, ]) - ->setMethods([ + ->onlyMethods([ 'getPayLoad', ]) ->getMock(); @@ -214,7 +214,7 @@ public function testAuthenticateInvalidPayloadEmpty() ->setConstructorArgs([ $this->identifiers, ]) - ->setMethods([ + ->onlyMethods([ 'getPayLoad', ]) ->getMock(); diff --git a/tests/TestCase/Authenticator/SessionAuthenticatorTest.php b/tests/TestCase/Authenticator/SessionAuthenticatorTest.php index 541af00e..f13fa7db 100644 --- a/tests/TestCase/Authenticator/SessionAuthenticatorTest.php +++ b/tests/TestCase/Authenticator/SessionAuthenticatorTest.php @@ -57,7 +57,7 @@ public function setUp(): void } $this->sessionMock = $this->getMockBuilder($class) ->disableOriginalConstructor() - ->setMethods(['read', 'write', 'delete', 'renew', 'check']) + ->onlyMethods(['read', 'write', 'delete', 'renew', 'check']) ->getMock(); } @@ -183,7 +183,9 @@ public function testPersistIdentity() $this->sessionMock ->expects($this->exactly(2)) ->method('check') - ->withConsecutive(['Auth'], ['Auth']) + ->with( + ...self::withConsecutive(['Auth'], ['Auth']) + ) ->willReturnOnConsecutiveCalls(false, true); $this->sessionMock @@ -261,7 +263,9 @@ public function testImpersonate() $this->sessionMock ->expects($this->exactly(2)) ->method('write') - ->withConsecutive(['AuthImpersonate', $impersonator], ['Auth', $impersonated]); + ->with( + ...self::withConsecutive(['AuthImpersonate', $impersonator], ['Auth', $impersonated]) + ); $result = $authenticator->impersonate($request, $response, $impersonator, $impersonated); diff --git a/tests/TestCase/Identifier/Resolver/ResolverAwareTraitTest.php b/tests/TestCase/Identifier/Resolver/ResolverAwareTraitTest.php index f4a84dd0..050bd27b 100644 --- a/tests/TestCase/Identifier/Resolver/ResolverAwareTraitTest.php +++ b/tests/TestCase/Identifier/Resolver/ResolverAwareTraitTest.php @@ -26,7 +26,7 @@ class ResolverAwareTraitTest extends TestCase public function testBuildResolverFromClassName() { $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->setMethods(['getConfig']) + ->addMethods(['getConfig']) ->getMockForTrait(); $object->expects($this->once()) @@ -40,7 +40,7 @@ public function testBuildResolverFromClassName() public function testBuildResolverFromArray() { $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->setMethods(['getConfig']) + ->addMethods(['getConfig']) ->getMockForTrait(); $object->expects($this->once()) @@ -58,7 +58,7 @@ public function testBuildResolverInvalid() $this->expectException('RuntimeException'); $this->expectExceptionMessage('Resolver must implement `Authentication\Identifier\Resolver\ResolverInterface`.'); $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->setMethods(['getConfig']) + ->addMethods(['getConfig']) ->getMockForTrait(); $object->expects($this->once()) @@ -73,7 +73,7 @@ public function testBuildResolverMissing() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Resolver class `Missing` does not exist.'); $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->setMethods(['getConfig']) + ->addMethods(['getConfig']) ->getMockForTrait(); $object->expects($this->once()) @@ -88,7 +88,7 @@ public function testBuildResolverMissingClassNameOption() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Option `className` is not present.'); $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->setMethods(['getConfig']) + ->addMethods(['getConfig']) ->getMockForTrait(); $object->expects($this->once()) @@ -103,7 +103,7 @@ public function testGetResolverNotSet() $this->expectException('RuntimeException'); $this->expectExceptionMessage('Resolver has not been set.'); $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->setMethods(['getConfig']) + ->addMethods(['getConfig']) ->getMockForTrait(); $object->expects($this->once()) @@ -116,7 +116,7 @@ public function testGetResolverNotSet() public function testSetResolver() { $object = $this->getMockBuilder(ResolverAwareTrait::class) - ->setMethods(['getConfig']) + ->addMethods(['getConfig']) ->getMockForTrait(); $resolver = $this->createMock(ResolverInterface::class); diff --git a/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php b/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php index 82efd2ee..b4de8f13 100644 --- a/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php +++ b/tests/TestCase/Middleware/AuthenticationMiddlewareTest.php @@ -117,7 +117,7 @@ public function testApplicationAuthenticationRequestResponse() $application = $this->getMockBuilder(Application::class) ->disableOriginalConstructor() - ->setMethods(['getAuthenticationService', 'middleware']) + ->onlyMethods(['getAuthenticationService', 'middleware']) ->getMock(); $application->expects($this->once())