2021-01-20 04:11:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Tests\Integration;
|
|
|
|
|
2021-01-31 03:12:22 +00:00
|
|
|
use Illuminate\Http\Response;
|
2021-01-20 04:11:00 +00:00
|
|
|
use Illuminate\Testing\Assert as PHPUnit;
|
2021-01-20 05:20:55 +00:00
|
|
|
use Pterodactyl\Exceptions\DisplayException;
|
|
|
|
use Illuminate\Validation\ValidationException;
|
2021-01-20 04:11:00 +00:00
|
|
|
use Illuminate\Testing\TestResponse as IlluminateTestResponse;
|
|
|
|
|
|
|
|
class TestResponse extends IlluminateTestResponse
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Overrides the default assert status logic to dump out the error to the
|
|
|
|
* test output if it is caused by a 500 level error and we were not specifically
|
|
|
|
* look for that status response.
|
|
|
|
*
|
|
|
|
* @param int $status
|
2021-01-23 20:33:34 +00:00
|
|
|
*
|
2021-01-20 04:11:00 +00:00
|
|
|
* @return \Pterodactyl\Tests\Integration\TestResponse
|
|
|
|
*/
|
|
|
|
public function assertStatus($status)
|
|
|
|
{
|
|
|
|
$actual = $this->getStatusCode();
|
|
|
|
|
|
|
|
// Dump the response to the screen before making the assertion which is going
|
|
|
|
// to fail so that debugging isn't such a nightmare.
|
|
|
|
if ($actual !== $status && $status !== 500) {
|
|
|
|
$this->dump();
|
2021-01-23 20:33:34 +00:00
|
|
|
if (!is_null($this->exception) && !$this->exception instanceof DisplayException && !$this->exception instanceof ValidationException) {
|
2022-05-29 21:52:14 +00:00
|
|
|
dump([
|
|
|
|
'exception_class' => get_class($this->exception),
|
|
|
|
'message' => $this->exception->getMessage(),
|
|
|
|
'trace' => $this->exception->getTrace(),
|
|
|
|
]);
|
2021-01-20 04:11:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PHPUnit::assertSame($actual, $status, "Expected status code {$status} but received {$actual}.");
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2021-01-31 03:12:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function assertForbidden()
|
|
|
|
{
|
|
|
|
return self::assertStatus(Response::HTTP_FORBIDDEN);
|
|
|
|
}
|
2021-01-20 04:11:00 +00:00
|
|
|
}
|