2022-06-22 10:48:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace modules\Api\Rest\V1;
|
|
|
|
|
|
|
|
use App\Database\Seeds\FakeSinglePodcastApiSeeder;
|
|
|
|
use CodeIgniter\Test\CIUnitTestCase;
|
|
|
|
use CodeIgniter\Test\DatabaseTestTrait;
|
|
|
|
use CodeIgniter\Test\FeatureTestTrait;
|
|
|
|
|
|
|
|
class PodcastTest extends CIUnitTestCase
|
|
|
|
{
|
|
|
|
use FeatureTestTrait;
|
|
|
|
use DatabaseTestTrait;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $migrate = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $migrateOnce = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
protected $namespace;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $seed = 'FakeSinglePodcastApiSeeder';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $basePath = 'app/Database';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array<mixed>
|
|
|
|
*/
|
|
|
|
private array $podcast = [];
|
|
|
|
|
2022-10-17 14:17:50 +00:00
|
|
|
private readonly string $podcastApiUrl;
|
2022-06-22 10:48:58 +00:00
|
|
|
|
2023-02-22 16:29:45 +00:00
|
|
|
public function __construct(?string $name = null)
|
2022-06-22 10:48:58 +00:00
|
|
|
{
|
2023-02-22 16:29:45 +00:00
|
|
|
parent::__construct($name);
|
2022-06-22 10:48:58 +00:00
|
|
|
$this->podcast = FakeSinglePodcastApiSeeder::podcast();
|
|
|
|
$this->podcast['created_at'] = [];
|
|
|
|
$this->podcast['updated_at'] = [];
|
2022-06-29 16:19:22 +00:00
|
|
|
$this->podcastApiUrl = config('RestApi')
|
2022-06-22 10:48:58 +00:00
|
|
|
->gateway;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testList(): void
|
|
|
|
{
|
|
|
|
$result = $this->call('get', $this->podcastApiUrl . 'podcasts');
|
|
|
|
$result->assertStatus(200);
|
|
|
|
$result->assertHeader('Content-Type', 'application/json; charset=UTF-8');
|
|
|
|
$result->assertJSONFragment([
|
|
|
|
0 => $this->podcast,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testView(): void
|
|
|
|
{
|
|
|
|
$result = $this->call('get', $this->podcastApiUrl . 'podcasts/1');
|
|
|
|
$result->assertStatus(200);
|
|
|
|
$result->assertHeader('Content-Type', 'application/json; charset=UTF-8');
|
|
|
|
$result->assertJSONFragment($this->podcast);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testViewNotFound(): void
|
|
|
|
{
|
|
|
|
$result = $this->call('get', $this->podcastApiUrl . 'podcasts/2');
|
|
|
|
$result->assertStatus(404);
|
|
|
|
$result->assertJSONExact(
|
|
|
|
[
|
|
|
|
'status' => 404,
|
|
|
|
'error' => 404,
|
|
|
|
'messages' => [
|
|
|
|
'error' => 'Podcast not found',
|
|
|
|
],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$result->assertHeader('Content-Type', 'application/json; charset=UTF-8');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Refreshing database to fetch empty array of podcasts
|
|
|
|
*/
|
|
|
|
public function testListEmpty(): void
|
|
|
|
{
|
|
|
|
$this->regressDatabase();
|
|
|
|
$this->migrateDatabase();
|
|
|
|
$result = $this->call('get', $this->podcastApiUrl . 'podcasts');
|
|
|
|
$result->assertStatus(200);
|
|
|
|
$result->assertHeader('Content-Type', 'application/json; charset=UTF-8');
|
|
|
|
$result->assertJSONExact([]);
|
|
|
|
$this->seed($this->seed);
|
|
|
|
}
|
|
|
|
}
|