Skip to content

Commit

Permalink
Add test failing test case for auraphp#177
Browse files Browse the repository at this point in the history
  • Loading branch information
harikt committed Feb 28, 2022
1 parent 2d3afee commit 617146d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/Parser/AbstractParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,24 @@ public function testIssue107()
$this->assertEquals($statement, $sql);
$this->assertEquals($values, $parameters);
}

public function testIn()
{
$parameters = ['types' => [1, 2]];
$sql = <<<SQL
SELECT * FROM table WHERE id IN (:types)
SQL;
list ($statement, $values) = $this->rebuild($sql, $parameters);

$expectedSql = <<<SQL
SELECT * FROM table WHERE id IN (:types_0, :types_1)
SQL;
$expectedParameters = [
'types_0' => 1,
'types_1' => 2
];

$this->assertEquals($expectedSql, $statement);
$this->assertEquals($expectedParameters, $values);
}
}
35 changes: 35 additions & 0 deletions tests/Parser/PgsqlParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,39 @@ public function testInvalidPlaceholderName()
list ($statement, $values) = $this->rebuild($sql, $parameters);
$this->assertEquals($sql, $statement);
}

public function testIssue177()
{
$parameters = ['types' => [1, 2]];
// AND
$sql = <<<SQL
SELECT * FROM table WHERE type in (:types) AND removed = false AND data @> '{\"is_hidden\":false}'::jsonb
SQL;
list ($statement, $values) = $this->rebuild($sql, $parameters);

$expectedSql = <<<SQL
SELECT * FROM table WHERE type in (:types_0, :types_1) AND removed = false AND data @> '{\"is_hidden\":false}'::jsonb
SQL;

$expectedParameters = [
'types_0' => 1,
'types_1' => 2
];

$this->assertEquals($expectedSql, $statement);
$this->assertEquals($expectedParameters, $values);

// change order
$sql = <<<SQL
SELECT * FROM table WHERE removed = false AND data @> '{\"is_hidden\":false}'::jsonb AND type in (:types)
SQL;
list ($statement, $values) = $this->rebuild($sql, $parameters);

$expectedSql = <<<SQL
SELECT * FROM table WHERE removed = false AND data @> '{\"is_hidden\":false}'::jsonb AND type in (:types_0, :types_1)
SQL;

$this->assertEquals($expectedSql, $statement);
$this->assertEquals($expectedParameters, $values);
}
}

0 comments on commit 617146d

Please sign in to comment.