Skip to content

Commit b0175de

Browse files
committed
Edit asserts to have Laravel < 5.4 compatibility
1 parent 6304fba commit b0175de

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

tests/PanicHDTestCase.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ abstract class PanicHDTestCase extends TestCase
1717
*/
1818
protected $baseUrl = 'http://localhost';
1919

20+
// Cover different test methods for different Laravel Versions
21+
protected $laravel_version = null;
22+
2023
// Package general status
2124
protected $status = "Not installed";
2225

@@ -85,7 +88,37 @@ public function load_vars()
8588
$this->admin = Member::inRandomOrder()->admins()->first();
8689
}
8790
}
91+
92+
if (is_null($this->laravel_version)){
93+
$laravel = app();
94+
95+
$this->laravel_version = $laravel::VERSION;
96+
}
8897
}
98+
99+
/*
100+
* Execute different assertRedirect deppending on Laravel version
101+
*/
102+
public function versionAssertRedirect($response, $url)
103+
{
104+
if (version_compare($this->laravel_version, '5.4', '<')){
105+
$response->assertRedirectedTo($url);
106+
}else{
107+
$response->assertRedirect($url);
108+
}
109+
}
110+
111+
/*
112+
* Execute different assertStatus deppending on Laravel version
113+
*/
114+
public function versionAssertStatus($response, $status)
115+
{
116+
if (version_compare($this->laravel_version, '5.4', '<')){
117+
$response->assertResponseStatus($status);
118+
}else{
119+
$response->assertStatus($status);
120+
}
121+
}
89122
}
90123

91124
?>

tests/TicketsTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public function testNoAuth()
1818
if ($this->status == "Installed" and !is_null($this->main_route)){
1919
// Main route
2020
$response = $this->get($this->main_route);
21-
$response->assertRedirect('/login');
21+
$this->versionAssertRedirect($response, '/login');
2222

2323
// Ticket creation
2424
$response = $this->get(route($this->main_route . '.create'));
25-
$response->assertRedirect('/login');
25+
$this->versionAssertRedirect($response, '/login');
2626
}
2727
}
2828

@@ -37,19 +37,19 @@ public function testMainRoute()
3737
// Member access
3838
if(!is_null($this->member)){
3939
$response = $this->actingAs($this->member)->get($this->main_route);
40-
$response->assertStatus(200);
40+
$this->versionAssertStatus($response, 200);
4141
}
4242

4343
// Agent access
4444
if(!is_null($this->agent)){
4545
$response = $this->actingAs($this->agent)->get($this->main_route);
46-
$response->assertStatus(200);
46+
$this->versionAssertStatus($response, 200);
4747
}
4848

4949
// Admin access
5050
if(!is_null($this->admin)){
5151
$response = $this->actingAs($this->admin)->get($this->main_route);
52-
$response->assertStatus(200);
52+
$this->versionAssertStatus($response, 200);
5353
}
5454
}
5555
}
@@ -93,9 +93,9 @@ public function testTicketShowEdit()
9393
$ticket = clone $this->member_tickets_builder;
9494
$ticket = $ticket->notHidden()->first();
9595
$response = $this->actingAs($this->member)->get(route($this->main_route . '.show', ['id' => $ticket->id]));
96-
$response->assertStatus(200);
96+
$this->versionAssertStatus($response, 200);
9797
$response = $this->actingAs($this->member)->get(route($this->main_route . '.edit', ['id' => $ticket->id]));
98-
$response->assertStatus(302);
98+
$this->versionAssertStatus($response, 302);
9999

100100
// Hidden ticket without $this->member in notifications
101101
$ticket = clone $this->member_tickets_builder;
@@ -107,9 +107,9 @@ public function testTicketShowEdit()
107107
->first();
108108
if(!is_null($ticket)){
109109
$response = $this->actingAs($this->member)->get(route($this->main_route . '.show', ['id' => $ticket->id]));
110-
$response->assertStatus(302);
110+
$this->versionAssertStatus($response, 302);
111111
$response = $this->actingAs($this->member)->get(route($this->main_route . '.edit', ['id' => $ticket->id]));
112-
$response->assertStatus(302);
112+
$this->versionAssertStatus($response, 302);
113113
}
114114
}
115115

@@ -118,9 +118,9 @@ public function testTicketShowEdit()
118118
$ticket = $this->agent->agentTickets()->inRandomOrder()->first();
119119

120120
$response = $this->actingAs($this->agent)->get(route($this->main_route . '.show', ['id' => $ticket->id]));
121-
$response->assertStatus(200);
121+
$this->versionAssertStatus($response, 200);
122122
$response = $this->actingAs($this->agent)->get(route($this->main_route . '.edit', ['id' => $ticket->id]));
123-
$response->assertStatus(200);
123+
$this->versionAssertStatus($response, 200);
124124
}
125125

126126
// Admin access
@@ -133,9 +133,9 @@ public function testTicketShowEdit()
133133

134134
if (!is_null($ticket)){
135135
$response = $this->actingAs($this->admin)->get(route($this->main_route . '.show', ['id' => $ticket->id]));
136-
$response->assertStatus(200);
136+
$this->versionAssertStatus($response, 200);
137137
$response = $this->actingAs($this->admin)->get(route($this->main_route . '.edit', ['id' => $ticket->id]));
138-
$response->assertStatus(200);
138+
$this->versionAssertStatus($response, 200);
139139
}
140140

141141
// Active ticket
@@ -144,9 +144,9 @@ public function testTicketShowEdit()
144144

145145
if (!is_null($ticket)){
146146
$response = $this->actingAs($this->admin)->get(route($this->main_route . '.show', ['id' => $ticket->id]));
147-
$response->assertStatus(200);
147+
$this->versionAssertStatus($response, 200);
148148
$response = $this->actingAs($this->admin)->get(route($this->main_route . '.edit', ['id' => $ticket->id]));
149-
$response->assertStatus(200);
149+
$this->versionAssertStatus($response, 200);
150150
}
151151

152152
// Complete ticket
@@ -155,9 +155,9 @@ public function testTicketShowEdit()
155155

156156
if (!is_null($ticket)){
157157
$response = $this->actingAs($this->admin)->get(route($this->main_route . '.show', ['id' => $ticket->id]));
158-
$response->assertStatus(200);
158+
$this->versionAssertStatus($response, 200);
159159
$response = $this->actingAs($this->admin)->get(route($this->main_route . '.edit', ['id' => $ticket->id]));
160-
$response->assertStatus(200);
160+
$this->versionAssertStatus($response, 200);
161161
}
162162
}
163163
}

0 commit comments

Comments
 (0)