-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
861 additions
and
40 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HarmonyIO\DbalTest\Unit\QueryBuilder\Condition; | ||
|
||
use HarmonyIO\Dbal\QueryBuilder\Column\Field; | ||
use HarmonyIO\Dbal\QueryBuilder\Column\Value; | ||
use HarmonyIO\Dbal\QueryBuilder\Condition\InCondition; | ||
use HarmonyIO\Dbal\QueryBuilder\QuoteStyle; | ||
use HarmonyIO\PHPUnitExtension\TestCase; | ||
|
||
class InConditionTest extends TestCase | ||
{ | ||
/** @var QuoteStyle */ | ||
private $quoteStyle; | ||
|
||
//phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint | ||
public function setUp() | ||
{ | ||
$this->quoteStyle = new QuoteStyle(QuoteStyle::MYSQL); | ||
} | ||
|
||
public function testToSqlWithValueAsColumn(): void | ||
{ | ||
$condition = new InCondition(new Value($this->quoteStyle, 3), [1, 2, 3]); | ||
|
||
$this->assertSame('? IN (?, ?, ?)', $condition->toSql()); | ||
} | ||
|
||
public function testToSqlWithFieldAsColumn(): void | ||
{ | ||
$condition = new InCondition(new Field($this->quoteStyle, 'column', 'table'), [1, 2, 3]); | ||
|
||
$this->assertSame('`table`.`column` IN (?, ?, ?)', $condition->toSql()); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
tests/Unit/QueryBuilder/Condition/MatchingConditionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HarmonyIO\DbalTest\Unit\QueryBuilder\Condition; | ||
|
||
use HarmonyIO\Dbal\QueryBuilder\Column\Field; | ||
use HarmonyIO\Dbal\QueryBuilder\Column\Value; | ||
use HarmonyIO\Dbal\QueryBuilder\Condition\MatchingCondition; | ||
use HarmonyIO\Dbal\QueryBuilder\QuoteStyle; | ||
use HarmonyIO\PHPUnitExtension\TestCase; | ||
|
||
class MatchingConditionTest extends TestCase | ||
{ | ||
/** @var QuoteStyle */ | ||
private $quoteStyle; | ||
|
||
//phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint | ||
public function setUp() | ||
{ | ||
$this->quoteStyle = new QuoteStyle(QuoteStyle::MYSQL); | ||
} | ||
|
||
public function testToSqlWithValuesOnBothLeftAndRightSide(): void | ||
{ | ||
$this->assertSame( | ||
'? = ?', | ||
(new MatchingCondition(new Value($this->quoteStyle, 1), '=', new Value($this->quoteStyle, 1)))->toSql() | ||
); | ||
} | ||
|
||
public function testToSqlWithValueOnLeftSide(): void | ||
{ | ||
$condition = (new MatchingCondition( | ||
new Field($this->quoteStyle, 'column'), | ||
'=', | ||
new Value($this->quoteStyle, 1) | ||
)); | ||
|
||
$this->assertSame( | ||
'`column` = ?', | ||
$condition->toSql() | ||
); | ||
} | ||
|
||
public function testToSqlWithValueOnRightSide(): void | ||
{ | ||
$condition = (new MatchingCondition( | ||
new Value($this->quoteStyle, 1), | ||
'=', | ||
new Field($this->quoteStyle, 'column') | ||
)); | ||
|
||
$this->assertSame( | ||
'? = `column`', | ||
$condition->toSql() | ||
); | ||
} | ||
|
||
public function testToSqlWithLiteralValueOnRightSide(): void | ||
{ | ||
$condition = (new MatchingCondition( | ||
new Field($this->quoteStyle, 'column'), | ||
'=', | ||
1 | ||
)); | ||
|
||
$this->assertSame( | ||
'`column` = ?', | ||
$condition->toSql() | ||
); | ||
} | ||
|
||
public function testToSqlWithFieldsOnBothLeftAndRightSide(): void | ||
{ | ||
$condition = (new MatchingCondition( | ||
new Field($this->quoteStyle, 'column1'), | ||
'=', | ||
new Field($this->quoteStyle, 'column2') | ||
)); | ||
|
||
$this->assertSame( | ||
'`column1` = `column2`', | ||
$condition->toSql() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HarmonyIO\DbalTest\Unit\QueryBuilder\Condition; | ||
|
||
use HarmonyIO\Dbal\QueryBuilder\Column\Field; | ||
use HarmonyIO\Dbal\QueryBuilder\Column\Value; | ||
use HarmonyIO\Dbal\QueryBuilder\Condition\NotInCondition; | ||
use HarmonyIO\Dbal\QueryBuilder\QuoteStyle; | ||
use HarmonyIO\PHPUnitExtension\TestCase; | ||
|
||
class NotInConditionTest extends TestCase | ||
{ | ||
/** @var QuoteStyle */ | ||
private $quoteStyle; | ||
|
||
//phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint | ||
public function setUp() | ||
{ | ||
$this->quoteStyle = new QuoteStyle(QuoteStyle::MYSQL); | ||
} | ||
|
||
public function testToSqlWithValueAsColumn(): void | ||
{ | ||
$condition = new NotInCondition(new Value($this->quoteStyle, 3), [1, 2, 3]); | ||
|
||
$this->assertSame('? NOT IN (?, ?, ?)', $condition->toSql()); | ||
} | ||
|
||
public function testToSqlWithFieldAsColumn(): void | ||
{ | ||
$condition = new NotInCondition(new Field($this->quoteStyle, 'column', 'table'), [1, 2, 3]); | ||
|
||
$this->assertSame('`table`.`column` NOT IN (?, ?, ?)', $condition->toSql()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/Unit/QueryBuilder/Condition/NotNullConditionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HarmonyIO\DbalTest\Unit\QueryBuilder\Condition; | ||
|
||
use HarmonyIO\Dbal\QueryBuilder\Column\Field; | ||
use HarmonyIO\Dbal\QueryBuilder\Condition\NotNullCondition; | ||
use HarmonyIO\Dbal\QueryBuilder\QuoteStyle; | ||
use HarmonyIO\PHPUnitExtension\TestCase; | ||
|
||
class NotNullConditionTest extends TestCase | ||
{ | ||
/** @var QuoteStyle */ | ||
private $quoteStyle; | ||
|
||
//phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint | ||
public function setUp() | ||
{ | ||
$this->quoteStyle = new QuoteStyle(QuoteStyle::MYSQL); | ||
} | ||
|
||
public function testToSql(): void | ||
{ | ||
$condition = new NotNullCondition(new Field($this->quoteStyle, 'column', 'table')); | ||
|
||
$this->assertSame('`table`.`column` IS NOT NULL', $condition->toSql()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace HarmonyIO\DbalTest\Unit\QueryBuilder\Condition; | ||
|
||
use HarmonyIO\Dbal\QueryBuilder\Column\Field; | ||
use HarmonyIO\Dbal\QueryBuilder\Condition\NullCondition; | ||
use HarmonyIO\Dbal\QueryBuilder\QuoteStyle; | ||
use HarmonyIO\PHPUnitExtension\TestCase; | ||
|
||
class NullConditionTest extends TestCase | ||
{ | ||
/** @var QuoteStyle */ | ||
private $quoteStyle; | ||
|
||
//phpcs:ignore SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint | ||
public function setUp() | ||
{ | ||
$this->quoteStyle = new QuoteStyle(QuoteStyle::MYSQL); | ||
} | ||
|
||
public function testToSql(): void | ||
{ | ||
$condition = new NullCondition(new Field($this->quoteStyle, 'column', 'table')); | ||
|
||
$this->assertSame('`table`.`column` IS NULL', $condition->toSql()); | ||
} | ||
} |
Oops, something went wrong.