Skip to content

Commit e67b9ee

Browse files
committed
bunch more test updates
1 parent 80e2f32 commit e67b9ee

24 files changed

Lines changed: 258 additions & 291 deletions

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"illuminate/events": "^12.25",
2626
"illuminate/support": "^10.0||^11.0||^12.0",
2727
"laravel/prompts": "^0.1.0||^0.2.0||^0.3.0",
28-
"symfony/console": "^6.0||^7.0"
28+
"symfony/console": "^6.0||^7.0",
29+
"vlucas/phpdotenv": "^5.6"
2930
},
3031
"require-dev": {
3132
"aws/aws-sdk-php": "^3.354",

src/Commands/BaseCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ public function handle(): int
3636
try {
3737
$result = $this->process();
3838

39-
return is_int($result) || is_bool($result) ? $result : self::SUCCESS;
39+
return match(true) {
40+
is_int($result) => $result,
41+
is_bool($result) => $result ? self::SUCCESS : self::FAILURE,
42+
default => self::SUCCESS,
43+
};
4044
} catch (KeepException $e) {
4145
$this->enhanceExceptionWithCommandContext($e);
4246
$e->renderConsole($this->line(...));

src/KeepManager.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public function getSetting(string $key, mixed $default = null): mixed
4141
return $this->settings[$key] ?? $default;
4242
}
4343

44+
public function setSetting(string $key, mixed $value): static
45+
{
46+
$this->settings[$key] = $value;
47+
return $this;
48+
}
49+
4450
public function getAvailableVaults(): array
4551
{
4652
return $this->availableVaults;
@@ -94,6 +100,15 @@ protected function driverClass($name): ?string
94100
{
95101
return Arr::first($this->availableVaults, fn($class) => $class::DRIVER === $name);
96102
}
103+
104+
/**
105+
* Add a vault driver class to available vaults (useful for testing)
106+
*/
107+
public function addVaultDriver(string $driverClass): static
108+
{
109+
$this->availableVaults[] = $driverClass;
110+
return $this;
111+
}
97112

98113
/**
99114
* Clear the vault cache - useful for testing

tests-laravel-backup/Unit/Commands/AbstractCommandTest.php

Lines changed: 0 additions & 103 deletions
This file was deleted.

tests/Feature/CopyCommandTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@
1212
$settings = [
1313
'app_name' => 'test-app',
1414
'namespace' => 'test-app',
15-
'default_vault' => 'ssm',
15+
'default_vault' => 'test',
1616
'stages' => ['testing', 'production'],
1717
'created_at' => date('c'),
1818
'version' => '1.0'
1919
];
2020

2121
file_put_contents('.keep/settings.json', json_encode($settings, JSON_PRETTY_PRINT));
2222

23-
// Create SSM vault configuration for testing
23+
// Create test vault configuration for testing (never hits AWS)
2424
$vaultConfig = [
25-
'driver' => 'ssm',
26-
'name' => 'Test SSM Vault',
27-
'region' => 'us-east-1',
28-
'prefix' => 'test'
25+
'driver' => 'test',
26+
'name' => 'Test Vault',
27+
'namespace' => 'test-app'
2928
];
3029

31-
file_put_contents('.keep/vaults/ssm.json', json_encode($vaultConfig, JSON_PRETTY_PRINT));
30+
file_put_contents('.keep/vaults/test.json', json_encode($vaultConfig, JSON_PRETTY_PRINT));
3231
});
3332

3433
describe('command structure and signature', function () {

tests/Feature/DeleteCommandTest.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,29 @@
1212
$settings = [
1313
'app_name' => 'test-app',
1414
'namespace' => 'test-app',
15-
'default_vault' => 'ssm',
15+
'default_vault' => 'test',
1616
'stages' => ['testing', 'production'],
1717
'created_at' => date('c'),
1818
'version' => '1.0'
1919
];
2020

2121
file_put_contents('.keep/settings.json', json_encode($settings, JSON_PRETTY_PRINT));
2222

23-
// Create SSM vault configuration for testing
23+
// Create test vault configuration for testing (never hits AWS)
2424
$vaultConfig = [
25-
'driver' => 'ssm',
26-
'name' => 'Test SSM Vault',
27-
'region' => 'us-east-1',
28-
'prefix' => 'test'
25+
'driver' => 'test',
26+
'name' => 'Test Vault',
27+
'namespace' => 'test-app'
2928
];
3029

31-
file_put_contents('.keep/vaults/ssm.json', json_encode($vaultConfig, JSON_PRETTY_PRINT));
30+
file_put_contents('.keep/vaults/test.json', json_encode($vaultConfig, JSON_PRETTY_PRINT));
3231
});
3332

3433
describe('command structure and signature', function () {
3534
it('accepts force flag option', function () {
3635
$commandTester = runCommand('delete', [
3736
'key' => 'TEST_KEY',
38-
'--vault' => 'ssm',
37+
'--vault' => 'test',
3938
'--stage' => 'testing',
4039
'--force' => true
4140
]);
@@ -49,7 +48,7 @@
4948
it('validates key argument is provided', function () {
5049
// Try to run delete command without key
5150
$commandTester = runCommand('delete', [
52-
'--vault' => 'ssm',
51+
'--vault' => 'test',
5352
'--stage' => 'testing',
5453
'--force' => true
5554
]);
@@ -65,7 +64,7 @@
6564
it('accepts vault and stage parameters', function () {
6665
$commandTester = runCommand('delete', [
6766
'key' => 'TEST_KEY',
68-
'--vault' => 'ssm',
67+
'--vault' => 'test',
6968
'--stage' => 'testing',
7069
'--force' => true
7170
]);
@@ -81,7 +80,7 @@
8180
it('handles non-existent secrets gracefully', function () {
8281
$commandTester = runCommand('delete', [
8382
'key' => 'NONEXISTENT_KEY',
84-
'--vault' => 'ssm',
83+
'--vault' => 'test',
8584
'--stage' => 'testing',
8685
'--force' => true
8786
]);
@@ -95,7 +94,7 @@
9594
it('handles vault connection issues gracefully', function () {
9695
$commandTester = runCommand('delete', [
9796
'key' => 'CONNECTION_TEST_KEY',
98-
'--vault' => 'ssm',
97+
'--vault' => 'test',
9998
'--stage' => 'testing',
10099
'--force' => true
101100
]);
@@ -110,7 +109,7 @@
110109
it('validates stage parameters exist in configuration', function () {
111110
$commandTester = runCommand('delete', [
112111
'key' => 'STAGE_TEST_KEY',
113-
'--vault' => 'ssm',
112+
'--vault' => 'test',
114113
'--stage' => 'testing', // Valid stage from our config
115114
'--force' => true
116115
]);
@@ -126,7 +125,7 @@
126125
it('accepts force flag without prompting', function () {
127126
$commandTester = runCommand('delete', [
128127
'key' => 'FORCE_TEST_KEY',
129-
'--vault' => 'ssm',
128+
'--vault' => 'test',
130129
'--stage' => 'testing',
131130
'--force' => true
132131
]);
@@ -140,7 +139,7 @@
140139
it('shows appropriate deletion message format', function () {
141140
$commandTester = runCommand('delete', [
142141
'key' => 'MESSAGE_TEST_KEY',
143-
'--vault' => 'ssm',
142+
'--vault' => 'test',
144143
'--stage' => 'testing',
145144
'--force' => true
146145
]);
@@ -156,7 +155,7 @@
156155
it('uses specified vault parameter', function () {
157156
$commandTester = runCommand('delete', [
158157
'key' => 'VAULT_TEST_KEY',
159-
'--vault' => 'ssm',
158+
'--vault' => 'test',
160159
'--stage' => 'testing',
161160
'--force' => true
162161
]);
@@ -170,7 +169,7 @@
170169
it('uses specified stage parameter', function () {
171170
$commandTester = runCommand('delete', [
172171
'key' => 'STAGE_TEST_KEY',
173-
'--vault' => 'ssm',
172+
'--vault' => 'test',
174173
'--stage' => 'testing',
175174
'--force' => true
176175
]);
@@ -184,7 +183,7 @@
184183
it('handles production stage parameter', function () {
185184
$commandTester = runCommand('delete', [
186185
'key' => 'PROD_TEST_KEY',
187-
'--vault' => 'ssm',
186+
'--vault' => 'test',
188187
'--stage' => 'production', // Valid stage from our config
189188
'--force' => true
190189
]);
@@ -200,7 +199,7 @@
200199
it('shows secret details appropriately', function () {
201200
$commandTester = runCommand('delete', [
202201
'key' => 'DETAILS_TEST_KEY',
203-
'--vault' => 'ssm',
202+
'--vault' => 'test',
204203
'--stage' => 'testing',
205204
'--force' => true
206205
]);
@@ -214,7 +213,7 @@
214213
it('handles table display formatting', function () {
215214
$commandTester = runCommand('delete', [
216215
'key' => 'TABLE_TEST_KEY',
217-
'--vault' => 'ssm',
216+
'--vault' => 'test',
218217
'--stage' => 'testing',
219218
'--force' => true
220219
]);
@@ -230,7 +229,7 @@
230229
it('handles special characters in key names', function () {
231230
$commandTester = runCommand('delete', [
232231
'key' => 'KEY_WITH_SPECIAL-CHARS.123',
233-
'--vault' => 'ssm',
232+
'--vault' => 'test',
234233
'--stage' => 'testing',
235234
'--force' => true
236235
]);
@@ -245,7 +244,7 @@
245244
// Test command without --force to test confirmation logic path
246245
$commandTester = runCommand('delete', [
247246
'key' => 'CANCEL_TEST_KEY',
248-
'--vault' => 'ssm',
247+
'--vault' => 'test',
249248
'--stage' => 'testing'
250249
// Note: no --force flag, so would normally prompt
251250
]);
@@ -259,7 +258,7 @@
259258
it('handles context creation appropriately', function () {
260259
$commandTester = runCommand('delete', [
261260
'key' => 'CONTEXT_TEST_KEY',
262-
'--vault' => 'ssm',
261+
'--vault' => 'test',
263262
'--stage' => 'testing',
264263
'--force' => true
265264
]);
@@ -275,7 +274,7 @@
275274
it('handles secret retrieval for verification', function () {
276275
$commandTester = runCommand('delete', [
277276
'key' => 'VERIFY_TEST_KEY',
278-
'--vault' => 'ssm',
277+
'--vault' => 'test',
279278
'--stage' => 'testing',
280279
'--force' => true
281280
]);
@@ -288,7 +287,7 @@
288287
it('provides appropriate completion status', function () {
289288
$commandTester = runCommand('delete', [
290289
'key' => 'COMPLETION_TEST_KEY',
291-
'--vault' => 'ssm',
290+
'--vault' => 'test',
292291
'--stage' => 'testing',
293292
'--force' => true
294293
]);

0 commit comments

Comments
 (0)