File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change 55namespace Hyde \Foundation \Concerns ;
66
77use Hyde \Facades \Config ;
8+ use InvalidArgumentException ;
89use Illuminate \Support \Collection ;
910use Hyde \Framework \Features \Blogging \Models \PostAuthor ;
1011
@@ -50,6 +51,10 @@ public function authors(): Collection
5051 protected function parseConfigurationAuthors (Collection $ authors ): Collection
5152 {
5253 return $ authors ->mapWithKeys (function (PostAuthor $ author , string $ username ): array {
54+ if (! $ username ) {
55+ throw new InvalidArgumentException ('Author username cannot be empty. Did you forget to set the author \'s array key? ' );
56+ }
57+
5358 return [$ username => tap ($ author , fn (PostAuthor $ author ) => $ author ->username = $ username )];
5459 });
5560 }
Original file line number Diff line number Diff line change 66
77use Hyde \Facades \Author ;
88use Hyde \Facades \Features ;
9+ use InvalidArgumentException ;
910use Hyde \Foundation \Facades \Pages ;
1011use Illuminate \Support \Collection ;
1112use Hyde \Foundation \Facades \Routes ;
@@ -591,6 +592,16 @@ public function testAuthorsUseTheConfigArrayKeyAsTheUsername()
591592 ],
592593 ], Hyde::authors ()->toArray ());
593594 }
595+
596+ public function testAuthorsThrowsExceptionWhenUsernameIsNotSet ()
597+ {
598+ $ this ->expectException (InvalidArgumentException::class);
599+ $ this ->expectExceptionMessage ('Author username cannot be empty. Did you forget to set the author \'s array key? ' );
600+
601+ Config::set ('hyde.authors ' , ['' => Author::create ('foo ' )]);
602+
603+ Hyde::authors ();
604+ }
594605}
595606
596607class CallableClass
You can’t perform that action at this time.
0 commit comments