1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Tests\QueryBuilder\Condition; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Yiisoft\Db\Exception\InvalidArgumentException; |
9
|
|
|
use Yiisoft\Db\QueryBuilder\Condition\BetweenCondition; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @group db |
13
|
|
|
* |
14
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
15
|
|
|
*/ |
16
|
|
|
final class BetweenConditionTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
public function testConstructor(): void |
19
|
|
|
{ |
20
|
|
|
$betweenCondition = new BetweenCondition('date', 'BETWEEN', 1, 2); |
21
|
|
|
|
22
|
|
|
$this->assertSame('date', $betweenCondition->getColumn()); |
23
|
|
|
$this->assertSame('BETWEEN', $betweenCondition->getOperator()); |
24
|
|
|
$this->assertSame(1, $betweenCondition->getIntervalStart()); |
25
|
|
|
$this->assertSame(2, $betweenCondition->getIntervalEnd()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testFromArrayDefinition(): void |
29
|
|
|
{ |
30
|
|
|
$betweenCondition = BetweenCondition::fromArrayDefinition('BETWEEN', ['date', 1, 2]); |
31
|
|
|
|
32
|
|
|
$this->assertSame('date', $betweenCondition->getColumn()); |
33
|
|
|
$this->assertSame('BETWEEN', $betweenCondition->getOperator()); |
34
|
|
|
$this->assertSame(1, $betweenCondition->getIntervalStart()); |
35
|
|
|
$this->assertSame(2, $betweenCondition->getIntervalEnd()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testFromArrayDefinitionExceptionWithoutOperands(): void |
39
|
|
|
{ |
40
|
|
|
$this->expectException(InvalidArgumentException::class); |
41
|
|
|
$this->expectExceptionMessage("Operator 'between' requires three operands."); |
42
|
|
|
|
43
|
|
|
BetweenCondition::fromArrayDefinition('between', []); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testFromArrayDefinitionExceptionColumns(): void |
47
|
|
|
{ |
48
|
|
|
$this->expectException(InvalidArgumentException::class); |
49
|
|
|
$this->expectExceptionMessage("Operator 'between' requires column to be string or ExpressionInterface."); |
50
|
|
|
|
51
|
|
|
BetweenCondition::fromArrayDefinition('between', [1, 'min_value', 'max_value']); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|