Skip to content

Commit

Permalink
Add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cicnavi committed Nov 12, 2024
1 parent ec9805b commit 849e420
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/src/Factories/AlgorithmManagerFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\OpenID\Factories;

use Jose\Component\Signature\Algorithm\SignatureAlgorithm;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use SimpleSAML\OpenID\Algorithms\AlgorithmManager;
use SimpleSAML\OpenID\Algorithms\SignatureAlgorithmBag;
use SimpleSAML\OpenID\Factories\AlgorithmManagerFactory;
use SimpleSAML\OpenID\SupportedAlgorithms;

#[CoversClass(AlgorithmManagerFactory::class)]
class AlgorithmManagerFactoryTest extends TestCase
{
protected MockObject $supportedAlgorithmsMock;
protected MockObject $signatureAlgorithmBagMock;
protected MockObject $signatureAlgorithmMock;

protected function setUp(): void
{
$this->supportedAlgorithmsMock = $this->createMock(SupportedAlgorithms::class);
$this->signatureAlgorithmBagMock = $this->createMock(SignatureAlgorithmBag::class);
$this->signatureAlgorithmMock = $this->createMock(SignatureAlgorithm::class);

$this->supportedAlgorithmsMock->method('getSignatureAlgorithmBag')
->willReturn($this->signatureAlgorithmBagMock);
$this->signatureAlgorithmBagMock->method('getAllInstances')
->willReturn([
$this->signatureAlgorithmMock,
]);
}

protected function sut(): AlgorithmManagerFactory
{
return new AlgorithmManagerFactory();
}

public function testCanCreateInstance(): void
{
$this->assertInstanceOf(
AlgorithmManagerFactory::class,
$this->sut(),
);
}

public function testCanBuild(): void
{
$this->assertInstanceOf(
AlgorithmManager::class,
$this->sut()->build($this->supportedAlgorithmsMock),
);
}
}
46 changes: 46 additions & 0 deletions tests/src/Factories/CacheDecoratorFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\OpenID\Factories;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\SimpleCache\CacheInterface;
use SimpleSAML\OpenID\Decorators\CacheDecorator;
use SimpleSAML\OpenID\Factories\CacheDecoratorFactory;

#[CoversClass(CacheDecoratorFactory::class)]
#[UsesClass(CacheDecorator::class)]
class CacheDecoratorFactoryTest extends TestCase
{
protected MockObject $cacheInterfaceMock;

protected function setUp(): void
{
$this->cacheInterfaceMock = $this->createMock(CacheInterface::class);
}

protected function sut(): CacheDecoratorFactory
{
return new CacheDecoratorFactory();
}

public function testCacnCreateInstance(): void
{
$this->assertInstanceOf(
CacheDecoratorFactory::class,
$this->sut(),
);
}

public function testCanBuild(): void
{
$this->assertInstanceOf(
CacheDecorator::class,
$this->sut()->build($this->cacheInterfaceMock),
);
}
}
42 changes: 42 additions & 0 deletions tests/src/Factories/DateIntervalDecoratorFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\OpenID\Factories;

use DateInterval;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\OpenID\Decorators\DateIntervalDecorator;
use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory;

#[CoversClass(DateIntervalDecoratorFactory::class)]
#[UsesClass(DateIntervalDecorator::class)]
class DateIntervalDecoratorFactoryTest extends TestCase
{
protected DateInterval $dateInterval;

protected function setUp(): void
{
$this->dateInterval = new DateInterval('P1D');
}

protected function sut(): DateIntervalDecoratorFactory
{
return new DateIntervalDecoratorFactory();
}

public function testCanCreateInstance(): void
{
$this->assertInstanceOf(DateIntervalDecoratorFactory::class, $this->sut());
}

public function testCanBuild(): void
{
$this->assertInstanceOf(
DateIntervalDecorator::class,
$this->sut()->build($this->dateInterval),
);
}
}
43 changes: 43 additions & 0 deletions tests/src/Factories/HttpClientDecoratorFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\OpenID\Factories;

use GuzzleHttp\Client;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use SimpleSAML\OpenID\Decorators\HttpClientDecorator;
use SimpleSAML\OpenID\Factories\HttpClientDecoratorFactory;

#[CoversClass(HttpClientDecoratorFactory::class)]
#[UsesClass(HttpClientDecorator::class)]
class HttpClientDecoratorFactoryTest extends TestCase
{
protected MockObject $clientMock;

protected function setUp(): void
{
$this->clientMock = $this->createMock(Client::class);
}

protected function sut(): HttpClientDecoratorFactory
{
return new HttpClientDecoratorFactory();
}

public function testCanCreateInstance(): void
{
$this->assertInstanceOf(HttpClientDecoratorFactory::class, $this->sut());
}

public function testCanBuild(): void
{
$this->assertInstanceOf(
HttpClientDecorator::class,
$this->sut()->build($this->clientMock),
);
}
}
58 changes: 58 additions & 0 deletions tests/src/Factories/JwsSerializerManagerFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\Test\OpenID\Factories;

use Jose\Component\Signature\Serializer\JWSSerializer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use SimpleSAML\OpenID\Factories\JwsSerializerManagerFactory;
use SimpleSAML\OpenID\Serializers\JwsSerializerBag;
use SimpleSAML\OpenID\Serializers\JwsSerializerManager;
use SimpleSAML\OpenID\SupportedSerializers;

#[CoversClass(JwsSerializerManagerFactory::class)]
#[UsesClass(JwsSerializerManager::class)]
class JwsSerializerManagerFactoryTest extends TestCase
{
protected MockObject $supportedSerializersMock;
protected MockObject $jwsSerializerBagMock;
protected MockObject $jwsSerializerMock;

protected function setUp(): void
{
$this->supportedSerializersMock = $this->createMock(SupportedSerializers::class);
$this->jwsSerializerBagMock = $this->createMock(JwsSerializerBag::class);
$this->jwsSerializerMock = $this->createMock(JwsSerializer::class);

$this->supportedSerializersMock->method('getJwsSerializerBag')
->willReturn($this->jwsSerializerBagMock);

$this->jwsSerializerBagMock->method('getAllInstances')
->willReturn([$this->jwsSerializerMock]);
}

protected function sut(): JwsSerializerManagerFactory
{
return new JwsSerializerManagerFactory();
}

public function testCanCreateInstance(): void
{
$this->assertInstanceOf(
JwsSerializerManagerFactory::class,
$this->sut(),
);
}

public function testCanBuild(): void
{
$this->assertInstanceOf(
JwsSerializerManager::class,
$this->sut()->build($this->supportedSerializersMock),
);
}
}

0 comments on commit 849e420

Please sign in to comment.