File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed
test/Feature/Console/Command Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change 55namespace ApiSkeletons \Laravel \Doctrine \ApiKey \Console \Command ;
66
77use ApiSkeletons \Laravel \Doctrine \ApiKey \Entity \ApiKey ;
8- use Throwable ;
98
109// phpcs:disable SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint
1110final class RegenerateApiKey extends Command
@@ -30,9 +29,9 @@ public function handle(): mixed
3029 $ apiKeyRepository = $ this ->apiKeyService ->getEntityManager ()
3130 ->getRepository (ApiKey::class);
3231
33- try {
34- $ apiKey = $ apiKeyRepository -> findOneBy ([ ' name ' => $ name ]);
35- } catch ( Throwable $ e ) {
32+ $ apiKey = $ apiKeyRepository -> findOneBy ([ ' name ' => $ name ]);
33+
34+ if (! $ apiKey ) {
3635 $ this ->error ('ApiKey not found by name: ' . $ name );
3736
3837 return 1 ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace ApiSkeletonsTest \Laravel \Doctrine \ApiKey \Feature \Console \Command ;
4+
5+ use ApiSkeletons \Laravel \Doctrine \ApiKey \Entity \ApiKey ;
6+ use ApiSkeletons \Laravel \Doctrine \ApiKey \Entity \Scope ;
7+ use ApiSkeletonsTest \Laravel \Doctrine \ApiKey \TestCase ;
8+ use DateTime ;
9+
10+ final class ReenerateApiKeyTest extends TestCase
11+ {
12+ public function testReenerateApiKey (): void
13+ {
14+ $ entityManager = $ this ->createDatabase (app ('em ' ));
15+
16+ $ apiKey = $ entityManager ->getRepository (ApiKey::class)
17+ ->generate ('testing ' );
18+ $ entityManager ->flush ();
19+
20+ $ this ->artisan ('apikey:regenerate ' , [
21+ 'name ' => 'testing ' ,
22+ ])->assertExitCode (0 );
23+ }
24+
25+ public function testInvalidNameThrowsError (): void
26+ {
27+ $ this ->createDatabase (app ('em ' ));
28+
29+ $ this ->artisan ('apikey:regenerate ' , [
30+ 'name ' => 'test^ing ' ,
31+ ])->assertExitCode (1 );
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments