1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\AdminBundle\Tests\Helper\Security\Acl; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
6
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
7
|
|
|
use Doctrine\ORM\AbstractQuery; |
8
|
|
|
use Doctrine\ORM\Configuration; |
9
|
|
|
use Doctrine\ORM\EntityManager; |
10
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata; |
11
|
|
|
use Doctrine\ORM\Mapping\QuoteStrategy; |
12
|
|
|
use Doctrine\ORM\Query\AST\FromClause; |
13
|
|
|
use Doctrine\ORM\Query\AST\IdentificationVariableDeclaration; |
14
|
|
|
use Doctrine\ORM\Query\AST\IndexBy; |
15
|
|
|
use Doctrine\ORM\Query\AST\PathExpression; |
16
|
|
|
use Doctrine\ORM\Query\AST\RangeVariableDeclaration; |
17
|
|
|
use Doctrine\ORM\Query\ParserResult; |
18
|
|
|
use Doctrine\ORM\Query\ResultSetMapping; |
19
|
|
|
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclWalker; |
20
|
|
|
use PHPUnit\Framework\TestCase; |
21
|
|
|
|
22
|
|
|
class AclWalkerTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
public function testWalker() |
25
|
|
|
{ |
26
|
|
|
$range = new RangeVariableDeclaration('someschema', 's'); |
27
|
|
|
$expr = new PathExpression('int', 'id'); |
28
|
|
|
$indexBy = new IndexBy($expr); |
29
|
|
|
$from = new FromClause([new IdentificationVariableDeclaration($range, $indexBy, [])]); |
30
|
|
|
|
31
|
|
|
$meta = $this->createMock(ClassMetadata::class); |
32
|
|
|
$strategy = $this->createMock(QuoteStrategy::class); |
33
|
|
|
$config = $this->createMock(Configuration::class); |
34
|
|
|
|
35
|
|
|
$platform = $this->createMock(AbstractPlatform::class); |
36
|
|
|
$platform->expects($this->once())->method('appendLockHint')->willReturn($from); |
37
|
|
|
|
38
|
|
|
$conn = $this->createMock(Connection::class); |
39
|
|
|
$conn->expects($this->once())->method('getDatabasePlatform')->willReturn($platform); |
40
|
|
|
|
41
|
|
|
$em = $this->createMock(EntityManager::class); |
42
|
|
|
$query = $this->createMock(AbstractQuery::class); |
43
|
|
|
$mapping = $this->createMock(ResultSetMapping::class); |
44
|
|
|
$result = $this->createMock(ParserResult::class); |
45
|
|
|
|
46
|
|
|
$meta->expects($this->once())->method('getTableName')->willReturn('sometable'); |
47
|
|
|
$strategy->expects($this->once())->method('getTableName')->willReturn('sometable'); |
48
|
|
|
$config->expects($this->once())->method('getQuoteStrategy')->willReturn($strategy); |
49
|
|
|
|
50
|
|
|
$query->expects($this->once())->method('getEntityManager')->willReturn($em); |
51
|
|
|
$query->expects($this->exactly(4))->method('getHint')->will($this->onConsecutiveCalls('sometable', 'sometable', 's', null)); |
52
|
|
|
$em->expects($this->once())->method('getConnection')->willReturn($conn); |
53
|
|
|
$em->expects($this->once())->method('getConfiguration')->willReturn($config); |
54
|
|
|
$em->expects($this->once())->method('getClassMetaData')->willReturn($meta); |
55
|
|
|
$result->expects($this->once())->method('getResultSetMapping')->willReturn($mapping); |
56
|
|
|
|
57
|
|
|
$aclWalker = new AclWalker($query, $result, []); |
|
|
|
|
58
|
|
|
$sql = $aclWalker->walkFromClause($from); |
59
|
|
|
$this->assertRegExp('/(JOIN \(\) ta_ ON s0_\.id = ta_.id)$/', $sql); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: