Skip to content

Commit ddb3c47

Browse files
committed
Fix addAuxDataType()
1 parent 9160191 commit ddb3c47

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/Registry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function addAuxDataType(ExtensionInterface $extension, ?string $alias = n
4444
throw new ExtensionException('Extension already registered');
4545
}
4646
}
47-
$this->auxDataTypes[$type] = $alias;
47+
$this->auxDataTypes[$type] = $extension;
4848
if (!is_null($alias)) {
4949
$this->aliases[$alias] = $type;
5050
}

tests/RegistryTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,57 @@
55
use FediE2EE\PKD\Extensions\AuxDataTypes\AgeV1;
66
use FediE2EE\PKD\Extensions\AuxDataTypes\SshV2;
77
use FediE2EE\PKD\Extensions\ExtensionException;
8+
use FediE2EE\PKD\Extensions\ExtensionInterface;
89
use FediE2EE\PKD\Extensions\Registry;
910
use PHPUnit\Framework\Attributes\CoversClass;
1011
use PHPUnit\Framework\TestCase;
1112

1213
#[CoversClass(Registry::class)]
1314
class RegistryTest extends TestCase
1415
{
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+
*/
1559
public function testAliasBehavior(): void
1660
{
1761
$registry = new Registry();

0 commit comments

Comments
 (0)