Skip to content

Commit

Permalink
Add tests with different operators
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed Nov 29, 2023
1 parent 32537f4 commit cc23e1e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Driver/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ protected function condition(QueryParameters $params, Quoter $q, array $context)

$placeholder = '?';
if ($value->isArray()) {
return $this->arrayToInOperator($params, $q, $value->getValue(), $operator === 'IN');
return $this->arrayToInOperator($params, $q, $value->getValue(), $operator === 'IN' || $operator === '=');
}

if ($value->isNull()) {
Expand Down
56 changes: 56 additions & 0 deletions tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,62 @@ public function testSelectWithFragmentedColumns(): void
);
}

public function testWhereInWithoutSpecifiedOperator(): void
{
$select = $this->database
->select()
->from(['users'])
->where(
'uuid',
new Parameter(['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013'])
);

$this->assertSameQuery('SELECT * FROM {users} WHERE {uuid} IN (?, ?)', $select);

$this->assertSameParameters(
['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013'],
$select,
);
}

public function testWhereInWithEqualSpecifiedOperator(): void
{
$select = $this->database
->select()
->from(['users'])
->where(
'uuid',
'=',
new Parameter(['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013'])
);

$this->assertSameQuery('SELECT * FROM {users} WHERE {uuid} IN (?, ?)', $select);

$this->assertSameParameters(
['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013'],
$select,
);
}

public function testWhereInWithNotEqualSpecifiedOperator(): void
{
$select = $this->database
->select()
->from(['users'])
->where(
'uuid',
'!=',
new Parameter(['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013'])
);

$this->assertSameQuery('SELECT * FROM {users} WHERE {uuid} NOT IN (?, ?)', $select);

$this->assertSameParameters(
['12345678-1234-1234-1234-123456789012', '12345678-1234-1234-1234-123456789013'],
$select,
);
}

public function testFragmentInWhereInClause(): void
{
$select = $this->database
Expand Down

0 comments on commit cc23e1e

Please sign in to comment.