-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Consolidate repetitive model instantiations across tests #3416
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 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -49,7 +49,14 @@ | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| class ModelTest extends TestCase | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| public function tearDown(): void | ||||||||||||||||||||||||||||||||
| protected function setUp(): void | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| parent::setUp(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Carbon::setTestNow(); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| protected function tearDown(): void | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| Carbon::setTestNow(); | ||||||||||||||||||||||||||||||||
| DB::connection('mongodb')->getCollection('users')->drop(); | ||||||||||||||||||||||||||||||||
|
|
@@ -83,15 +90,22 @@ public function testQualifyColumn(): void | |||||||||||||||||||||||||||||||
| $this->assertEquals('users.name', $sqlUser->qualifyColumn('name')); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| public function testInsert(): void | ||||||||||||||||||||||||||||||||
| private function makeUser(): User | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| $user = new User(); | ||||||||||||||||||||||||||||||||
| $user = new User(); | ||||||||||||||||||||||||||||||||
| $user->name = 'John Doe'; | ||||||||||||||||||||||||||||||||
| $user->title = 'admin'; | ||||||||||||||||||||||||||||||||
| $user->age = 35; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| $user->save(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return $user; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| public function testInsert(): void | ||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||
| $user = $this->makeUser(); | ||||||||||||||||||||||||||||||||
|
Comment on lines
100
to
+107
|
||||||||||||||||||||||||||||||||
| $user->save(); | |
| return $user; | |
| } | |
| public function testInsert(): void | |
| { | |
| $user = $this->makeUser(); | |
| return $user; | |
| } | |
| public function testInsert(): void | |
| { | |
| $user = $this->makeUser(); | |
| $user->save(); |
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.
The helper method
makeUser()hasprivatevisibility, which prevents subclasses from reusing this factory method. Consider changing it toprotectedto allow test class inheritance and reuse of the helper.