Skip to content

Commit

Permalink
style touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
pmjones committed Sep 25, 2023
1 parent 861e1b2 commit 561a43f
Showing 1 changed file with 61 additions and 49 deletions.
110 changes: 61 additions & 49 deletions tests/Relationship/ForeignCompositeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,70 @@
use Atlas\Pdo\Connection;
use Atlas\Query\Bind;
use Atlas\Table\Row;
use Atlas\Testing\Assertions;
use PHPUnit\Framework\TestCase;

final class ForeignCompositeTest extends TestCase
class ForeignCompositeTest extends TestCase
{
public function test()
{
$foreignStrategy = new ForeignComposite('test', [
'native1' => 'foreign1',
'native2' => 'foreign2',
]);
use Assertions;

$select = new class extends MapperSelect {
public function __construct()
{
parent::__construct(Connection::new('sqlite::memory:'), new Bind());
}
};
$foreignStrategy->modifySelect($select, [
new class extends Record {
public function __construct()
{
parent::__construct(
new class([
'id' => 1,
'native1' => 'n1',
'native2' => 'n2',
]) extends Row {
protected $cols = [
'id' => null,
'native1' => null,
'native2' => null,
];
}, new Related([]));
}
}
]);
public function test()
{
$foreignStrategy = new ForeignComposite('test', [
'native1' => 'foreign1',
'native2' => 'foreign2',
]);

$this->assertSame('SELECT
WHERE
( -- composite keys
("test"."foreign1" = :__1__ AND "test"."foreign2" = :__2__)
)', $select->getStatement());
$this->assertSame([
'__1__' => [
0 => 'n1',
1 => 2,
],
'__2__' => [
0 => 'n2',
1 => 2,
],
], $select->getBindValues());
}
$select = new class extends MapperSelect {
public function __construct()
{
parent::__construct(Connection::new('sqlite::memory:'), new Bind());
}
};

$foreignStrategy->modifySelect($select, [
new class extends Record {
public function __construct()
{
parent::__construct(
new class([
'id' => 1,
'native1' => 'n1',
'native2' => 'n2',
]) extends Row {
protected $cols = [
'id' => null,
'native1' => null,
'native2' => null,
];
}, new Related([]));
}
}
]);

$this->assertSameSql(
'SELECT
WHERE
( -- composite keys
("test"."foreign1" = :__1__ AND "test"."foreign2" = :__2__)
)
',
$select->getStatement()
);

$this->assertSame(
[
'__1__' => [
0 => 'n1',
1 => 2,
],
'__2__' => [
0 => 'n2',
1 => 2,
],
],
$select->getBindValues()
);
}
}

0 comments on commit 561a43f

Please sign in to comment.