Changeset View
Changeset View
Standalone View
Standalone View
src/tests/TestCase.php
<?php | <?php | ||||
namespace Tests; | namespace Tests; | ||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | ||||
use Illuminate\Routing\Middleware\ThrottleRequests; | use Illuminate\Routing\Middleware\ThrottleRequests; | ||||
use Illuminate\Contracts\Auth\Authenticatable; | |||||
use Laravel\Passport\Passport; | |||||
abstract class TestCase extends BaseTestCase | abstract class TestCase extends BaseTestCase | ||||
{ | { | ||||
use TestCaseTrait; | use TestCaseTrait; | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
// Disable throttling | // Disable throttling | ||||
$this->withoutMiddleware(ThrottleRequests::class); | $this->withoutMiddleware(ThrottleRequests::class); | ||||
} | } | ||||
/** | /** | ||||
* Set the user as which we want to authenticate | |||||
*/ | |||||
public function actingAs(Authenticatable $user, $guard = null) | |||||
{ | |||||
Passport::actingAs( | |||||
$user, | |||||
['api'] | |||||
); | |||||
return parent::actingAs($user, $guard); | |||||
} | |||||
/** | |||||
* Set baseURL to the regular UI location | * Set baseURL to the regular UI location | ||||
*/ | */ | ||||
protected static function useRegularUrl(): void | protected static function useRegularUrl(): void | ||||
{ | { | ||||
// This will set base URL for all tests in a file. | // This will set base URL for all tests in a file. | ||||
// If we wanted to access both user and admin in one test | // If we wanted to access both user and admin in one test | ||||
// we can also just call post/get/whatever with full url | // we can also just call post/get/whatever with full url | ||||
\config( | \config( | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |