1 | <?php |
||||
2 | |||||
3 | namespace Mautic\LeadBundle\Tests\Model; |
||||
4 | |||||
5 | use Mautic\CoreBundle\Helper\Serializer; |
||||
6 | use Mautic\LeadBundle\Entity\LeadList; |
||||
7 | use Mautic\LeadBundle\Model\ListModel; |
||||
8 | |||||
9 | class LeadListModelTest extends \PHPUnit\Framework\TestCase |
||||
10 | { |
||||
11 | protected $fixture; |
||||
12 | |||||
13 | protected function setUp(): void |
||||
14 | { |
||||
15 | $mockListModel = $this->getMockBuilder(ListModel::class) |
||||
0 ignored issues
–
show
|
|||||
16 | ->disableOriginalConstructor() |
||||
17 | ->setMethods(['getEntities', 'getEntity']) |
||||
18 | ->getMock(); |
||||
19 | |||||
20 | $mockListModel->expects($this->any()) |
||||
21 | ->method('getEntity') |
||||
22 | ->willReturnCallback(function ($id) { |
||||
23 | $mockEntity = $this->getMockBuilder(LeadList::class) |
||||
0 ignored issues
–
show
The function
PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This function has been deprecated. The supplier of the function has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.
Loading history...
|
|||||
24 | ->disableOriginalConstructor() |
||||
25 | ->setMethods(['getName']) |
||||
26 | ->getMock(); |
||||
27 | |||||
28 | $mockEntity->expects($this->once()) |
||||
29 | ->method('getName') |
||||
30 | ->willReturn((string) $id); |
||||
31 | |||||
32 | return $mockEntity; |
||||
33 | }); |
||||
34 | |||||
35 | $filters = 'a:1:{i:0;a:7:{s:4:"glue";s:3:"and";s:5:"field";s:8:"leadlist";s:6:"object";s:4:"lead";s:4:"type";s:8:"leadlist";s:6:"filter";a:2:{i:0;i:1;i:1;i:3;}s:7:"display";N;s:8:"operator";s:2:"in";}}'; |
||||
36 | |||||
37 | $filters4 = 'a:1:{i:0;a:7:{s:4:"glue";s:3:"and";s:5:"field";s:8:"leadlist";s:6:"object";s:4:"lead";s:4:"type";s:8:"leadlist";s:6:"filter";a:1:{i:0;i:3;}s:7:"display";N;s:8:"operator";s:2:"in";}}'; |
||||
38 | |||||
39 | $mockEntity = $this->getMockBuilder(LeadList::class) |
||||
40 | ->disableOriginalConstructor() |
||||
41 | ->getMock(); |
||||
42 | |||||
43 | $mockEntity1 = clone $mockEntity; |
||||
44 | $mockEntity1->expects($this->once()) |
||||
45 | ->method('getFilters') |
||||
46 | ->willReturn([]); |
||||
47 | $mockEntity1->expects($this->any()) |
||||
48 | ->method('getId') |
||||
49 | ->willReturn(1); |
||||
50 | |||||
51 | $mockEntity2 = clone $mockEntity; |
||||
52 | $mockEntity2->expects($this->once()) |
||||
53 | ->method('getFilters') |
||||
54 | ->willReturn(Serializer::decode($filters)); |
||||
55 | $mockEntity2->expects($this->any()) |
||||
56 | ->method('getId') |
||||
57 | ->willReturn(2); |
||||
58 | |||||
59 | $mockEntity3 = clone $mockEntity; |
||||
60 | $mockEntity3->expects($this->once()) |
||||
61 | ->method('getFilters') |
||||
62 | ->willReturn([]); |
||||
63 | $mockEntity3->expects($this->any()) |
||||
64 | ->method('getId') |
||||
65 | ->willReturn(3); |
||||
66 | |||||
67 | $mockEntity4 = clone $mockEntity; |
||||
68 | $mockEntity4->expects($this->once()) |
||||
69 | ->method('getFilters') |
||||
70 | ->willReturn(Serializer::decode($filters4)); |
||||
71 | $mockEntity4->expects($this->any()) |
||||
72 | ->method('getId') |
||||
73 | ->willReturn(4); |
||||
74 | |||||
75 | $mockListModel->expects($this->once()) |
||||
76 | ->method('getEntities') |
||||
77 | ->willReturn([ |
||||
78 | 1 => $mockEntity1, |
||||
79 | 2 => $mockEntity2, |
||||
80 | 3 => $mockEntity3, |
||||
81 | 4 => $mockEntity4, |
||||
82 | ]); |
||||
83 | |||||
84 | $this->fixture = $mockListModel; |
||||
85 | } |
||||
86 | |||||
87 | /** |
||||
88 | * @dataProvider segmentTestDataProvider |
||||
89 | */ |
||||
90 | public function testSegmentsCanBeDeletedCorrecty(array $arg, array $expected, $message) |
||||
91 | { |
||||
92 | $result = $this->fixture->canNotBeDeleted($arg); |
||||
93 | |||||
94 | $this->assertEquals($expected, $result, $message); |
||||
95 | } |
||||
96 | |||||
97 | public function segmentTestDataProvider() |
||||
98 | { |
||||
99 | return [ |
||||
100 | [ |
||||
101 | [1], |
||||
102 | [1 => '1'], |
||||
103 | '2 is dependent on 1, so 1 cannot be deleted.', |
||||
104 | ], |
||||
105 | [ |
||||
106 | [1, 3], |
||||
107 | [1 => '1', 3 => '3'], |
||||
108 | '2 is dependent on 1 & 3, so 1 & 3 cannot be deleted.', |
||||
109 | ], |
||||
110 | [ |
||||
111 | [1, 2, 3, 4], |
||||
112 | [], |
||||
113 | 'Since we are deleting all segments, it should not prevent any from being deleted.', |
||||
114 | ], |
||||
115 | [ |
||||
116 | [2], |
||||
117 | [], |
||||
118 | 'Segments without any other segment dependent on them should always be able to be deleted.', |
||||
119 | ], |
||||
120 | ]; |
||||
121 | } |
||||
122 | } |
||||
123 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.