getAlgorithmClasses()); } /** * @test * * @throws Exception * @throws ExpectationFailedException */ public function itReturnsTheAvailableAlgorithms(): void { $algorithmProvider = new AlgorithmProvider(self::ALL_ALGORITHMS); foreach ($algorithmProvider->getAvailableAlgorithms() as $algorithm) { static::assertContains(get_class($algorithm), self::ALL_ALGORITHMS); } } /** * @test * * @throws ExpectationFailedException * @throws \Exception */ public function itAllowsNonExistingClasses(): void { $nonExistingClassName = 'NonExistingClass'.bin2hex(random_bytes(31)); $algorithmProvider = new AlgorithmProvider([$nonExistingClassName]); static::assertSame([$nonExistingClassName], $algorithmProvider->getAlgorithmClasses()); static::assertSame([], $algorithmProvider->getAvailableAlgorithms()); } /** * @test * * @throws ExpectationFailedException */ public function itCanHandleClassesWithExceptions(): void { $test = [$this->createAlgorithmClassWithExceptionMock()]; $algorithmProvider = new AlgorithmProvider($test); static::assertSame($test, $algorithmProvider->getAlgorithmClasses()); static::assertSame([], $algorithmProvider->getAvailableAlgorithms()); } private function createAlgorithmClassWithExceptionMock(): string { $mockClass = new class() implements Algorithm\SignatureAlgorithm { /** @var bool */ private static $throw; public function __construct() { if (null === self::$throw) { self::$throw = true; return; } throw new BadFunctionCallException('should not be called'); } public function name(): string { throw new BadFunctionCallException('should not be called'); } public function allowedKeyTypes(): array { throw new BadFunctionCallException('should not be called'); } public function sign(JWK $key, string $input): string { throw new BadFunctionCallException('should not be called'); } public function verify(JWK $key, string $input, string $signature): bool { throw new BadFunctionCallException('should not be called'); } }; return get_class($mockClass); } }