Skip to content

Commit e618977

Browse files
authored
Merge pull request #3 from cspray/bug/add-sources-to-store
Add sources to secrets parameter store
2 parents cd9e547 + 1bed547 commit e618977

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/SecretsParameterStoreFactory.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ public function createParameterStore(string $identifier) : ParameterStore {
2525
throw InvalidParameterStoreIdentifier::fromIdentifierNotSecretsParameterStore($identifier);
2626
}
2727
$store = new SecretsParameterStore();
28+
foreach ($this->sources as $source) {
29+
$store->addSource($source);
30+
}
2831

2932
return $store;
3033
}
31-
}
34+
35+
}

tests/SecretsParameterStoreFactoryTest.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,24 @@
22

33
namespace Cspray\AnnotatedContainer\Secrets\Test;
44

5+
use Cspray\AnnotatedContainer\Secrets\ArrayValueProvider;
56
use Cspray\AnnotatedContainer\Secrets\Exception\InvalidParameterStoreIdentifier;
67
use Cspray\AnnotatedContainer\Secrets\Exception\NoSourcesProvided;
78
use Cspray\AnnotatedContainer\Secrets\SecretsParameterStore;
89
use Cspray\AnnotatedContainer\Secrets\SecretsParameterStoreFactory;
10+
use Cspray\AnnotatedContainer\Secrets\SingleValueProviderSource;
911
use Cspray\AnnotatedContainer\Secrets\Source;
1012
use PHPUnit\Framework\Attributes\CoversClass;
1113
use PHPUnit\Framework\TestCase;
14+
use function Cspray\Typiphy\stringType;
1215

1316
#[
1417
CoversClass(SecretsParameterStoreFactory::class),
1518
CoversClass(SecretsParameterStore::class),
1619
CoversClass(InvalidParameterStoreIdentifier::class),
17-
CoversClass(NoSourcesProvided::class)
20+
CoversClass(NoSourcesProvided::class),
21+
CoversClass(ArrayValueProvider::class),
22+
CoversClass(SingleValueProviderSource::class),
1823
]
1924
final class SecretsParameterStoreFactoryTest extends TestCase {
2025

@@ -46,4 +51,14 @@ public function testFactoryConstructorGivenNoSourcesThrowsException() : void {
4651
new SecretsParameterStoreFactory([]);
4752
}
4853

49-
}
54+
public function testSourcesAreProvidedToSecretsParameterStore() : void {
55+
$subject = new SecretsParameterStoreFactory(
56+
[new SingleValueProviderSource('source', new ArrayValueProvider(['foo' => 'bar']))]
57+
);
58+
59+
$store = $subject->createParameterStore(SecretsParameterStore::class);
60+
61+
self::assertSame('bar', $store->fetch(stringType(), 'source.foo'));
62+
}
63+
64+
}

0 commit comments

Comments
 (0)