Make debugging test failures easier
This commit is contained in:
parent
9684456480
commit
eecd550c48
|
@ -15,6 +15,7 @@ use Pterodactyl\Models\Location;
|
||||||
use Pterodactyl\Models\Schedule;
|
use Pterodactyl\Models\Schedule;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Pterodactyl\Models\Allocation;
|
use Pterodactyl\Models\Allocation;
|
||||||
|
use Pterodactyl\Tests\Integration\TestResponse;
|
||||||
use Pterodactyl\Tests\Integration\IntegrationTestCase;
|
use Pterodactyl\Tests\Integration\IntegrationTestCase;
|
||||||
use Pterodactyl\Transformers\Api\Client\BaseClientTransformer;
|
use Pterodactyl\Transformers\Api\Client\BaseClientTransformer;
|
||||||
|
|
||||||
|
@ -44,6 +45,19 @@ abstract class ClientApiIntegrationTestCase extends IntegrationTestCase
|
||||||
CarbonImmutable::setTestNow(Carbon::now());
|
CarbonImmutable::setTestNow(Carbon::now());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override the default createTestResponse from Illuminate so that we can
|
||||||
|
* just dump 500-level errors to the screen in the tests without having
|
||||||
|
* to keep re-assigning variables.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Response $response
|
||||||
|
* @return \Illuminate\Testing\TestResponse
|
||||||
|
*/
|
||||||
|
protected function createTestResponse($response)
|
||||||
|
{
|
||||||
|
return TestResponse::fromBaseResponse($response);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a link to the specific resource using the client API.
|
* Returns a link to the specific resource using the client API.
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pterodactyl\Tests\Integration;
|
||||||
|
|
||||||
|
use Illuminate\Testing\Assert as PHPUnit;
|
||||||
|
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
|
||||||
|
* @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();
|
||||||
|
if (! is_null($this->exception)) {
|
||||||
|
dump($this->exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PHPUnit::assertSame($actual, $status, "Expected status code {$status} but received {$actual}.");
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue