Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FrontendActionsFlushTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class FrontendActionsFlushTest extends \PHPUnit\Framework\TestCase
11 {
13  protected $model;
14 
17 
20 
23 
24  protected function setUp()
25  {
26  $this->productFrontendActionMock = $this->getMockBuilder(
27  \Magento\Catalog\Model\ResourceModel\ProductFrontendAction::class
28  )
29  ->disableOriginalConstructor()
30  ->getMock();
31  $this->frontendStorageConfigurationPoolMock = $this->getMockBuilder(
32  \Magento\Catalog\Model\FrontendStorageConfigurationPool::class
33  )
34  ->disableOriginalConstructor()
35  ->getMock();
36 
37  $this->objectManagerHelper = new ObjectManagerHelper($this);
38  $this->model = $this->objectManagerHelper->getObject(
39  \Magento\Catalog\Cron\FrontendActionsFlush::class,
40  [
41  'productFrontendActionResource' => $this->productFrontendActionMock,
42  'frontendStorageConfigurationPool' => $this->frontendStorageConfigurationPoolMock
43  ]
44  );
45  }
46 
47  public function testExecute()
48  {
49  $connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
50  $selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
51  $frontendConfiguration = $this->createMock(\Magento\Catalog\Model\FrontendStorageConfigurationInterface::class);
52 
53  $selectMock
54  ->expects($this->once())
55  ->method('from')
56  ->with('catalog_product_frontend_action', ['action_id', 'type_id'])
57  ->will($this->returnSelf());
58  $selectMock
59  ->expects($this->once())
60  ->method('group')
61  ->with('type_id')
62  ->willReturnSelf();
63 
64  $frontendConfiguration->expects($this->once())
65  ->method('get')
66  ->willReturn([
67  'lifetime' => 1500
68  ]);
69 
70  $this->frontendStorageConfigurationPoolMock->expects($this->once())
71  ->method('get')
72  ->with('recently_viewed_product')
73  ->willReturn($frontendConfiguration);
74  $this->productFrontendActionMock->expects($this->exactly(2))
75  ->method('getMainTable')
76  ->willReturn('catalog_product_frontend_action');
77  $this->productFrontendActionMock->expects($this->exactly(2))
78  ->method('getConnection')
79  ->willReturn($connectionMock);
80  $connectionMock->expects($this->once())
81  ->method('select')
82  ->willReturn($selectMock);
83  $connectionMock->expects($this->once())
84  ->method('fetchPairs')
85  ->with($selectMock)
86  ->willReturn([
87  'recently_viewed_product'
88  ]);
89 
90  $connectionMock->expects($this->once())
91  ->method('quoteInto')
92  ->with('added_at < ?', time() - 1500)
93  ->willReturn(['added_at < ?', time() - 1500]);
94  $connectionMock->expects($this->once())
95  ->method('delete')
96  ->with('catalog_product_frontend_action', [['added_at < ?', time() - 1500]]);
97 
98  $this->model->execute();
99  }
100 }