koel/tests/Feature/TestCase.php

40 lines
1.1 KiB
PHP
Raw Normal View History

2017-02-14 06:53:02 +00:00
<?php
2017-08-05 16:56:11 +00:00
namespace Tests\Feature;
2017-02-14 06:53:02 +00:00
use App\Models\User;
2020-09-06 18:21:39 +00:00
use Illuminate\Testing\TestResponse;
2020-09-09 16:18:53 +00:00
use Tests\TestCase as BaseTestCase;
2017-02-14 06:53:02 +00:00
2017-08-05 16:56:11 +00:00
abstract class TestCase extends BaseTestCase
2017-02-14 06:53:02 +00:00
{
2022-07-27 08:49:33 +00:00
private function jsonAs(?User $user, string $method, $uri, array $data = [], array $headers = []): TestResponse
2017-02-14 06:53:02 +00:00
{
2021-07-26 21:21:36 +00:00
/** @var User $user */
$user = $user ?: User::factory()->create();
2022-07-26 20:08:31 +00:00
$this->withToken($user->createToken('koel')->plainTextToken);
2020-09-06 18:21:39 +00:00
return parent::json($method, $uri, $data, $headers);
2017-02-14 06:53:02 +00:00
}
2022-07-27 08:49:33 +00:00
protected function getAs(string $url, ?User $user = null): TestResponse
2017-02-14 06:53:02 +00:00
{
2022-07-27 08:49:33 +00:00
return $this->jsonAs($user, 'get', $url);
2017-02-14 06:53:02 +00:00
}
2022-07-27 08:49:33 +00:00
protected function deleteAs(string $url, array $data = [], ?User $user = null): TestResponse
2017-02-14 06:53:02 +00:00
{
2022-07-27 08:49:33 +00:00
return $this->jsonAs($user, 'delete', $url, $data);
2017-02-14 06:53:02 +00:00
}
2022-07-27 08:49:33 +00:00
protected function postAs(string $url, array $data, ?User $user = null): TestResponse
2017-02-14 06:53:02 +00:00
{
2022-07-27 08:49:33 +00:00
return $this->jsonAs($user, 'post', $url, $data);
2017-02-14 06:53:02 +00:00
}
2022-07-27 08:49:33 +00:00
protected function putAs(string $url, array $data, ?User $user = null): TestResponse
2018-08-31 13:47:15 +00:00
{
2022-07-27 08:49:33 +00:00
return $this->jsonAs($user, 'put', $url, $data);
2018-08-31 13:47:15 +00:00
}
2017-02-14 06:53:02 +00:00
}