Version 1.0.0
This commit is contained in:
44
tests/Storage/RepositoriesTest.php
Normal file
44
tests/Storage/RepositoriesTest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Diffhead\PHP\DataEnrichmentKit\Tests\Storage;
|
||||
|
||||
use Diffhead\PHP\DataEnrichmentKit\Exception\RepositoryNotFound;
|
||||
use Diffhead\PHP\DataEnrichmentKit\Interface\Repository;
|
||||
use Diffhead\PHP\DataEnrichmentKit\Storage\Repositories;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\CoversMethod;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(Repositories::class)]
|
||||
#[CoversMethod(Repositories::class, 'set')]
|
||||
#[CoversMethod(Repositories::class, 'get')]
|
||||
class RepositoriesTest extends TestCase
|
||||
{
|
||||
public function testSetAndGet(): void
|
||||
{
|
||||
$repositories = new Repositories();
|
||||
$mockRepository = new class implements Repository {
|
||||
public function getByFieldValues(string $field, array $values): array
|
||||
{
|
||||
return [
|
||||
['field' => $field, 'value' => $values[0]],
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
$repositories->set('target', $mockRepository);
|
||||
|
||||
$retrievedRepository = $repositories->get('target');
|
||||
$this->assertSame($mockRepository, $retrievedRepository);
|
||||
}
|
||||
|
||||
public function testGetThrowsExceptionWhenRepositoryNotFound(): void
|
||||
{
|
||||
$this->expectException(RepositoryNotFound::class);
|
||||
|
||||
$repositories = new Repositories();
|
||||
$repositories->get('nonexistent_target');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user