Compare commits
3 Commits
3a5a4c7a5c
...
7783b245df
| Author | SHA1 | Date |
|---|---|---|
|
|
7783b245df | 4 weeks ago |
|
|
79c0272cec | 1 month ago |
|
|
ff8b022454 | 1 month ago |
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kartierung\Repository\ResolutionStrategy;
|
||||
|
||||
use PDO;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
||||
abstract class SqliteBaseCase extends TestCase
|
||||
{
|
||||
private PDO $pdo;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$tmpfile = tempnam(sys_get_temp_dir(), 'kartierung.sqlite');
|
||||
$this->pdo = new \PDO("sqlite:/$tmpfile");
|
||||
}
|
||||
|
||||
protected function getPdo(): PDO
|
||||
{
|
||||
return $this->pdo;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue