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\QueryBuilder\Conditions\InCondition; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @group db |
12
|
|
|
*/ |
13
|
|
|
final class InConditionTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
public function testConstructor(): void |
16
|
|
|
{ |
17
|
|
|
$inCondition = new InCondition('id', 'IN', [1, 2, 3]); |
18
|
|
|
|
19
|
|
|
$this->assertSame('id', $inCondition->getColumn()); |
20
|
|
|
$this->assertSame('IN', $inCondition->getOperator()); |
21
|
|
|
$this->assertSame([1, 2, 3], $inCondition->getValues()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testFromArrayDefinition(): void |
25
|
|
|
{ |
26
|
|
|
$inCondition = InCondition::fromArrayDefinition('IN', ['id', [1, 2, 3]]); |
27
|
|
|
|
28
|
|
|
$this->assertSame('id', $inCondition->getColumn()); |
29
|
|
|
$this->assertSame('IN', $inCondition->getOperator()); |
30
|
|
|
$this->assertSame([1, 2, 3], $inCondition->getValues()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testFromArrayDefinitionException(): void |
34
|
|
|
{ |
35
|
|
|
$this->expectException(\Yiisoft\Db\Exception\InvalidArgumentException::class); |
36
|
|
|
$this->expectExceptionMessage("Operator 'IN' requires two operands."); |
37
|
|
|
InCondition::fromArrayDefinition('IN', []); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testFromArrayDefinitionExceptionColumn(): void |
41
|
|
|
{ |
42
|
|
|
$this->expectException(\Yiisoft\Db\Exception\InvalidArgumentException::class); |
43
|
|
|
$this->expectExceptionMessage("Operator 'IN' requires column to be string, array or Iterator."); |
44
|
|
|
InCondition::fromArrayDefinition('IN', [1, [1, 2, 3]]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testFromArrayDefinitionExceptionValues(): void |
48
|
|
|
{ |
49
|
|
|
$this->expectException(\Yiisoft\Db\Exception\InvalidArgumentException::class); |
50
|
|
|
$this->expectExceptionMessage( |
51
|
|
|
"Operator 'IN' requires values to be array, Iterator, int or QueryInterface." |
52
|
|
|
); |
53
|
|
|
InCondition::fromArrayDefinition('IN', ['id', false]); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|