Passed
Push — staging ( 81b4f0...b25da5 )
by
unknown
24:23 queued 12:05
created

EventModelTest::testThatItDeletesEventLogs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 19
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 30
rs 9.6333
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * @copyright   2017 Mautic Contributors. All rights reserved
7
 * @author      Mautic, Inc.
8
 *
9
 * @link        https://mautic.org
10
 *
11
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Mautic\CampaignBundle\Tests\Model;
15
16
use Mautic\CampaignBundle\Entity\LeadEventLogRepository;
17
use Mautic\CampaignBundle\Model\EventModel;
18
use PHPUnit\Framework\TestCase;
19
20
class EventModelTest extends TestCase
21
{
22
    /**
23
     * @var LeadEventLogRepository
24
     */
25
    private $leadEventLogRepository;
26
27
    /**
28
     * @var EventModel
29
     */
30
    private $eventModel;
31
32
    protected function setUp(): void
33
    {
34
        $this->eventModel = $this->getMockBuilder(EventModel::class)
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder(Ma...eEntities'))->getMock() of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Mautic\CampaignBundle\Model\EventModel of property $eventModel.

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..

Loading history...
35
            ->disableOriginalConstructor()
36
            ->setMethods([
37
                'getRepository',
38
                'getLeadEventLogRepository',
39
                'deleteEntities',
40
            ])
41
            ->getMock();
42
43
        $this->leadEventLogRepository = $this->createMock(LeadEventLogRepository::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Mautic...ntLogRepository::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Mautic\CampaignBundle\En...\LeadEventLogRepository of property $leadEventLogRepository.

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..

Loading history...
44
    }
45
46
    public function testThatClonedEventsDoNotAttemptNullingParentInDeleteEvents(): void
47
    {
48
        $this->eventModel->expects($this->exactly(0))
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Mautic\CampaignBundle\Model\EventModel. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
        $this->eventModel->/** @scrutinizer ignore-call */ 
49
                           expects($this->exactly(0))

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
            ->method('getRepository')
50
            ->willReturn($this->leadEventLogRepository);
51
52
        $currentEvents = [
53
            'new1',
54
            'new2',
55
            'new3',
56
        ];
57
58
        $deletedEvents = [
59
            'new1',
60
        ];
61
62
        $this->eventModel->deleteEvents($currentEvents, $deletedEvents);
63
    }
64
65
    public function testThatItDeletesEventLogs(): void
66
    {
67
        $idToDelete = 'old1';
68
69
        $this->eventModel->expects($this->once())
70
            ->method('getRepository')
71
            ->willReturn($this->leadEventLogRepository);
72
73
        $this->eventModel->expects($this->once())
74
            ->method('getLeadEventLogRepository')
75
            ->willReturn($this->leadEventLogRepository);
76
77
        $this->leadEventLogRepository->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Mautic\CampaignBundle\En...\LeadEventLogRepository. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
        $this->leadEventLogRepository->/** @scrutinizer ignore-call */ 
78
                                       expects($this->once())
Loading history...
78
            ->method('removeEventLogs')
79
            ->with($idToDelete);
80
81
        $this->eventModel->expects($this->once())
82
            ->method('deleteEntities')
83
            ->with([$idToDelete]);
84
85
        $currentEvents = [
86
            'new1',
87
        ];
88
89
        $deletedEvents = [
90
            'new1',
91
            $idToDelete,
92
        ];
93
94
        $this->eventModel->deleteEvents($currentEvents, $deletedEvents);
95
    }
96
}
97