|
11 | 11 | use Illuminate\Database\Eloquent\ModelNotFoundException; |
12 | 12 | use Illuminate\Support\Facades\Date; |
13 | 13 | use Illuminate\Support\Str; |
| 14 | +use InvalidArgumentException; |
14 | 15 | use MongoDB\BSON\Binary; |
15 | 16 | use MongoDB\BSON\ObjectID; |
16 | 17 | use MongoDB\BSON\UTCDateTime; |
@@ -1047,40 +1048,47 @@ public function testNumericFieldName(): void |
1047 | 1048 |
|
1048 | 1049 | public function testCreateOrFirst() |
1049 | 1050 | { |
1050 | | - $user1 = User::createOrFirst(['email' => 'taylorotwell@gmail.com']); |
| 1051 | + $user1 = User::createOrFirst(['email' => 'john.doe@example.com']); |
1051 | 1052 |
|
1052 | | - $this->assertSame('taylorotwell@gmail.com', $user1->email); |
| 1053 | + $this->assertSame('john.doe@example.com', $user1->email); |
1053 | 1054 | $this->assertNull($user1->name); |
1054 | 1055 | $this->assertTrue($user1->wasRecentlyCreated); |
1055 | 1056 |
|
1056 | 1057 | $user2 = User::createOrFirst( |
1057 | | - ['email' => 'taylorotwell@gmail.com'], |
1058 | | - ['name' => 'Taylor Otwell', 'birthday' => new DateTime('1987-05-28')], |
| 1058 | + ['email' => 'john.doe@example.com'], |
| 1059 | + ['name' => 'John Doe', 'birthday' => new DateTime('1987-05-28')], |
1059 | 1060 | ); |
1060 | 1061 |
|
1061 | 1062 | $this->assertEquals($user1->id, $user2->id); |
1062 | | - $this->assertSame('taylorotwell@gmail.com', $user2->email); |
| 1063 | + $this->assertSame('john.doe@example.com', $user2->email); |
1063 | 1064 | $this->assertNull($user2->name); |
1064 | 1065 | $this->assertNull($user2->birthday); |
1065 | 1066 | $this->assertFalse($user2->wasRecentlyCreated); |
1066 | 1067 |
|
1067 | 1068 | $user3 = User::createOrFirst( |
1068 | | - ['email' => 'abigailotwell@gmail.com'], |
1069 | | - ['name' => 'Abigail Otwell', 'birthday' => new DateTime('1987-05-28')], |
| 1069 | + ['email' => 'jane.doe@example.com'], |
| 1070 | + ['name' => 'Jane Doe', 'birthday' => new DateTime('1987-05-28')], |
1070 | 1071 | ); |
1071 | 1072 |
|
1072 | 1073 | $this->assertNotEquals($user3->id, $user1->id); |
1073 | | - $this->assertSame('abigailotwell@gmail.com', $user3->email); |
1074 | | - $this->assertSame('Abigail Otwell', $user3->name); |
| 1074 | + $this->assertSame('jane.doe@example.com', $user3->email); |
| 1075 | + $this->assertSame('Jane Doe', $user3->name); |
1075 | 1076 | $this->assertEquals(new DateTime('1987-05-28'), $user3->birthday); |
1076 | 1077 | $this->assertTrue($user3->wasRecentlyCreated); |
1077 | 1078 |
|
1078 | 1079 | $user4 = User::createOrFirst( |
1079 | | - ['name' => 'Dries Vints'], |
1080 | | - ['name' => 'Nuno Maduro', 'email' => 'nuno@laravel.com'], |
| 1080 | + ['name' => 'Robert Doe'], |
| 1081 | + ['name' => 'Maria Doe', 'email' => 'maria.doe@example.com'], |
1081 | 1082 | ); |
1082 | 1083 |
|
1083 | | - $this->assertSame('Nuno Maduro', $user4->name); |
| 1084 | + $this->assertSame('Maria Doe', $user4->name); |
1084 | 1085 | $this->assertTrue($user4->wasRecentlyCreated); |
1085 | 1086 | } |
| 1087 | + |
| 1088 | + public function testCreateOrFirstRequiresFilter() |
| 1089 | + { |
| 1090 | + $this->expectException(InvalidArgumentException::class); |
| 1091 | + $this->expectExceptionMessage('You must provide attributes to check for duplicates'); |
| 1092 | + User::createOrFirst([]); |
| 1093 | + } |
1086 | 1094 | } |
0 commit comments