Skip to content

Commit 78e32f4

Browse files
committed
style fix
1 parent c81e203 commit 78e32f4

3 files changed

Lines changed: 132 additions & 43 deletions

File tree

psalm.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<directory name="src" />
1212
<ignoreFiles>
1313
<directory name="vendor" />
14-
<directory name="src/Core/Tests" />
15-
<file name="src/Bundle/SecretaryBundle/Test.php" />
14+
<directory name="**/vendor" />
15+
<directory name="**/Tests" />
1616
</ignoreFiles>
1717
</projectFiles>
1818

src/Adapter/AWS/SecretsManager/Tests/AWSSecretsManagerAdapterTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
declare(strict_types=1);
44

5+
/*
6+
* @author Aaron Scherer <aequasi@gmail.com>
7+
* @date 2019
8+
* @license https://opensource.org/licenses/MIT
9+
*/
10+
511
namespace Secretary\Tests;
612

713
use Aws\CommandInterface;
@@ -26,7 +32,7 @@ protected function setUp(): void
2632
{
2733
parent::setUp();
2834

29-
$this->client = \Mockery::mock(SecretsManagerClient::class);
35+
$this->client = \Mockery::mock(SecretsManagerClient::class);
3036
$this->adapter = new AWSSecretsManagerAdapter([]);
3137

3238
$reflection = new \ReflectionProperty(AWSSecretsManagerAdapter::class, 'client');
@@ -59,7 +65,7 @@ public function testGetSecretWithStringValue(): void
5965
public function testGetSecretWithJsonValue(): void
6066
{
6167
$jsonData = ['username' => 'admin', 'password' => 'secret123'];
62-
$result = new Result(['SecretString' => json_encode($jsonData)]);
68+
$result = new Result(['SecretString' => json_encode($jsonData)]);
6369

6470
$this->client
6571
->shouldReceive('getSecretValue')
@@ -78,7 +84,7 @@ public function testGetSecretThrowsSecretNotFoundException(): void
7884
{
7985
$this->expectException(SecretNotFoundException::class);
8086

81-
$command = \Mockery::mock(CommandInterface::class);
87+
$command = \Mockery::mock(CommandInterface::class);
8288
$exception = new SecretsManagerException(
8389
'Error',
8490
$command,
@@ -97,7 +103,7 @@ public function testGetSecretRethrowsOtherExceptions(): void
97103
{
98104
$this->expectException(SecretsManagerException::class);
99105

100-
$command = \Mockery::mock(CommandInterface::class);
106+
$command = \Mockery::mock(CommandInterface::class);
101107
$exception = new SecretsManagerException(
102108
'Access denied',
103109
$command,
@@ -119,7 +125,7 @@ public function testPutSecretUpdatesExisting(): void
119125
$this->client
120126
->shouldReceive('updateSecret')
121127
->with(\Mockery::on(function (array $opts) {
122-
return $opts['SecretId'] === 'my/key'
128+
return $opts['SecretId'] === 'my/key'
123129
&& $opts['SecretString'] === 'my-value';
124130
}))
125131
->once();
@@ -141,7 +147,7 @@ public function testPutSecretCreatesWhenUpdateFails(): void
141147
$this->client
142148
->shouldReceive('createSecret')
143149
->with(\Mockery::on(function (array $opts) {
144-
return $opts['Name'] === 'new/key'
150+
return $opts['Name'] === 'new/key'
145151
&& $opts['SecretString'] === 'new-value';
146152
}))
147153
->once();
@@ -153,7 +159,7 @@ public function testPutSecretCreatesWhenUpdateFails(): void
153159

154160
public function testPutSecretWithArrayValue(): void
155161
{
156-
$value = ['user' => 'admin', 'pass' => 'secret'];
162+
$value = ['user' => 'admin', 'pass' => 'secret'];
157163
$secret = new Secret('my/key', $value);
158164

159165
$this->client

src/Bundle/SecretaryBundle/Tests/SecretaryBundleTest.php

Lines changed: 117 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,135 @@
1010

1111
namespace Secretary\Tests;
1212

13+
use PHPUnit\Framework\Attributes\CoversClass;
14+
use PHPUnit\Framework\TestCase;
15+
use Secretary\Bundle\SecretaryBundle\DependencyInjection\SecretaryExtension;
16+
use Secretary\Bundle\SecretaryBundle\EnvVar\EnvVarProcessor;
1317
use Secretary\Bundle\SecretaryBundle\SecretaryBundle;
14-
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
15-
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
16-
use Symfony\Component\Config\Loader\LoaderInterface;
18+
use Secretary\Manager;
1719
use Symfony\Component\DependencyInjection\ContainerBuilder;
18-
use Symfony\Component\HttpKernel\Kernel;
1920

20-
class SecretaryBundleTest extends Kernel
21+
#[CoversClass(SecretaryBundle::class)]
22+
#[CoversClass(SecretaryExtension::class)]
23+
class SecretaryBundleTest extends TestCase
2124
{
22-
use MicroKernelTrait;
25+
public function testBundleRegistersExtension(): void
26+
{
27+
$bundle = new SecretaryBundle();
28+
29+
$this->assertInstanceOf(SecretaryBundle::class, $bundle);
30+
}
2331

24-
public const CONFIG_EXTS = '.{php,xml,yaml,yml}';
32+
public function testExtensionRegistersServices(): void
33+
{
34+
$container = new ContainerBuilder();
35+
$extension = new SecretaryExtension();
36+
37+
$extension->load([
38+
[
39+
'adapters' => [
40+
'default' => [
41+
'adapter' => 'Secretary\Adapter\AWS\SecretsManager\AWSSecretsManagerAdapter',
42+
'config' => [
43+
'region' => 'us-east-1',
44+
'version' => '2017-10-17',
45+
],
46+
'cache' => [
47+
'enabled' => false,
48+
],
49+
],
50+
],
51+
],
52+
], $container);
53+
54+
$this->assertTrue($container->has('secretary.adapter.default'));
55+
$this->assertTrue($container->has('secretary.manager.default'));
56+
$this->assertTrue($container->has('secretary'));
57+
$this->assertTrue($container->has(Manager::class));
58+
$this->assertTrue($container->has('secretary.env_var_processor'));
59+
}
2560

26-
/**
27-
* Returns an array of bundles to register.
28-
*
29-
* @return iterable|\Symfony\Component\HttpKernel\Bundle\BundleInterface An iterable of bundle instances
30-
*/
31-
public function registerBundles(): iterable
61+
public function testExtensionRegistersMultipleAdapters(): void
3262
{
33-
yield new FrameworkBundle();
34-
yield new SecretaryBundle();
63+
$container = new ContainerBuilder();
64+
$extension = new SecretaryExtension();
65+
66+
$extension->load([
67+
[
68+
'adapters' => [
69+
'aws' => [
70+
'adapter' => 'Secretary\Adapter\AWS\SecretsManager\AWSSecretsManagerAdapter',
71+
'config' => [
72+
'region' => 'us-east-1',
73+
'version' => '2017-10-17',
74+
],
75+
'cache' => [
76+
'enabled' => false,
77+
],
78+
],
79+
'default' => [
80+
'adapter' => 'Secretary\Adapter\Chain\ChainAdapter',
81+
'config' => [],
82+
'cache' => [
83+
'enabled' => false,
84+
],
85+
],
86+
],
87+
],
88+
], $container);
89+
90+
$this->assertTrue($container->has('secretary.adapter.aws'));
91+
$this->assertTrue($container->has('secretary.manager.aws'));
92+
$this->assertTrue($container->has('secretary.adapter.default'));
93+
$this->assertTrue($container->has('secretary.manager.default'));
94+
// 'default' adapter should be aliased to 'secretary'
95+
$this->assertTrue($container->has('secretary'));
3596
}
3697

37-
/**
38-
* Add or import routes into your application.
39-
*
40-
* $routes->import('config/routing.yml');
41-
* $routes->add('/admin', 'App\Controller\AdminController::dashboard', 'admin_dashboard');
42-
*
43-
*/
44-
protected function configureRoutes(Symfony\Component\Routing\RouteCollectionBuilder $routes)
98+
public function testFirstAdapterBecomesDefaultWhenNoDefaultDefined(): void
4599
{
100+
$container = new ContainerBuilder();
101+
$extension = new SecretaryExtension();
102+
103+
$extension->load([
104+
[
105+
'adapters' => [
106+
'aws' => [
107+
'adapter' => 'Secretary\Adapter\AWS\SecretsManager\AWSSecretsManagerAdapter',
108+
'config' => [],
109+
'cache' => [
110+
'enabled' => false,
111+
],
112+
],
113+
],
114+
],
115+
], $container);
116+
117+
// 'aws' should be aliased as the default since no 'default' adapter exists
118+
$alias = $container->getAlias('secretary');
119+
$this->assertEquals('secretary.manager.aws', (string) $alias);
46120
}
47121

48-
/**
49-
* {@inheritDc}.
50-
*
51-
* @throws Exception
52-
*/
53-
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
122+
public function testEnvVarProcessorIsRegistered(): void
54123
{
55-
$loader->load(__DIR__.'/services'.self::CONFIG_EXTS, 'glob');
124+
$container = new ContainerBuilder();
125+
$extension = new SecretaryExtension();
126+
127+
$extension->load([
128+
[
129+
'adapters' => [
130+
'default' => [
131+
'adapter' => 'Secretary\Adapter\AWS\SecretsManager\AWSSecretsManagerAdapter',
132+
'config' => [],
133+
'cache' => [
134+
'enabled' => false,
135+
],
136+
],
137+
],
138+
],
139+
], $container);
140+
141+
$definition = $container->getDefinition('secretary.env_var_processor');
142+
$this->assertEquals(EnvVarProcessor::class, $definition->getClass());
56143
}
57144
}
58-
59-
$k = new SecretaryBundleTest('dev', true);
60-
$k->boot();
61-
var_dump($k->getContainer()->getParameter('foo'));

0 commit comments

Comments
 (0)