Skip to content

Commit eecd550

Browse files
committed
Make debugging test failures easier
1 parent 9684456 commit eecd550

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

tests/Integration/Api/Client/ClientApiIntegrationTestCase.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Pterodactyl\Models\Schedule;
1616
use Illuminate\Support\Collection;
1717
use Pterodactyl\Models\Allocation;
18+
use Pterodactyl\Tests\Integration\TestResponse;
1819
use Pterodactyl\Tests\Integration\IntegrationTestCase;
1920
use Pterodactyl\Transformers\Api\Client\BaseClientTransformer;
2021

@@ -44,6 +45,19 @@ public function setUp(): void
4445
CarbonImmutable::setTestNow(Carbon::now());
4546
}
4647

48+
/**
49+
* Override the default createTestResponse from Illuminate so that we can
50+
* just dump 500-level errors to the screen in the tests without having
51+
* to keep re-assigning variables.
52+
*
53+
* @param \Illuminate\Http\Response $response
54+
* @return \Illuminate\Testing\TestResponse
55+
*/
56+
protected function createTestResponse($response)
57+
{
58+
return TestResponse::fromBaseResponse($response);
59+
}
60+
4761
/**
4862
* Returns a link to the specific resource using the client API.
4963
*

tests/Integration/TestResponse.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Pterodactyl\Tests\Integration;
4+
5+
use Illuminate\Testing\Assert as PHPUnit;
6+
use Illuminate\Testing\TestResponse as IlluminateTestResponse;
7+
8+
class TestResponse extends IlluminateTestResponse
9+
{
10+
/**
11+
* Overrides the default assert status logic to dump out the error to the
12+
* test output if it is caused by a 500 level error and we were not specifically
13+
* look for that status response.
14+
*
15+
* @param int $status
16+
* @return \Pterodactyl\Tests\Integration\TestResponse
17+
*/
18+
public function assertStatus($status)
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)) {
27+
dump($this->exception);
28+
}
29+
}
30+
31+
PHPUnit::assertSame($actual, $status, "Expected status code {$status} but received {$actual}.");
32+
33+
return $this;
34+
}
35+
}

0 commit comments

Comments
 (0)