-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
EventModelTest.php
96 lines (76 loc) · 2.35 KB
/
EventModelTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
declare(strict_types=1);
/*
* @copyright 2017 Mautic Contributors. All rights reserved
* @author Mautic, Inc.
*
* @link https://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
namespace Mautic\CampaignBundle\Tests\Model;
use Mautic\CampaignBundle\Entity\LeadEventLogRepository;
use Mautic\CampaignBundle\Model\EventModel;
use PHPUnit\Framework\TestCase;
class EventModelTest extends TestCase
{
/**
* @var LeadEventLogRepository
*/
private $leadEventLogRepository;
/**
* @var EventModel
*/
private $eventModel;
protected function setUp(): void
{
$this->eventModel = $this->getMockBuilder(EventModel::class)
->disableOriginalConstructor()
->onlyMethods([
'getRepository',
'getLeadEventLogRepository',
'deleteEntities',
])
->getMock();
$this->leadEventLogRepository = $this->createMock(LeadEventLogRepository::class);
}
public function testThatClonedEventsDoNotAttemptNullingParentInDeleteEvents(): void
{
$this->eventModel->expects($this->exactly(0))
->method('getRepository')
->willReturn($this->leadEventLogRepository);
$currentEvents = [
'new1',
'new2',
'new3',
];
$deletedEvents = [
'new1',
];
$this->eventModel->deleteEvents($currentEvents, $deletedEvents);
}
public function testThatItDeletesEventLogs(): void
{
$idToDelete = 'old1';
$this->eventModel->expects($this->once())
->method('getRepository')
->willReturn($this->leadEventLogRepository);
$this->eventModel->expects($this->once())
->method('getLeadEventLogRepository')
->willReturn($this->leadEventLogRepository);
$this->leadEventLogRepository->expects($this->once())
->method('removeEventLogs')
->with($idToDelete);
$this->eventModel->expects($this->once())
->method('deleteEntities')
->with([$idToDelete]);
$currentEvents = [
'new1',
];
$deletedEvents = [
'new1',
$idToDelete,
];
$this->eventModel->deleteEvents($currentEvents, $deletedEvents);
}
}