Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/tests/Integration/TestResponse.php
7458 views
1
<?php
2
3
namespace Pterodactyl\Tests\Integration;
4
5
use Illuminate\Http\Response;
6
use Illuminate\Testing\Assert as PHPUnit;
7
use Pterodactyl\Exceptions\DisplayException;
8
use Illuminate\Validation\ValidationException;
9
use Illuminate\Testing\TestResponse as IlluminateTestResponse;
10
11
class TestResponse extends IlluminateTestResponse
12
{
13
/**
14
* Overrides the default assert status logic to dump out the error to the
15
* test output if it is caused by a 500 level error, and we were not specifically
16
* look for that status response.
17
*/
18
public function assertStatus($status): TestResponse
19
{
20
$actual = $this->getStatusCode();
21
22
// Dump the response to the screen before making the assertion which is going
23
// to fail so that debugging isn't such a nightmare.
24
if ($actual !== $status && $status !== 500) {
25
$this->dump();
26
if (!is_null($this->exception) && !$this->exception instanceof DisplayException && !$this->exception instanceof ValidationException) {
27
dump([
28
'exception_class' => get_class($this->exception),
29
'message' => $this->exception->getMessage(),
30
'trace' => $this->exception->getTrace(),
31
]);
32
}
33
}
34
35
PHPUnit::assertSame($actual, $status, "Expected status code {$status} but received {$actual}.");
36
37
return $this;
38
}
39
40
public function assertForbidden(): self
41
{
42
return self::assertStatus(Response::HTTP_FORBIDDEN);
43
}
44
}
45
46