Issues (3627)

CampaignBundle/Tests/Model/EventModelTest.php (3 issues)

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...
Deprecated Code introduced by
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 ignore-deprecated  annotation

34
        $this->eventModel = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(EventModel::class)

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