feat: SearchManga endpoint + tests
This commit is contained in:
parent
6667cc224b
commit
ae0eac3197
34
tests/Domain/Manga/Adapter/InMemoryMangaProvider.php
Normal file
34
tests/Domain/Manga/Adapter/InMemoryMangaProvider.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Domain\Manga\Adapter;
|
||||
|
||||
use App\Domain\Manga\Domain\Contract\Provider\MangaProviderInterface;
|
||||
use App\Domain\Manga\Domain\Model\Manga;
|
||||
use App\Domain\Manga\Domain\Model\MangaCollection;
|
||||
|
||||
class InMemoryMangaProvider implements MangaProviderInterface
|
||||
{
|
||||
/** @var Manga[] */
|
||||
private array $mangas;
|
||||
|
||||
/**
|
||||
* @param Manga[] $mangas
|
||||
*/
|
||||
public function __construct(array $mangas = [])
|
||||
{
|
||||
$this->mangas = $mangas;
|
||||
}
|
||||
|
||||
public function search(string $title): MangaCollection
|
||||
{
|
||||
$results = array_filter(
|
||||
$this->mangas,
|
||||
fn (Manga $manga) => str_contains(
|
||||
strtolower($manga->getTitle()->getValue()),
|
||||
strtolower($title)
|
||||
)
|
||||
);
|
||||
|
||||
return new MangaCollection($results);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user