Skip to content
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

chore: use singleton in all tests #2349

Merged
merged 3 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions tests/Unit/Services/Account/Company/CreateCompanyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public function test_it_stores_a_company()
'number_of_employees' => 3,
];

$companyService = new CreateCompany;
$company = $companyService->execute($request);
$company = app(CreateCompany::class)->execute($request);

$this->assertDatabaseHas('companies', [
'id' => $company->id,
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Services/Account/Company/DestroyCompanyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public function test_it_destroys_a_company()
'company_id' => $company->id,
];

$companyService = new DestroyCompany;
$bool = $companyService->execute($request);
app(DestroyCompany::class)->execute($request);

$this->assertDatabaseMissing('companies', [
'id' => $company->id,
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Services/Account/Company/UpdateCompanyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public function test_it_updates_a_company()
'number_of_employees' => 300,
];

$companyService = new UpdateCompany;
$company = $companyService->execute($request);
app(UpdateCompany::class)->execute($request);

$this->assertDatabaseHas('companies', [
'id' => $company->id,
Expand Down
6 changes: 2 additions & 4 deletions tests/Unit/Services/Account/DestroyAllDocumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public function test_it_destroys_all_documents()
'account_id' => $contact->account->id,
];

$destroyAllDocumentsService = new DestroyAllDocuments;
$bool = $destroyAllDocumentsService->execute($request);
app(DestroyAllDocuments::class)->execute($request);

$this->assertDatabaseMissing('documents', [
'account_id' => $contact->account->id,
Expand All @@ -45,8 +44,7 @@ public function test_it_fails_if_wrong_parameters_are_given()

$this->expectException(ValidationException::class);

$destroyAllDocumentsService = new DestroyAllDocuments;
$result = $destroyAllDocumentsService->execute($request);
app(DestroyAllDocuments::class)->execute($request);
}

private function uploadDocument($contact)
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Services/Account/Gender/CreateGenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public function test_it_stores_a_gender()
'name' => 'man',
];

$genderService = new CreateGender;
$gender = $genderService->execute($request);
$gender = app(CreateGender::class)->execute($request);

$this->assertDatabaseHas('genders', [
'id' => $gender->id,
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Services/Account/Gender/DestroyGenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public function test_it_destroys_a_gender()
'gender_id' => $gender->id,
];

$genderService = new DestroyGender;
$bool = $genderService->execute($request);
app(DestroyGender::class)->execute($request);

$this->assertDatabaseMissing('genders', [
'id' => $gender->id,
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Services/Account/Gender/UpdateGenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public function test_it_updates_a_gender()
'name' => 'man',
];

$genderService = new UpdateGender;
$gender = $genderService->execute($request);
$gender = app(UpdateGender::class)->execute($request);

$this->assertDatabaseHas('genders', [
'id' => $gender->id,
Expand Down
9 changes: 3 additions & 6 deletions tests/Unit/Services/Account/Photo/DestroyPhotoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public function test_it_destroys_a_photo()
'id' => $photo->id,
]);

$destroyPhotoService = new DestroyPhoto;
$bool = $destroyPhotoService->execute($request);
app(DestroyPhoto::class)->execute($request);

$this->assertDatabaseMissing('photos', [
'id' => $photo->id,
Expand All @@ -49,8 +48,7 @@ public function test_it_fails_if_wrong_parameters_are_given()

$this->expectException(ValidationException::class);

$destroyPhotoService = new DestroyPhoto;
$result = $destroyPhotoService->execute($request);
app(DestroyPhoto::class)->execute($request);
}

public function test_it_throws_a_photo_doesnt_exist()
Expand All @@ -64,8 +62,7 @@ public function test_it_throws_a_photo_doesnt_exist()

$this->expectException(ModelNotFoundException::class);

$destroyPhotoService = new DestroyPhoto;
$photo = $destroyPhotoService->execute($request);
app(DestroyPhoto::class)->execute($request);
}

private function uploadPhoto($contact)
Expand Down
6 changes: 2 additions & 4 deletions tests/Unit/Services/Account/Photo/UploadPhotoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public function test_it_uploads_a_photo()
'photo' => $file,
];

$uploadService = new UploadPhoto;
$photo = $uploadService->execute($request);
$photo = app(UploadPhoto::class)->execute($request);

$this->assertDatabaseHas('photos', [
'id' => $photo->id,
Expand All @@ -52,8 +51,7 @@ public function test_it_fails_if_wrong_parameters_are_given()

$this->expectException(ValidationException::class);

$uploadService = new UploadPhoto;
$photo = $uploadService->execute($request);
app(UploadPhoto::class)->execute($request);
}

public function test_it_throws_an_exception_if_account_does_not_exist()
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Services/Account/Place/DestroyPlaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public function test_it_destroys_a_place()
'place_id' => $place->id,
];

$placeService = new DestroyPlace;
$bool = $placeService->execute($request);
app(DestroyPlace::class)->execute($request);

$this->assertDatabaseMissing('places', [
'id' => $place->id,
Expand Down
15 changes: 5 additions & 10 deletions tests/Unit/Services/Auth/PopulateLifeEventsTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ public function test_it_fails_if_wrong_parameters_are_given()

$this->expectException(\Exception::class);

$populateLifeEventService = new PopulateLifeEventsTable;
$populateLifeEventService->execute($request);
app(PopulateLifeEventsTable::class)->execute($request);

$request = [
'migrate_existing_data' => false,
];

$this->expectException(ValidationException::class);

$populateLifeEventService = new PopulateLifeEventsTable;
$populateLifeEventService->execute($request);
app(PopulateLifeEventsTable::class)->execute($request);
}

public function test_it_populate_life_event_tables()
Expand All @@ -51,8 +49,7 @@ public function test_it_populate_life_event_tables()
'migrate_existing_data' => 1,
];

$populateLifeEventService = new PopulateLifeEventsTable;
$populateLifeEventService->execute($request);
app(PopulateLifeEventsTable::class)->execute($request);

$this->assertEquals(
5,
Expand Down Expand Up @@ -83,8 +80,7 @@ public function test_it_refuses_to_populate_table_if_account_doesnt_have_locale(
'migrate_existing_data' => 0,
];

$populateLifeEventService = new PopulateLifeEventsTable;
$this->assertFalse($populateLifeEventService->execute($request));
$this->assertFalse(app(PopulateLifeEventsTable::class)->execute($request));
}

public function test_it_only_populates_life_event_tables_partially()
Expand All @@ -107,8 +103,7 @@ public function test_it_only_populates_life_event_tables_partially()
'migrate_existing_data' => 0,
];

$populateLifeEventService = new PopulateLifeEventsTable;
$populateLifeEventService->execute($request);
app(PopulateLifeEventsTable::class)->execute($request);

$this->assertEquals(
4,
Expand Down
9 changes: 3 additions & 6 deletions tests/Unit/Services/Auth/PopulateModulesTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public function test_it_fails_if_wrong_parameters_are_given()

$this->expectException(ValidationException::class);

$populateModulesService = new PopulateModulesTable;
$populateModulesService->execute($request);
app(PopulateModulesTable::class)->execute($request);
}

public function test_it_populate_modules_tables()
Expand All @@ -51,8 +50,7 @@ public function test_it_populate_modules_tables()
'migrate_existing_data' => 1,
];

$populateModulesService = new PopulateModulesTable;
$populateModulesService->execute($request);
app(PopulateModulesTable::class)->execute($request);

// by defauult there is 18 columns in the default table.
// therefore, we need 18 entries for the new account.
Expand Down Expand Up @@ -87,8 +85,7 @@ public function test_it_only_populates_module_tables_partially()
'migrate_existing_data' => 0,
];

$populateModulesService = new PopulateModulesTable;
$populateModulesService->execute($request);
app(PopulateModulesTable::class)->execute($request);

// by defauult there is 18 columns in the default table.
// therefore, we need 17 entries for the new account.
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Services/Contact/Address/CreateAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function test_it_stores_an_address()
'longitude' => '',
];

$addressService = new CreateAddress;
$address = $addressService->execute($request);
$address = app(CreateAddress::class)->execute($request);

$this->assertDatabaseHas('addresses', [
'id' => $address->id,
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Services/Contact/Address/UpdateAddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public function test_it_updates_an_address()
'longitude' => '',
];

$addressService = new UpdateAddress;
$address = $addressService->execute($request);
$address = app(UpdateAddress::class)->execute($request);

$this->assertDatabaseHas('addresses', [
'id' => $address->id,
Expand Down
21 changes: 7 additions & 14 deletions tests/Unit/Services/Contact/Call/CreateCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public function test_it_stores_a_call()
'content' => 'this is the content',
];

$callService = new CreateCall;
$call = $callService->execute($request);
$call = app(CreateCall::class)->execute($request);

$this->assertDatabaseHas('calls', [
'id' => $call->id,
Expand Down Expand Up @@ -57,8 +56,7 @@ public function test_it_stores_a_call_and_who_called_information()
'contact_called' => true,
];

$callService = new CreateCall;
$call = $callService->execute($request);
$call = app(CreateCall::class)->execute($request);

$this->assertDatabaseHas('calls', [
'id' => $call->id,
Expand Down Expand Up @@ -88,8 +86,7 @@ public function test_it_adds_emotions()
'emotions' => $emotionArray,
];

$callService = new CreateCall;
$call = $callService->execute($request);
$call = app(CreateCall::class)->execute($request);

$this->assertDatabaseHas('calls', [
'id' => $call->id,
Expand Down Expand Up @@ -131,8 +128,7 @@ public function test_it_fails_adding_emotions_when_emotion_is_unknown()

$this->expectException(ModelNotFoundException::class);

$callService = new CreateCall;
$call = $callService->execute($request);
app(CreateCall::class)->execute($request);
}

public function test_it_stores_a_call_without_the_content()
Expand All @@ -145,8 +141,7 @@ public function test_it_stores_a_call_without_the_content()
'called_at' => Carbon::now(),
];

$callService = new CreateCall;
$call = $callService->execute($request);
$call = app(CreateCall::class)->execute($request);

$this->assertDatabaseHas('calls', [
'id' => $call->id,
Expand All @@ -170,8 +165,7 @@ public function test_it_updates_the_last_call_info()
'called_at' => $date,
];

$callService = new CreateCall;
$call = $callService->execute($request);
app(CreateCall::class)->execute($request);

$this->assertDatabaseHas('contacts', [
'id' => $contact->id,
Expand All @@ -193,8 +187,7 @@ public function test_it_doesnt_update_the_last_call_info()
'called_at' => $date,
];

$callService = new CreateCall;
$call = $callService->execute($request);
app(CreateCall::class)->execute($request);

$this->assertDatabaseHas('contacts', [
'id' => $contact->id,
Expand Down
12 changes: 4 additions & 8 deletions tests/Unit/Services/Contact/Call/DestroyCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public function test_it_destroys_a_call()
'id' => $call->id,
]);

$callService = new DestroyCall;
$bool = $callService->execute($request);
app(DestroyCall::class)->execute($request);

$this->assertDatabaseMissing('calls', [
'id' => $call->id,
Expand Down Expand Up @@ -60,8 +59,7 @@ public function test_it_removes_emotions()
'call_id' => $call->id,
];

$callService = new DestroyCall;
$bool = $callService->execute($request);
app(DestroyCall::class)->execute($request);

$this->assertDatabaseMissing('emotion_call', [
'contact_id' => $call->contact_id,
Expand Down Expand Up @@ -94,8 +92,7 @@ public function test_it_updates_the_last_talked_to_information()
'call_id' => $call->id,
];

$callService = new DestroyCall;
$bool = $callService->execute($request);
app(DestroyCall::class)->execute($request);

$this->assertDatabaseHas('contacts', [
'id' => $contact->id,
Expand All @@ -118,8 +115,7 @@ public function test_it_doesnt_update_the_last_talked_to_information()
'call_id' => $call->id,
];

$callService = new DestroyCall;
$bool = $callService->execute($request);
app(DestroyCall::class)->execute($request);

$this->assertDatabaseHas('contacts', [
'id' => $contact->id,
Expand Down
Loading