Skip to content

Commit

Permalink
Dump exception if dying on 500 during tests. (#1612)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Dec 5, 2022
1 parent 4fe60a1 commit d87c867
Show file tree
Hide file tree
Showing 22 changed files with 213 additions and 128 deletions.
31 changes: 15 additions & 16 deletions tests/Feature/ApiTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace Tests\Feature;

use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Tests\Feature\Lib\UsersUnitTest;
Expand Down Expand Up @@ -43,12 +42,12 @@ public function testAuthenticateWithTokenOnly(): void
$token = $this->resetAdminToken();

$response = $this->postJson('/api/User::getAuthenticatedUser');
$response->assertStatus(204);
$this->assertStatus($response, 204);

$response = $this->postJson('/api/User::getAuthenticatedUser', [], [
'Authorization' => $token,
]);
$response->assertStatus(200);
$this->assertStatus($response, 200);
$response->assertSee([
'id' => 0,
], false);
Expand All @@ -71,7 +70,7 @@ public function testChangeOfTokensWithoutSession(): void
$response = $this->postJson('/api/User::getAuthenticatedUser', [], [
'Authorization' => $adminToken,
]);
$response->assertStatus(200);
$this->assertStatus($response, 200);
$response->assertSee([
'id' => 0,
], false);
Expand All @@ -90,7 +89,7 @@ public function testChangeOfTokensWithoutSession(): void
$response = $this->postJson('/api/User::getAuthenticatedUser', [], [
'Authorization' => $userToken,
]);
$response->assertStatus(200);
$this->assertStatus($response, 200);
$response->assertSee([
'id' => $userId,
], false);
Expand All @@ -111,7 +110,7 @@ public function testForbiddenChangeOfTokensInSameSession(): void
$response = $this->postJson('/api/User::getAuthenticatedUser', [], [
'Authorization' => $adminToken,
]);
$response->assertStatus(200);
$this->assertStatus($response, 200);
$response->assertSee([
'id' => 0,
], false);
Expand All @@ -134,7 +133,7 @@ public function testForbiddenChangeOfTokensInSameSession(): void
$response = $this->postJson('/api/User::getAuthenticatedUser', [], [
'Authorization' => $userToken,
]);
$response->assertStatus(401);
$this->assertStatus($response, 401);
}

/**
Expand All @@ -153,7 +152,7 @@ public function testLoginAndLogoutWithToken(): void
$response = $this->postJson('/api/User::getAuthenticatedUser', [], [
'Authorization' => $userToken,
]);
$response->assertStatus(200);
$this->assertStatus($response, 200);
$response->assertSee([
'id' => $userId,
], false);
Expand All @@ -174,13 +173,13 @@ public function testLoginAndLogoutWithToken(): void
], [
'Authorization' => $userToken,
]);
$response->assertStatus(204);
$this->assertStatus($response, 204);

Auth::forgetGuards();

// Ensure that we are still logged in even without providing the token
$response = $this->postJson('/api/User::getAuthenticatedUser');
$response->assertStatus(200);
$this->assertStatus($response, 200);
$response->assertSee([
'id' => $userId,
], false);
Expand All @@ -191,13 +190,13 @@ public function testLoginAndLogoutWithToken(): void
$response = $this->postJson('/api/Session::logout', [], [
'Authorization' => $userToken,
]);
$response->assertStatus(204);
$this->assertStatus($response, 204);

Auth::forgetGuards();

// Ensure that we are logged out without the token
$response = $this->postJson('/api/User::getAuthenticatedUser');
$response->assertStatus(204);
$this->assertStatus($response, 204);
}

/**
Expand All @@ -217,7 +216,7 @@ public function testLoginWithDifferentUserThanToken(): void
], [
'Authorization' => $userToken2,
]);
$response->assertStatus(400);
$this->assertStatus($response, 400);
}

/**
Expand All @@ -236,9 +235,9 @@ public function testProvideDifferentTokenThanLogin(): void
'username' => 'user1',
'password' => 'pwd1',
]);
$response->assertStatus(204);
$this->assertStatus($response, 204);
$response = $this->postJson('/api/User::getAuthenticatedUser');
$response->assertStatus(200);
$this->assertStatus($response, 200);
$response->assertSee([
'id' => $userId1,
], false);
Expand All @@ -256,7 +255,7 @@ public function testProvideDifferentTokenThanLogin(): void
$response = $this->postJson('/api/User::getAuthenticatedUser', [], [
'Authorization' => $userToken2,
]);
$response->assertStatus(400);
$this->assertStatus($response, 400);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/DemoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function testDemo0(): void

// check redirection
$response = $this->get('/demo');
$response->assertStatus(302);
$this->assertStatus($response, 302);
$response->assertRedirect('/');

// set back to initial value
Expand All @@ -54,7 +54,7 @@ public function testDemo1()

// check redirection
$response = $this->get('/demo');
$response->assertOk();
$this->assertOk($response);
$response->assertViewIs('demo');

// set back to initial value
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/DiagnosticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ class DiagnosticsTest extends TestCase
public function testDiagnostics(): void
{
$response = $this->get('/Diagnostics');
$response->assertOk(); // code 200 something
$this->assertOk($response); // code 200 something

Auth::loginUsingId(0);

$response = $this->get('/Diagnostics');
$response->assertOk(); // code 200 something
$this->assertOk($response); // code 200 something

Configs::query()->where('key', '=', 'lossless_optimization')->update(['value' => null]);

$response = $this->postJson('/api/Diagnostics::get');
$response->assertOk(); // code 200 something too
$this->assertOk($response); // code 200 something too

$response = $this->postJson('/api/Diagnostics::getSize');
$response->assertOk(); // code 200 something too
$this->assertOk($response); // code 200 something too

Configs::query()->where('key', '=', 'lossless_optimization')->update(['value' => '1']);

Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public function testHome(): void
* check if we can actually get a nice answer.
*/
$response = $this->get('/');
$response->assertOk();
$this->assertOk($response);

$response = $this->postJson('/api/Albums::get');
$response->assertOk();
$this->assertOk($response);
}

/**
Expand All @@ -47,7 +47,7 @@ public function testPhpInfo(): void
Session::flush();
// we don't want a non admin to access this
$response = $this->get('/phpinfo');
$response->assertForbidden();
$this->assertForbidden($response);
}

public function testLandingPage(): void
Expand All @@ -56,11 +56,11 @@ public function testLandingPage(): void
Configs::set('landing_page_enable', 1);

$response = $this->get('/');
$response->assertOk();
$this->assertOk($response);
$response->assertViewIs('landing');

$response = $this->get('/gallery');
$response->assertOk();
$this->assertOk($response);

Configs::set('landing_page_enable', $landing_on_off);
}
Expand Down
22 changes: 11 additions & 11 deletions tests/Feature/InstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testInstall(): void
$prevAppKey = config('app.key');
config(['app.key' => null]);
$response = $this->get('install/');
$response->assertOk();
$this->assertOk($response);
config(['app.key' => $prevAppKey]);

// TODO: Why does a `git pull` delete `installed.log`? This test needs to be discussed with @ildyria
Expand All @@ -47,7 +47,7 @@ public function testInstall(): void
* No installed.log: we should not be redirected to install (case where we have not done the last migration).
*/
$response = $this->get('/');
$response->assertOk();
$this->assertOk($response);

/*
* Clearing things up. We could do an Artisan migrate but this is more efficient.
Expand Down Expand Up @@ -88,35 +88,35 @@ public function testInstall(): void
* No database: we should be redirected to install: default case.
*/
$response = $this->get('/');
$response->assertStatus(307);
$this->assertStatus($response, 307);
$response->assertRedirect('install/');

/**
* Check the welcome page.
*/
$response = $this->get('install/');
$response->assertOk();
$this->assertOk($response);
$response->assertViewIs('install.welcome');

/**
* Check the requirements page.
*/
$response = $this->get('install/req');
$response->assertOk();
$this->assertOk($response);
$response->assertViewIs('install.requirements');

/**
* Check the permissions page.
*/
$response = $this->get('install/perm');
$response->assertOk();
$this->assertOk($response);
$response->assertViewIs('install.permissions');

/**
* Check the env page.
*/
$response = $this->get('install/env');
$response->assertOk();
$this->assertOk($response);
$response->assertViewIs('install.env');

$env = file_get_contents(base_path('.env'));
Expand All @@ -125,28 +125,28 @@ public function testInstall(): void
* POST '.env' the env page.
*/
$response = $this->post('install/env', ['envConfig' => $env]);
$response->assertOk();
$this->assertOk($response);
$response->assertViewIs('install.env');

/**
* apply migration.
*/
$response = $this->get('install/migrate');
$response->assertOk();
$this->assertOk($response);
$response->assertViewIs('install.migrate');

/**
* Re-Installation should be forbidden now.
*/
$response = $this->get('install/');
$response->assertForbidden();
$this->assertForbidden($response);

/**
* We now should NOT be redirected.
*/
Configs::invalidateCache();
$response = $this->get('/');
$response->assertOk();
$this->assertOk($response);

$admin->save();
$admin->id = 0;
Expand Down
Loading

0 comments on commit d87c867

Please sign in to comment.