|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\Test\Module\oidc\integration\Factories; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 8 | +use PHPUnit\Framework\Attributes\UsesClass; |
| 9 | +use PHPUnit\Framework\MockObject\MockObject; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | +use SimpleSAML\Module\oidc\Bridges\SspBridge; |
| 12 | +use SimpleSAML\Module\oidc\Factories\FormFactory; |
| 13 | +use SimpleSAML\Module\oidc\Forms\ClientForm; |
| 14 | +use SimpleSAML\Module\oidc\Forms\Controls\CsrfProtection; |
| 15 | +use SimpleSAML\Module\oidc\ModuleConfig; |
| 16 | + |
| 17 | +#[CoversClass(FormFactory::class)] |
| 18 | +#[UsesClass(ClientForm::class)] |
| 19 | +class FormFactoryTest extends TestCase |
| 20 | +{ |
| 21 | + protected MockObject $moduleConfigMock; |
| 22 | + protected MockObject $csrfProtectionMock; |
| 23 | + protected MockObject $sspBridgeMock; |
| 24 | + |
| 25 | + protected function setUp(): void |
| 26 | + { |
| 27 | + $this->moduleConfigMock = $this->createMock(ModuleConfig::class); |
| 28 | + $this->csrfProtectionMock = $this->createMock(CsrfProtection::class); |
| 29 | + $this->sspBridgeMock = $this->createMock(SspBridge::class); |
| 30 | + } |
| 31 | + |
| 32 | + protected function sut( |
| 33 | + ?ModuleConfig $moduleConfig = null, |
| 34 | + ?CsrfProtection $csrfProtection = null, |
| 35 | + ?SspBridge $sspBridge = null, |
| 36 | + ): FormFactory { |
| 37 | + $moduleConfig ??= $this->moduleConfigMock; |
| 38 | + $csrfProtection ??= $this->csrfProtectionMock; |
| 39 | + $sspBridge ??= $this->sspBridgeMock; |
| 40 | + |
| 41 | + return new FormFactory( |
| 42 | + $moduleConfig, |
| 43 | + $csrfProtection, |
| 44 | + $sspBridge, |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + public function testCanConstruct(): void |
| 49 | + { |
| 50 | + $this->assertInstanceOf(FormFactory::class, $this->sut()); |
| 51 | + } |
| 52 | + |
| 53 | + public function testCanBuildClientForm(): void |
| 54 | + { |
| 55 | + $this->assertInstanceOf( |
| 56 | + ClientForm::class, |
| 57 | + $this->sut()->build(ClientForm::class), |
| 58 | + ); |
| 59 | + } |
| 60 | +} |
0 commit comments