@@ -76,6 +76,65 @@ public function testCanCreateAuthorModelWithFullDetailsFromArgumentUnpacking()
7676 $ this ->assertSame ($ data ['socials ' ], $ author ->socials );
7777 }
7878
79+ public function testCanCreateAuthorModelWithFullDetailsFromArrayUsingGetOrCreate ()
80+ {
81+ $ data = $ this ->exampleData ();
82+
83+ $ author = PostAuthor::getOrCreate ($ data );
84+
85+ $ this ->assertSame ($ data ['username ' ], $ author ->username );
86+ $ this ->assertSame ($ data ['name ' ], $ author ->name );
87+ $ this ->assertSame ($ data ['website ' ], $ author ->website );
88+ $ this ->assertSame ($ data ['bio ' ], $ author ->bio );
89+ $ this ->assertSame ($ data ['avatar ' ], $ author ->avatar );
90+ $ this ->assertSame ($ data ['socials ' ], $ author ->socials );
91+ }
92+
93+ public function testCanCreateAuthorModelWithSomeDetailsFromArrayUsingGetOrCreate ()
94+ {
95+ $ data = $ this ->exampleData ();
96+
97+ $ author = PostAuthor::getOrCreate ([
98+ 'username ' => $ data ['username ' ],
99+ 'name ' => $ data ['name ' ],
100+ 'website ' => $ data ['website ' ],
101+ ]);
102+
103+ $ this ->assertSame ($ data ['username ' ], $ author ->username );
104+ $ this ->assertSame ($ data ['name ' ], $ author ->name );
105+ $ this ->assertSame ($ data ['website ' ], $ author ->website );
106+ $ this ->assertNull ($ author ->bio );
107+ $ this ->assertNull ($ author ->avatar );
108+ $ this ->assertEmpty ($ author ->socials );
109+ }
110+
111+ public function testCanCreateAuthorModelWithSomeDetailsFromArrayUsingGetOrCreateWithoutUsername ()
112+ {
113+ $ data = $ this ->exampleData ();
114+
115+ $ author = PostAuthor::getOrCreate ([
116+ 'name ' => $ data ['name ' ],
117+ 'website ' => $ data ['website ' ],
118+ ]);
119+
120+ $ this ->assertSame ($ data ['name ' ], $ author ->username );
121+ $ this ->assertSame ($ data ['name ' ], $ author ->name );
122+ $ this ->assertSame ($ data ['website ' ], $ author ->website );
123+ }
124+
125+ public function testCanCreateAuthorModelWithSomeDetailsFromArrayUsingGetOrCreateWithoutAnyNames ()
126+ {
127+ $ data = $ this ->exampleData ();
128+
129+ $ author = PostAuthor::getOrCreate ([
130+ 'website ' => $ data ['website ' ],
131+ ]);
132+
133+ $ this ->assertSame ('Guest ' , $ author ->username );
134+ $ this ->assertSame ('Guest ' , $ author ->name );
135+ $ this ->assertSame ($ data ['website ' ], $ author ->website );
136+ }
137+
79138 public function testNameIsSetToUsernameIfNoNameIsProvided ()
80139 {
81140 $ author = new PostAuthor ('foo ' );
0 commit comments