implement FindById, move to proper type alanysis on repository return types
parent
79c0272cec
commit
7783b245df
@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Kartierung\Repository\ResolutionStrategy;
|
||||||
|
|
||||||
|
use Kartierung\Analyze\Result\RepositoryMethod;
|
||||||
|
use PHPUnit\Framework\Attributes\Group;
|
||||||
|
|
||||||
|
class FindByIdTest extends SqliteBaseCase
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->getPdo()->exec(
|
||||||
|
"
|
||||||
|
CREATE TABLE SimpleEntity (
|
||||||
|
stringcol VARCHAR(250),
|
||||||
|
intcol INT
|
||||||
|
);
|
||||||
|
INSERT INTO SimpleEntity(stringcol, intcol)
|
||||||
|
VALUES ('dings', 1),
|
||||||
|
('bumms', 2),
|
||||||
|
('foobar', 3);
|
||||||
|
"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Group('integration')]
|
||||||
|
public function testSelectsFirstEntry(): void
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
$method = new RepositoryMethod(
|
||||||
|
query: '',
|
||||||
|
returnType: SimpleEntity::class,
|
||||||
|
returnsNullable: true,
|
||||||
|
returnListType: '',
|
||||||
|
name: '',
|
||||||
|
parameters: [],
|
||||||
|
resolutionStrategy: new FindById()
|
||||||
|
);
|
||||||
|
$query = $method->createQuery([1]);
|
||||||
|
|
||||||
|
// When
|
||||||
|
$result = $query->execute($this->getPdo());
|
||||||
|
|
||||||
|
// Then
|
||||||
|
$this->assertEquals(
|
||||||
|
new SimpleEntity(1, 'dings'),
|
||||||
|
$result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Group('integration')]
|
||||||
|
public function testSelectsThirdEntry(): void
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
$method = new RepositoryMethod(
|
||||||
|
query: '',
|
||||||
|
returnType: SimpleEntity::class,
|
||||||
|
returnsNullable: true,
|
||||||
|
returnListType: '',
|
||||||
|
name: '',
|
||||||
|
parameters: [],
|
||||||
|
resolutionStrategy: new FindById()
|
||||||
|
);
|
||||||
|
$query = $method->createQuery([3]);
|
||||||
|
|
||||||
|
// When
|
||||||
|
$result = $query->execute($this->getPdo());
|
||||||
|
|
||||||
|
// Then
|
||||||
|
$this->assertEquals(
|
||||||
|
new SimpleEntity(3, 'foobar'),
|
||||||
|
$result
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Group('integration')]
|
||||||
|
public function testSelectsNothingMatching(): void
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
$method = new RepositoryMethod(
|
||||||
|
query: '',
|
||||||
|
returnType: SimpleEntity::class,
|
||||||
|
returnsNullable: true,
|
||||||
|
returnListType: '',
|
||||||
|
name: '',
|
||||||
|
parameters: [],
|
||||||
|
resolutionStrategy: new FindById()
|
||||||
|
);
|
||||||
|
$query = $method->createQuery([4]);
|
||||||
|
|
||||||
|
// When
|
||||||
|
$result = $query->execute($this->getPdo());
|
||||||
|
|
||||||
|
// Then
|
||||||
|
$this->assertNull($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue