Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/tmp
/tools
/vendor
.phpunit.result.cache
.phpunit.cache

# OS generated files #
######################
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
Expand Down
56 changes: 28 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<exclude>
<file>src/Identifier/Ldap/ExtensionAdapter.php</file>
</exclude>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
processIsolation="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
bootstrap="./tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd">

<php>
<ini name="memory_limit" value="-1"/>
<env name="FIXTURE_SCHEMA_METADATA" value="./vendor/cakephp/cakephp/tests/schema.php"/>
</php>
<testsuites>
<testsuite name="authentication">
<directory>tests/TestCase/</directory>
</testsuite>
</testsuites>

<testsuites>
<testsuite name="authentication">
<directory>tests/TestCase/</directory>
</testsuite>
</testsuites>
<extensions>
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>

<extensions>
<extension class="Cake\TestSuite\Fixture\PHPUnitExtension"/>
</extensions>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
<exclude>
<file>src/Identifier/Ldap/ExtensionAdapter.php</file>
</exclude>
</source>

<php>
<ini name="memory_limit" value="-1"/>
<env name="FIXTURE_SCHEMA_METADATA" value="./vendor/cakephp/cakephp/tests/schema.php"/>
</php>
</phpunit>
9 changes: 6 additions & 3 deletions src/UrlChecker/UrlCheckerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ 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'],
UrlCheckerInterface::class
));
}

return $checker;
/** @var \Authentication\UrlChecker\UrlCheckerInterface $obj */
$obj = new $className();

return $obj;
}
}
16 changes: 0 additions & 16 deletions tests/TestCase/Authenticator/HttpDigestAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions tests/TestCase/Authenticator/JwtAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function testAuthenticateInvalidPayloadNotAnObject()
->setConstructorArgs([
$this->identifiers,
])
->setMethods([
->onlyMethods([
'getPayLoad',
])
->getMock();
Expand Down Expand Up @@ -214,7 +214,7 @@ public function testAuthenticateInvalidPayloadEmpty()
->setConstructorArgs([
$this->identifiers,
])
->setMethods([
->onlyMethods([
'getPayLoad',
])
->getMock();
Expand Down
10 changes: 7 additions & 3 deletions tests/TestCase/Authenticator/SessionAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
14 changes: 7 additions & 7 deletions tests/TestCase/Identifier/Resolver/ResolverAwareTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -40,7 +40,7 @@ public function testBuildResolverFromClassName()
public function testBuildResolverFromArray()
{
$object = $this->getMockBuilder(ResolverAwareTrait::class)
->setMethods(['getConfig'])
->addMethods(['getConfig'])
->getMockForTrait();

$object->expects($this->once())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Middleware/AuthenticationMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function testApplicationAuthenticationRequestResponse()

$application = $this->getMockBuilder(Application::class)
->disableOriginalConstructor()
->setMethods(['getAuthenticationService', 'middleware'])
->onlyMethods(['getAuthenticationService', 'middleware'])
->getMock();

$application->expects($this->once())
Expand Down