|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Doctrine\Tests\ORM\Persisters\Collection\Expr; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\Expr\Comparison; |
|
8
|
|
|
use Doctrine\Common\Collections\Expr\Value; |
|
9
|
|
|
use Doctrine\Common\Collections\Expr\CompositeExpression; |
|
10
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
|
11
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
|
12
|
|
|
use Doctrine\ORM\Mapping\QuoteStrategy; |
|
13
|
|
|
use Doctrine\ORM\Persisters\Collection\Expr\MappingVisitor; |
|
14
|
|
|
|
|
15
|
|
|
class MappingVisitorTest extends \PHPUnit_Framework_TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var QuoteStrategy */ |
|
18
|
|
|
private $quoteStrategy; |
|
19
|
|
|
/** @var MappingVisitor */ |
|
20
|
|
|
private $sut; |
|
21
|
|
|
|
|
22
|
|
|
protected function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
parent::setUp(); |
|
25
|
|
|
|
|
26
|
|
|
/** @var ClassMetadata $metadata */ |
|
27
|
|
|
$metadata = $this->getMockBuilder('\Doctrine\ORM\Mapping\ClassMetadata') |
|
28
|
|
|
->disableOriginalConstructor() |
|
29
|
|
|
->getMock(); |
|
30
|
|
|
|
|
31
|
|
|
/** @var AbstractPlatform $platform */ |
|
32
|
|
|
$platform = $this->getMockBuilder('\Doctrine\DBAL\Platforms\AbstractPlatform') |
|
33
|
|
|
->disableOriginalConstructor() |
|
34
|
|
|
->getMock(); |
|
35
|
|
|
|
|
36
|
|
|
$this->quoteStrategy = $this->getMockBuilder('\Doctrine\ORM\Mapping\QuoteStrategy') |
|
37
|
|
|
->getMock(); |
|
38
|
|
|
|
|
39
|
|
|
$this->quoteStrategy->expects($this->any()) |
|
40
|
|
|
->method('getColumnName') |
|
41
|
|
|
->with('field', $metadata, $platform) |
|
42
|
|
|
->willReturn('column'); |
|
43
|
|
|
|
|
44
|
|
|
$this->sut = new MappingVisitor( |
|
45
|
|
|
$this->quoteStrategy, |
|
46
|
|
|
$metadata, |
|
47
|
|
|
$platform |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
public function testWalkComparisonReturnsComparisonWithMappedField() |
|
53
|
|
|
{ |
|
54
|
|
|
$expr = new Comparison('field', Comparison::GT, 73); |
|
55
|
|
|
/** @var Comparison $mapped */ |
|
56
|
|
|
$mapped = $this->sut->dispatch($expr); |
|
57
|
|
|
static::assertInstanceOf('\Doctrine\Common\Collections\Expr\Comparison', $mapped); |
|
58
|
|
|
static::assertEquals('column', $mapped->getField()); |
|
59
|
|
|
static::assertEquals($expr->getOperator(), $mapped->getOperator()); |
|
60
|
|
|
static::assertEquals($expr->getValue(), $mapped->getValue()); |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testWalkValueReturnsValue() |
|
65
|
|
|
{ |
|
66
|
|
|
$value = new Value('foo'); |
|
67
|
|
|
static::assertSame($value, $this->sut->dispatch($value)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testWalkCompositeExpressionReturnsMappedCompositeExpression() |
|
71
|
|
|
{ |
|
72
|
|
|
$gtExpr = new Comparison('field', Comparison::GT, 73); |
|
73
|
|
|
$ltExpr = new Comparison('field', Comparison::LT, 53); |
|
74
|
|
|
|
|
75
|
|
|
$composite = new CompositeExpression( |
|
76
|
|
|
CompositeExpression::TYPE_OR, [$gtExpr, $ltExpr]); |
|
77
|
|
|
|
|
78
|
|
|
/** @var CompositeExpression $mapped */ |
|
79
|
|
|
$mapped = $this->sut->dispatch($composite); |
|
80
|
|
|
static::assertInstanceOf('\Doctrine\Common\Collections\Expr\CompositeExpression', $mapped); |
|
81
|
|
|
/** @var Comparison[]|Value[] $mappedExpressions */ |
|
82
|
|
|
$mappedExpressions = $mapped->getExpressionList(); |
|
83
|
|
|
|
|
84
|
|
|
static::assertCount(2, $mappedExpressions); |
|
85
|
|
|
|
|
86
|
|
|
static::assertInstanceOf('\Doctrine\Common\Collections\Expr\Comparison', $mappedExpressions[0]); |
|
87
|
|
|
static::assertInstanceOf('\Doctrine\Common\Collections\Expr\Comparison', $mappedExpressions[1]); |
|
88
|
|
|
|
|
89
|
|
|
static::assertEquals('column', $mappedExpressions[0]->getField()); |
|
|
|
|
|
|
90
|
|
|
static::assertEquals('column', $mappedExpressions[1]->getField()); |
|
91
|
|
|
|
|
92
|
|
|
static::assertEquals($gtExpr->getOperator(), $mappedExpressions[0]->getOperator()); |
|
|
|
|
|
|
93
|
|
|
static::assertEquals($ltExpr->getOperator(), $mappedExpressions[1]->getOperator()); |
|
94
|
|
|
|
|
95
|
|
|
static::assertEquals($gtExpr->getValue(), $mappedExpressions[0]->getValue()); |
|
96
|
|
|
static::assertEquals($ltExpr->getValue(), $mappedExpressions[1]->getValue()); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: