Skip to content

Commit dc0b8c7

Browse files
committed
Inline route helpers in tests
1 parent b8265d5 commit dc0b8c7

File tree

5 files changed

+17
-42
lines changed

5 files changed

+17
-42
lines changed

tests/Feature/ReportTemplates/DeleteReportTemplateTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testRequiresPermission()
1616
$reportTemplate = ReportTemplate::factory()->create();
1717

1818
$this->actingAs(User::factory()->create())
19-
->post($this->getRoute($reportTemplate))
19+
->post(route('report-templates.destroy', $reportTemplate->id))
2020
->assertNotFound();
2121

2222
$this->assertModelExists($reportTemplate);
@@ -27,7 +27,7 @@ public function testCannotDeleteAnotherUsersReportTemplate()
2727
$reportTemplate = ReportTemplate::factory()->create();
2828

2929
$this->actingAs(User::factory()->canViewReports()->create())
30-
->delete($this->getRoute($reportTemplate))
30+
->delete(route('report-templates.destroy', $reportTemplate->id))
3131
->assertNotFound();
3232

3333
$this->assertModelExists($reportTemplate);
@@ -39,14 +39,9 @@ public function testCanDeleteAReportTemplate()
3939
$reportTemplate = ReportTemplate::factory()->for($user, 'creator')->create();
4040

4141
$this->actingAs($user)
42-
->delete($this->getRoute($reportTemplate))
42+
->delete(route('report-templates.destroy', $reportTemplate->id))
4343
->assertRedirect(route('reports/custom'));
4444

4545
$this->assertSoftDeleted($reportTemplate);
4646
}
47-
48-
private function getRoute(ReportTemplate $reportTemplate): string
49-
{
50-
return route('report-templates.destroy', $reportTemplate->id);
51-
}
5247
}

tests/Feature/ReportTemplates/EditReportTemplateTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class EditReportTemplateTest extends TestCase implements TestsPermissionsRequire
1414
public function testRequiresPermission()
1515
{
1616
$this->actingAs(User::factory()->create())
17-
->get($this->getRoute(ReportTemplate::factory()->create()))
17+
->get(route('report-templates.edit', ReportTemplate::factory()->create()))
1818
->assertNotFound();
1919
}
2020

@@ -24,7 +24,7 @@ public function testCannotLoadEditPageForAnotherUsersReportTemplate()
2424
$reportTemplate = ReportTemplate::factory()->create();
2525

2626
$this->actingAs($user)
27-
->get($this->getRoute($reportTemplate))
27+
->get(route('report-templates.edit', $reportTemplate))
2828
->assertNotFound();
2929
}
3030

@@ -34,12 +34,7 @@ public function testCanLoadEditReportTemplatePage()
3434
$reportTemplate = ReportTemplate::factory()->for($user, 'creator')->create();
3535

3636
$this->actingAs($user)
37-
->get($this->getRoute($reportTemplate))
37+
->get(route('report-templates.edit', $reportTemplate))
3838
->assertOk();
3939
}
40-
41-
private function getRoute(ReportTemplate $reportTemplate): string
42-
{
43-
return route('report-templates.edit', $reportTemplate);
44-
}
4540
}

tests/Feature/ReportTemplates/ShowReportTemplateTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ShowReportTemplateTest extends TestCase implements TestsPermissionsRequire
1414
public function testRequiresPermission()
1515
{
1616
$this->actingAs(User::factory()->create())
17-
->get($this->getRoute(ReportTemplate::factory()->create()))
17+
->get(route('report-templates.show', ReportTemplate::factory()->create()))
1818
->assertNotFound();
1919
}
2020

@@ -25,7 +25,7 @@ public function testCanLoadASavedReportTemplate()
2525
$user->reportTemplates()->save($reportTemplate);
2626

2727
$this->actingAs($user)
28-
->get($this->getRoute($reportTemplate))
28+
->get(route('report-templates.show', $reportTemplate))
2929
->assertOk()
3030
->assertViewHas(['template' => function (ReportTemplate $templatePassedToView) use ($reportTemplate) {
3131
return $templatePassedToView->is($reportTemplate);
@@ -37,12 +37,7 @@ public function testCannotLoadAnotherUsersSavedReportTemplate()
3737
$reportTemplate = ReportTemplate::factory()->create();
3838

3939
$this->actingAs(User::factory()->canViewReports()->create())
40-
->get($this->getRoute($reportTemplate))
40+
->get(route('report-templates.show', $reportTemplate))
4141
->assertNotFound();
4242
}
43-
44-
private function getRoute(ReportTemplate $reportTemplate): string
45-
{
46-
return route('report-templates.show', $reportTemplate);
47-
}
4843
}

tests/Feature/ReportTemplates/StoreReportTemplateTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class StoreReportTemplateTest extends TestCase implements TestsPermissionsRequir
1414
public function testRequiresPermission()
1515
{
1616
$this->actingAs(User::factory()->create())
17-
->post($this->getRoute())
17+
->post(route('report-templates.store'))
1818
->assertForbidden();
1919
}
2020

2121
public function testSavingReportTemplateRequiresValidFields()
2222
{
2323
$this->actingAs(User::factory()->canViewReports()->create())
24-
->post($this->getRoute(), [
24+
->post(route('report-templates.store'), [
2525
'name' => '',
2626
])
2727
->assertSessionHasErrors('name');
@@ -33,7 +33,7 @@ public function testRedirectingAfterValidationErrorRestoresInputs()
3333
// start on the custom report page
3434
->from(route('reports/custom'))
3535
->followingRedirects()
36-
->post($this->getRoute(), [
36+
->post(route('report-templates.store'), [
3737
'name' => '',
3838
// set some values to ensure they are still present
3939
// when returning to the custom report page.
@@ -48,7 +48,7 @@ public function testCanSaveAReportTemplate()
4848
$user = User::factory()->canViewReports()->create();
4949

5050
$this->actingAs($user)
51-
->post($this->getRoute(), [
51+
->post(route('report-templates.store'), [
5252
'name' => 'My Awesome Template',
5353
'company' => '1',
5454
'by_company_id' => ['1', '2'],
@@ -63,9 +63,4 @@ public function testCanSaveAReportTemplate()
6363
$this->assertEquals('1', $template->options['company']);
6464
$this->assertEquals(['1', '2'], $template->options['by_company_id']);
6565
}
66-
67-
private function getRoute(): string
68-
{
69-
return route('report-templates.store');
70-
}
7166
}

tests/Feature/ReportTemplates/UpdateReportTemplateTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class UpdateReportTemplateTest extends TestCase implements TestsPermissionsRequi
1414
public function testRequiresPermission()
1515
{
1616
$this->actingAs(User::factory()->create())
17-
->post($this->getRoute(ReportTemplate::factory()->create()))
17+
->post(route('report-templates.update', ReportTemplate::factory()->create()))
1818
->assertNotFound();
1919
}
2020

2121
public function testCannotUpdateAnotherUsersReportTemplate()
2222
{
2323
$this->actingAs(User::factory()->canViewReports()->create())
24-
->post($this->getRoute(ReportTemplate::factory()->create()))
24+
->post(route('report-templates.update', ReportTemplate::factory()->create()))
2525
->assertNotFound();
2626
}
2727

@@ -32,7 +32,7 @@ public function testUpdatingReportTemplateRequiresValidFields()
3232
$reportTemplate = ReportTemplate::factory()->for($user, 'creator')->create();
3333

3434
$this->actingAs($user)
35-
->post($this->getRoute($reportTemplate), [
35+
->post(route('report-templates.update', $reportTemplate), [
3636
//
3737
])
3838
->assertSessionHasErrors([
@@ -56,7 +56,7 @@ public function testCanUpdateAReportTemplate()
5656
]);
5757

5858
$this->actingAs($user)
59-
->post($this->getRoute($reportTemplate), [
59+
->post(route('report-templates.update', $reportTemplate), [
6060
'name' => 'Updated Name',
6161
'id' => 1,
6262
'company' => 1,
@@ -71,9 +71,4 @@ public function testCanUpdateAReportTemplate()
7171
$this->assertEquals(1, $reportTemplate->checkmarkValue('company'));
7272
$this->assertEquals([3], $reportTemplate->selectValues('by_company_id'));
7373
}
74-
75-
private function getRoute(ReportTemplate $reportTemplate): string
76-
{
77-
return route('report-templates.update', $reportTemplate);
78-
}
7974
}

0 commit comments

Comments
 (0)