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
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Persistent\Test\Unit\Observer;
class ClearExpiredCronJobObserverTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Persistent\Observer\ClearExpiredCronJobObserver
*/
protected $model;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $collectionFactoryMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $sessionFactoryMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $scheduleMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $websiteCollectionMock;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $sessionMock;
protected function setUp()
{
$this->collectionFactoryMock =
$this->createPartialMock(\Magento\Store\Model\ResourceModel\Website\CollectionFactory::class, ['create']);
$this->sessionFactoryMock = $this->createPartialMock(
\Magento\Persistent\Model\SessionFactory::class,
['create']
);
$this->scheduleMock = $this->createMock(\Magento\Cron\Model\Schedule::class);
$this->sessionMock = $this->createMock(\Magento\Persistent\Model\Session::class);
$this->websiteCollectionMock
= $this->createMock(\Magento\Store\Model\ResourceModel\Website\Collection::class);
$this->model = new \Magento\Persistent\Observer\ClearExpiredCronJobObserver(
$this->collectionFactoryMock,
$this->sessionFactoryMock
);
}
public function testExecute()
{
$this->collectionFactoryMock
->expects($this->once())
->method('create')
->will($this->returnValue($this->websiteCollectionMock));
$this->websiteCollectionMock->expects($this->once())->method('getAllIds')->will($this->returnValue([1]));
$this->sessionFactoryMock
->expects($this->once())
->method('create')
->will($this->returnValue($this->sessionMock));
$this->sessionMock->expects($this->once())->method('deleteExpired')->with(1);
$this->model->execute($this->scheduleMock);
}
public function testExecuteForNotExistingWebsite()
{
$this->collectionFactoryMock
->expects($this->once())
->method('create')
->will($this->returnValue($this->websiteCollectionMock));
$this->websiteCollectionMock->expects($this->once())->method('getAllIds');
$this->sessionFactoryMock
->expects($this->never())
->method('create');
$this->model->execute($this->scheduleMock);
}
}