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 5
5
namespace ApiSkeletons \Laravel \Doctrine \ApiKey \Console \Command ;
6
6
7
7
use ApiSkeletons \Laravel \Doctrine \ApiKey \Entity \ApiKey ;
8
- use Throwable ;
9
8
10
9
// phpcs:disable SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint
11
10
final class RegenerateApiKey extends Command
@@ -30,9 +29,9 @@ public function handle(): mixed
30
29
$ apiKeyRepository = $ this ->apiKeyService ->getEntityManager ()
31
30
->getRepository (ApiKey::class);
32
31
33
- try {
34
- $ apiKey = $ apiKeyRepository -> findOneBy ([ ' name ' => $ name ]);
35
- } catch ( Throwable $ e ) {
32
+ $ apiKey = $ apiKeyRepository -> findOneBy ([ ' name ' => $ name ]);
33
+
34
+ if (! $ apiKey ) {
36
35
$ this ->error ('ApiKey not found by name: ' . $ name );
37
36
38
37
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