mirror of
https://github.com/koel/koel
synced 2024-12-21 10:03:10 +00:00
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Testing\TestResponse;
|
|
use Tests\TestCase as BaseTestCase;
|
|
|
|
abstract class TestCase extends BaseTestCase
|
|
{
|
|
private function jsonAsUser(?User $user, string $method, $uri, array $data = [], array $headers = []): TestResponse
|
|
{
|
|
/** @var User $user */
|
|
$user = $user ?: User::factory()->create();
|
|
$headers['X-Requested-With'] = 'XMLHttpRequest';
|
|
$headers['Authorization'] = 'Bearer ' . $user->createToken('koel')->plainTextToken;
|
|
|
|
return parent::json($method, $uri, $data, $headers);
|
|
}
|
|
|
|
protected function getAsUser(string $url, ?User $user = null): TestResponse
|
|
{
|
|
return $this->jsonAsUser($user, 'get', $url);
|
|
}
|
|
|
|
protected function deleteAsUser(string $url, array $data = [], ?User $user = null): TestResponse
|
|
{
|
|
return $this->jsonAsUser($user, 'delete', $url, $data);
|
|
}
|
|
|
|
protected function postAsUser(string $url, array $data, ?User $user = null): TestResponse
|
|
{
|
|
return $this->jsonAsUser($user, 'post', $url, $data);
|
|
}
|
|
|
|
protected function putAsUser(string $url, array $data, ?User $user = null): TestResponse
|
|
{
|
|
return $this->jsonAsUser($user, 'put', $url, $data);
|
|
}
|
|
}
|