-
Notifications
You must be signed in to change notification settings - Fork 1.4k
PHPORM-171 Set timestamps when using createOrFirst
#2905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1048,12 +1048,17 @@ public function testNumericFieldName(): void | |
|
||
public function testCreateOrFirst() | ||
{ | ||
Carbon::setTestNow('2010-06-22'); | ||
$createdAt = Carbon::now()->getTimestamp(); | ||
jmikola marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$user1 = User::createOrFirst(['email' => '[email protected]']); | ||
|
||
$this->assertSame('[email protected]', $user1->email); | ||
$this->assertNull($user1->name); | ||
$this->assertTrue($user1->wasRecentlyCreated); | ||
$this->assertEquals($createdAt, $user1->created_at->getTimestamp()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this use a comparison to assert that the I don't see anything in the PR that would guarantee the entire test completes within a single timestamp. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
$this->assertEquals($createdAt, $user1->updated_at->getTimestamp()); | ||
|
||
Carbon::setTestNow('2020-12-28'); | ||
$user2 = User::createOrFirst( | ||
['email' => '[email protected]'], | ||
['name' => 'John Doe', 'birthday' => new DateTime('1987-05-28')], | ||
|
@@ -1064,6 +1069,8 @@ public function testCreateOrFirst() | |
$this->assertNull($user2->name); | ||
$this->assertNull($user2->birthday); | ||
$this->assertFalse($user2->wasRecentlyCreated); | ||
$this->assertEquals($createdAt, $user1->created_at->getTimestamp()); | ||
$this->assertEquals($createdAt, $user1->updated_at->getTimestamp()); | ||
|
||
$user3 = User::createOrFirst( | ||
['email' => '[email protected]'], | ||
|
@@ -1075,6 +1082,8 @@ public function testCreateOrFirst() | |
$this->assertSame('Jane Doe', $user3->name); | ||
$this->assertEquals(new DateTime('1987-05-28'), $user3->birthday); | ||
$this->assertTrue($user3->wasRecentlyCreated); | ||
$this->assertEquals($createdAt, $user1->created_at->getTimestamp()); | ||
$this->assertEquals($createdAt, $user1->updated_at->getTimestamp()); | ||
|
||
$user4 = User::createOrFirst( | ||
['name' => 'Robert Doe'], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/laravel/framework/blob/d1f17cff0285e8aa6a69a2f18d0ad7a2a0fd5ea8/src/Illuminate/Database/Eloquent/Model.php#L1290-L1295