|
5 | 5 | use FediE2EE\PKD\Extensions\AuxDataTypes\AgeV1; |
6 | 6 | use FediE2EE\PKD\Extensions\AuxDataTypes\SshV2; |
7 | 7 | use FediE2EE\PKD\Extensions\ExtensionException; |
| 8 | +use FediE2EE\PKD\Extensions\ExtensionInterface; |
8 | 9 | use FediE2EE\PKD\Extensions\Registry; |
9 | 10 | use PHPUnit\Framework\Attributes\CoversClass; |
10 | 11 | use PHPUnit\Framework\TestCase; |
11 | 12 |
|
12 | 13 | #[CoversClass(Registry::class)] |
13 | 14 | class RegistryTest extends TestCase |
14 | 15 | { |
| 16 | + /** |
| 17 | + * @throws ExtensionException |
| 18 | + */ |
| 19 | + public function testGet(): void |
| 20 | + { |
| 21 | + $registry = new Registry(); |
| 22 | + $got = $registry->get('age', [AgeV1::AUX_DATA_TYPE]); |
| 23 | + $this->assertInstanceOf(AgeV1::class, $got); |
| 24 | + |
| 25 | + $got = $registry->get('ssh', [SshV2::AUX_DATA_TYPE]); |
| 26 | + $this->assertInstanceOf(SshV2::class, $got); |
| 27 | + |
| 28 | + $this->expectException(ExtensionException::class); |
| 29 | + $registry->get('ssh', [AgeV1::AUX_DATA_TYPE]); |
| 30 | + } |
| 31 | + |
| 32 | + public function testAddExtension(): void |
| 33 | + { |
| 34 | + $registry = new Registry(); |
| 35 | + $custom = new class implements ExtensionInterface { |
| 36 | + public function getAuxDataType(): string |
| 37 | + { |
| 38 | + return 'foo-v1'; |
| 39 | + } |
| 40 | + |
| 41 | + public function getRejectionReason(): string |
| 42 | + { |
| 43 | + return ''; |
| 44 | + } |
| 45 | + |
| 46 | + public function isValid(string $auxData): bool |
| 47 | + { |
| 48 | + return true; |
| 49 | + } |
| 50 | + }; |
| 51 | + $registry->addAuxDataType($custom, 'foo'); |
| 52 | + $got = $registry->get('foo', ['foo-v1']); |
| 53 | + $this->assertSame('foo-v1', $got->getAuxDataType()); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @throws ExtensionException |
| 58 | + */ |
15 | 59 | public function testAliasBehavior(): void |
16 | 60 | { |
17 | 61 | $registry = new Registry(); |
|
0 commit comments