1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Artprima\QueryFiMemberOferBundle\Tests\Query\Condition; |
4
|
|
|
|
5
|
|
|
use Artprima\QueryFilterBundle\Query\Condition\MemberOf; |
6
|
|
|
use Artprima\QueryFilterBundle\Query\Filter; |
7
|
|
|
use Doctrine\ORM\Query\Expr; |
8
|
|
|
use Doctrine\ORM\QueryBuilder; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class MemberOfTest |
13
|
|
|
* |
14
|
|
|
* @author Denis Voytyuk <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class MemberOfTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
public function testGetExpr() |
19
|
|
|
{ |
20
|
|
|
$qb = $this->getMockBuilder(QueryBuilder::class) |
21
|
|
|
->disableOriginalConstructor() |
22
|
|
|
->getMock(); |
23
|
|
|
|
24
|
|
|
$qb |
25
|
|
|
->expects(self::once()) |
26
|
|
|
->method('expr') |
27
|
|
|
->willReturn(new Expr()); |
28
|
|
|
|
29
|
|
|
$qb |
30
|
|
|
->expects(self::once()) |
31
|
|
|
->method('setParameter') |
32
|
|
|
->with(0, ['1']) |
33
|
|
|
->willReturn($qb); |
34
|
|
|
|
35
|
|
|
$condition = new MemberOf(); |
36
|
|
|
|
37
|
|
|
$expr = $condition->getExpr($qb, 0, (new Filter()) |
38
|
|
|
->setField('t.dummy') |
39
|
|
|
->setX('1') |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
self::assertSame('?0 MEMBER OF t.dummy', (string)$expr); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testGetExprMultipleValues() |
46
|
|
|
{ |
47
|
|
|
$qb = $this->getMockBuilder(QueryBuilder::class) |
48
|
|
|
->disableOriginalConstructor() |
49
|
|
|
->getMock(); |
50
|
|
|
|
51
|
|
|
$qb |
52
|
|
|
->expects(self::once()) |
53
|
|
|
->method('expr') |
54
|
|
|
->willReturn(new Expr()); |
55
|
|
|
|
56
|
|
|
$qb |
57
|
|
|
->expects(self::once()) |
58
|
|
|
->method('setParameter') |
59
|
|
|
->with(0, ['1', '2', '3', '4', '5']) |
60
|
|
|
->willReturn($qb); |
61
|
|
|
|
62
|
|
|
$condition = new MemberOf(); |
63
|
|
|
|
64
|
|
|
$expr = $condition->getExpr($qb, 0, (new Filter()) |
65
|
|
|
->setField('t.dummy') |
66
|
|
|
->setX('1,2,3,4,5') |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
self::assertSame('?0 MEMBER OF t.dummy', (string)$expr); |
70
|
|
|
} |
71
|
|
|
} |