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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"yokai/dependency-injection": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^10.0|12.0",
"symfony/yaml": "^6.4|^7.4|^8.0",
"phpstan/phpstan": "^2.1",
"symplify/easy-coding-standard": "^13.0"
Expand Down
13 changes: 7 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
colors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnPhpunitDeprecations="true"
bootstrap="vendor/autoload.php">
<php>
<server name="KERNEL_CLASS" value="Yokai\SecurityTokenBundle\Tests\Kernel"/>
Expand All @@ -18,9 +19,9 @@
<directory>./tests</directory>
</testsuite>
</testsuites>
<coverage>
<source>
<include>
<directory>./src</directory>
</include>
</coverage>
</source>
</phpunit>
5 changes: 3 additions & 2 deletions tests/Command/ArchiveTokenCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected function setUp(): void
protected function tearDown(): void
{
parent::tearDown();
\restore_exception_handler();

unset(
$this->archivist,
Expand All @@ -65,7 +66,7 @@ protected function runCommand(Command $command, array $options = []): string
return $tester->getDisplay();
}

public function testIt_archive_every_token_when_run_without_options_with_confirmation(): void
public function test_it_archive_every_token_when_run_without_options_with_confirmation(): void
{
$command = $this->command();

Expand All @@ -79,7 +80,7 @@ public function testIt_archive_every_token_when_run_without_options_with_confirm
self::assertStringContainsString('Successfully archived 10 security token(s).', $output);
}

public function testIt_archive_partial_tokens_when_run_with_options(): void
public function test_it_archive_partial_tokens_when_run_with_options(): void
{
$command = $this->command();

Expand Down
13 changes: 6 additions & 7 deletions tests/DependencyInjection/DependencyInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Generator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\Config\FileLocator;
Expand Down Expand Up @@ -85,10 +86,8 @@ protected function setUp(): void
$bundle->build($this->container);
}

/**
* @dataProvider configurationProvider
*/
public function testIt_parse_configuration_as_expected(string $resource, array $tokens, array $aliases): void
#[DataProvider('configurationProvider')]
public function test_it_parse_configuration_as_expected(string $resource, array $tokens, array $aliases): void
{
// for test purpose, all services are switched to public
$this->container->addCompilerPass(new class implements CompilerPassInterface {
Expand Down Expand Up @@ -144,7 +143,7 @@ protected function loadConfiguration(string $resource): void
$loader->load($resource);
}

public function configurationProvider(): Generator
public static function configurationProvider(): Generator
{
$defaultAliases = [
'yokai_security_token.information_guesser' => 'yokai_security_token.default_information_guesser',
Expand All @@ -154,7 +153,7 @@ public function configurationProvider(): Generator
'yokai_security_token.archivist' => 'yokai_security_token.delete_archivist',
];

foreach ($this->formatProvider() as $format) {
foreach (self::formatProvider() as $format) {
$format = $format[0];

yield $format . ' - none' => [
Expand Down Expand Up @@ -205,7 +204,7 @@ public function configurationProvider(): Generator
}
}

public function formatProvider(): Generator
public static function formatProvider(): Generator
{
yield ['yml'];
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Entity/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
final class TokenTest extends TestCase
{
public function testIt_allow_limited_usage_token(): void
public function test_it_allow_limited_usage_token(): void
{
$token = new Token('string', 'jdoe', 'unique-token', 'reset-password', '+1 day', '+1 month', 2);
self::assertFalse($token->isConsumed());
Expand All @@ -29,7 +29,7 @@ public function testIt_allow_limited_usage_token(): void
self::assertSame([2], $token->getLastUsage()->getInformation());
}

public function testIt_allow_unlimited_usage_token(): void
public function test_it_allow_unlimited_usage_token(): void
{
$token = new Token('string', 'jdoe', 'unique-token', 'reset-password', '+1 day', '+1 month', 0);
self::assertFalse($token->isConsumed());
Expand Down
30 changes: 21 additions & 9 deletions tests/Factory/TokenFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,33 @@ protected function factory(array $configuration): TokenFactory
);
}

public function testIt_create_token_according_to_configuration(): void
public function test_it_create_token_according_to_configuration(): void
{
$generator1 = $this->createMock(TokenGeneratorInterface::class);
$generator1->method('generate')
->will($this->onConsecutiveCalls('existtoken-1', 'uniquetoken-1'));
$generator1->expects($matcher = $this->atMost(2))
->method('generate')
->willReturnCallback(fn() => match ($matcher->numberOfInvocations()) {
1 => 'existtoken-1',
2 => 'uniquetoken-1',
});
$user1 = 'user-1';

$generator2 = $this->createMock(TokenGeneratorInterface::class);
$generator2->method('generate')
->will($this->onConsecutiveCalls('existtoken-2', 'uniquetoken-2'));
$generator2->expects($matcher = $this->atMost(2))
->method('generate')
->willReturnCallback(fn() => match ($matcher->numberOfInvocations()) {
1 => 'existtoken-2',
2 => 'uniquetoken-2',
});
$user2 = 'user-2';

$generator3 = $this->createMock(TokenGeneratorInterface::class);
$generator3->method('generate')
->will($this->onConsecutiveCalls('existtoken-3', 'uniquetoken-3'));
$generator3->expects($matcher = $this->atMost(2))
->method('generate')
->willReturnCallback(fn() => match ($matcher->numberOfInvocations()) {
1 => 'existtoken-3',
2 => 'uniquetoken-3',
});
$user3 = 'user-3';
$token3FromRepository = new Token(
'string',
Expand Down Expand Up @@ -111,7 +123,7 @@ public function testIt_create_token_according_to_configuration(): void

$this->userManager->expects(self::exactly(3))
->method('getClass')
->with(self::isType('string'))
->with(\method_exists(self::class, 'isString') ? self::isString() : self::isType('string'))
->willReturnMap([
[$user1, 'string'],
[$user2, 'string'],
Expand All @@ -120,7 +132,7 @@ public function testIt_create_token_according_to_configuration(): void

$this->userManager->expects(self::exactly(3))
->method('getId')
->with(self::isType('string'))
->with(\method_exists(self::class, 'isString') ? self::isString() : self::isType('string'))
->willReturnMap([
[$user1, 'u1'],
[$user2, 'u2'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Generator/OpenSslTokenGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
final class OpenSslTokenGeneratorTest extends TestCase
{
public function testIt_generate_unique_token(): void
public function test_it_generate_unique_token(): void
{
$generator = new OpenSslTokenGenerator();

Expand Down
4 changes: 2 additions & 2 deletions tests/InformationGuesser/InformationGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function guesser(RequestStack $requestStack): InformationGuesser
return new InformationGuesser($requestStack);
}

public function testIt_return_empty_array_if_no_master_request(): void
public function test_it_return_empty_array_if_no_master_request(): void
{
$requestStack = new RequestStack();

Expand All @@ -30,7 +30,7 @@ public function testIt_return_empty_array_if_no_master_request(): void
self::assertSame([], $info);
}

public function testIt_return_array_with_ip_from_master_request(): void
public function test_it_return_array_with_ip_from_master_request(): void
{
$requestStack = new RequestStack();
$requestStack->push(new Request([], [], [], [], [], ['REMOTE_ADDR' => '88.88.88.88']));
Expand Down
26 changes: 16 additions & 10 deletions tests/Manager/ChainUserManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ private function entityManager(): UserManagerInterface
$manager->method('getId')
->willReturn('increment');
$manager->method('get')
->with(UserEntity::class, self::isType('string'))
->with(
UserEntity::class,
\method_exists(self::class, 'isString') ? self::isString() : self::isType('string'),
)
->willReturn(new UserEntity());

return $manager;
Expand All @@ -66,13 +69,16 @@ private function documentManager(): UserManagerInterface
$manager->method('getId')
->willReturn('uuid');
$manager->method('get')
->with(UserDocument::class, self::isType('string'))
->with(
UserDocument::class,
\method_exists(self::class, 'isString') ? self::isString() : self::isType('string'),
)
->willReturn(new UserDocument());

return $manager;
}

public function testIt_supports_same_classes_as_managers(): void
public function test_it_supports_same_classes_as_managers(): void
{
$entityManager = $this->entityManager();
$documentManager = $this->documentManager();
Expand All @@ -97,7 +103,7 @@ public function testIt_supports_same_classes_as_managers(): void
self::assertFalse($userEmptyManager->supportsClass($document));
}

public function testIt_supports_same_users_as_managers(): void
public function test_it_supports_same_users_as_managers(): void
{
$entityManager = $this->entityManager();
$documentManager = $this->documentManager();
Expand All @@ -122,7 +128,7 @@ public function testIt_supports_same_users_as_managers(): void
self::assertFalse($userEmptyManager->supportsUser($document));
}

public function testIt_get_user_class_from_appropriate_manager(): void
public function test_it_get_user_class_from_appropriate_manager(): void
{
$entity = new UserEntity();
$document = new UserDocument();
Expand All @@ -132,7 +138,7 @@ public function testIt_get_user_class_from_appropriate_manager(): void
self::assertSame(UserDocument::class, $userCompleteManager->getClass($document));
}

public function testIt_get_user_id_from_appropriate_manager()
public function test_it_get_user_id_from_appropriate_manager()
{
$entity = new UserEntity();
$document = new UserDocument();
Expand All @@ -142,7 +148,7 @@ public function testIt_get_user_id_from_appropriate_manager()
self::assertSame('uuid', $userCompleteManager->getId($document));
}

public function testIt_get_user_from_appropriate_manager(): void
public function test_it_get_user_from_appropriate_manager(): void
{
$userCompleteManager = $this->manager([$this->entityManager(), $this->documentManager()]);
self::assertInstanceOf(UserEntity::class, $userCompleteManager->get(UserEntity::class, '9999'));
Expand All @@ -152,23 +158,23 @@ public function testIt_get_user_from_appropriate_manager(): void
);
}

public function testIt_throw_exception_on_get_user_class_without_appropriate_manager(): void
public function test_it_throw_exception_on_get_user_class_without_appropriate_manager(): void
{
$this->expectException(InvalidArgumentException::class);

$userCompleteManager = $this->manager([$this->entityManager(), $this->documentManager()]);
$userCompleteManager->getClass(new \stdClass());
}

public function testIt_throw_exception_on_get_user_id_without_appropriate_manager(): void
public function test_it_throw_exception_on_get_user_id_without_appropriate_manager(): void
{
$this->expectException(InvalidArgumentException::class);

$userCompleteManager = $this->manager([$this->entityManager(), $this->documentManager()]);
$userCompleteManager->getId(new \stdClass());
}

public function testIt_throw_exception_on_get_user_without_appropriate_manager(): void
public function test_it_throw_exception_on_get_user_without_appropriate_manager(): void
{
$this->expectException(InvalidArgumentException::class);

Expand Down
10 changes: 5 additions & 5 deletions tests/Manager/DoctrineUserManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getId()
};
}

public function testIt_supports_doctrine_entities(): void
public function test_it_supports_doctrine_entities(): void
{
$user = $this->user('jdoe');

Expand All @@ -85,7 +85,7 @@ public function testIt_supports_doctrine_entities(): void
self::assertTrue($manager->supportsUser($user));
}

public function testIt_do_not_supports_objects_out_of_doctrine(): void
public function test_it_do_not_supports_objects_out_of_doctrine(): void
{
$user = $this->user('jdoe');

Expand All @@ -98,7 +98,7 @@ public function testIt_do_not_supports_objects_out_of_doctrine(): void
self::assertFalse($manager->supportsUser($user));
}

public function testIt_get_user(): void
public function test_it_get_user(): void
{
$expected = $this->user('jdoe');

Expand All @@ -117,7 +117,7 @@ public function testIt_get_user(): void
self::assertSame($expected, $user);
}

public function testIt_get_user_class(): void
public function test_it_get_user_class(): void
{
$expected = $this->user('jdoe');

Expand All @@ -126,7 +126,7 @@ public function testIt_get_user_class(): void
self::assertSame(\get_class($expected), $class);
}

public function testIt_get_user_id(): void
public function test_it_get_user_id(): void
{
$expected = $this->user('jdoe');

Expand Down
Loading
Loading