1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\AttachmentBundle\Tests\Unit\Provider; |
4
|
|
|
|
5
|
|
|
use Oro\Bundle\AttachmentBundle\Provider\AttachmentProvider; |
6
|
|
|
use Oro\Bundle\AttachmentBundle\Tests\Unit\Fixtures\TestClass; |
7
|
|
|
|
8
|
|
|
class AttachmentProviderTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
11
|
|
|
protected $em; |
12
|
|
|
|
13
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */ |
14
|
|
|
protected $attachmentAssociationHelper; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var AttachmentProvider|\PHPUnit_Framework_MockObject_MockObject |
18
|
|
|
*/ |
19
|
|
|
protected $attachmentProvider; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMock(); |
26
|
|
|
|
27
|
|
|
$this->attachmentAssociationHelper = $this |
28
|
|
|
->getMockBuilder('Oro\Bundle\AttachmentBundle\Tools\AttachmentAssociationHelper') |
29
|
|
|
->disableOriginalConstructor() |
30
|
|
|
->getMock(); |
31
|
|
|
|
32
|
|
|
$this->attachmentProvider = new AttachmentProvider($this->em, $this->attachmentAssociationHelper); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetEntityAttachments() |
36
|
|
|
{ |
37
|
|
|
$entity = new TestClass(); |
38
|
|
|
|
39
|
|
|
$this->attachmentAssociationHelper->expects($this->once()) |
40
|
|
|
->method('isAttachmentAssociationEnabled') |
41
|
|
|
->with(get_class($entity)) |
42
|
|
|
->willReturn(true); |
43
|
|
|
|
44
|
|
|
$repo = $this->getMockBuilder('Doctrine\ORM\EntityRepository') |
45
|
|
|
->disableOriginalConstructor() |
46
|
|
|
->getMock(); |
47
|
|
|
|
48
|
|
|
$this->em->expects($this->once()) |
49
|
|
|
->method('getRepository') |
50
|
|
|
->with('OroAttachmentBundle:Attachment') |
51
|
|
|
->willReturn($repo); |
52
|
|
|
|
53
|
|
|
$qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder') |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->getMock(); |
56
|
|
|
|
57
|
|
|
$qb->expects($this->once()) |
58
|
|
|
->method('leftJoin') |
59
|
|
|
->willReturn($qb); |
60
|
|
|
|
61
|
|
|
$qb->expects($this->once()) |
62
|
|
|
->method('where') |
63
|
|
|
->willReturn($qb); |
64
|
|
|
|
65
|
|
|
$qb->expects($this->once()) |
66
|
|
|
->method('setParameter') |
67
|
|
|
->willReturn($qb); |
68
|
|
|
|
69
|
|
|
$query = $this->getMockBuilder('Doctrine\ORM\AbstractQuery') |
70
|
|
|
->disableOriginalConstructor() |
71
|
|
|
->setMethods(['getSQL', 'getResult', '_doExecute']) |
72
|
|
|
->getMock(); |
73
|
|
|
|
74
|
|
|
$query->expects($this->once()) |
75
|
|
|
->method('getResult') |
76
|
|
|
->willReturn('result'); |
77
|
|
|
|
78
|
|
|
$qb->expects($this->once()) |
79
|
|
|
->method('getQuery') |
80
|
|
|
->willReturn($query); |
81
|
|
|
|
82
|
|
|
$repo->expects($this->once()) |
83
|
|
|
->method('createQueryBuilder') |
84
|
|
|
->with('a') |
85
|
|
|
->willReturn($qb); |
86
|
|
|
|
87
|
|
|
$result = $this->attachmentProvider->getEntityAttachments($entity); |
88
|
|
|
$this->assertEquals('result', $result); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testUnsupportedAttachments() |
92
|
|
|
{ |
93
|
|
|
$entity = new TestClass(); |
94
|
|
|
|
95
|
|
|
$this->attachmentAssociationHelper->expects($this->once()) |
96
|
|
|
->method('isAttachmentAssociationEnabled') |
97
|
|
|
->with(get_class($entity)) |
98
|
|
|
->willReturn(false); |
99
|
|
|
|
100
|
|
|
$result = $this->attachmentProvider->getEntityAttachments($entity); |
101
|
|
|
$this->assertEquals([], $result); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..