mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
added tests
This commit is contained in:
parent
8d4a595b75
commit
7c539d06c2
52
tests/Unit/JikanApiSearchableModelTest.php
Normal file
52
tests/Unit/JikanApiSearchableModelTest.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
final class JikanApiSearchableModelFixture extends \App\JikanApiSearchableModel
|
||||
{
|
||||
public string $titleAttributeNameFixture;
|
||||
|
||||
public function typesenseQueryBy(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTitleAttributeName(): string
|
||||
{
|
||||
return $this->titleAttributeNameFixture;
|
||||
}
|
||||
}
|
||||
|
||||
final class JikanApiSearchableModelTest extends TestCase
|
||||
{
|
||||
public function titleFieldDataProvider()
|
||||
{
|
||||
return [
|
||||
["name"],
|
||||
["username"],
|
||||
["title"]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider titleFieldDataProvider
|
||||
*/
|
||||
public function testGetCollectionSchemaShouldReturnSortableTitleFieldInSchemaConfig($titleAttributeNameFixture)
|
||||
{
|
||||
$fixture = new JikanApiSearchableModelFixture();
|
||||
$fixture->titleAttributeNameFixture = $titleAttributeNameFixture;
|
||||
$schema = $fixture->getCollectionSchema();
|
||||
|
||||
$this->assertArrayHasKey('fields', $schema);
|
||||
$this->assertArrayHasKey('name', $schema['fields'][1]);
|
||||
$this->assertArrayHasKey('type', $schema['fields'][1]);
|
||||
$this->assertArrayHasKey('sort', $schema['fields'][1]);
|
||||
$this->assertArrayHasKey('optional', $schema['fields'][1]);
|
||||
$this->assertEquals($titleAttributeNameFixture, $schema['fields'][1]['name']);
|
||||
$this->assertEquals('string', $schema['fields'][1]['type']);
|
||||
$this->assertTrue($schema['fields'][1]['sort']);
|
||||
$this->assertFalse($schema['fields'][1]['optional']);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user