Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
BulkCleanupTest.php
Go to the documentation of this file.
1 <?php
7 
8 class BulkCleanupTest extends \PHPUnit\Framework\TestCase
9 {
13  private $metadataPoolMock;
14 
18  private $resourceConnectionMock;
19 
23  private $dateTimeMock;
24 
28  private $scopeConfigMock;
29 
33  private $model;
34 
38  private $timeMock;
39 
40  protected function setUp()
41  {
42  $this->dateTimeMock = $this->createMock(\Magento\Framework\Stdlib\DateTime::class);
43  $this->scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
44  $this->resourceConnectionMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
45  $this->metadataPoolMock = $this->createMock(\Magento\Framework\EntityManager\MetadataPool::class);
46  $this->timeMock = $this->createMock(\Magento\Framework\Stdlib\DateTime\DateTime::class);
47  $this->model = new \Magento\AsynchronousOperations\Cron\BulkCleanup(
48  $this->metadataPoolMock,
49  $this->resourceConnectionMock,
50  $this->dateTimeMock,
51  $this->scopeConfigMock,
52  $this->timeMock
53  );
54  }
55 
56  public function testExecute()
57  {
58  $entityType = 'BulkSummaryInterface';
59  $connectionName = 'Connection';
60  $bulkLifetimeMultiplier = 10;
61  $bulkLifetime = 3600 * 24 * $bulkLifetimeMultiplier;
62 
63  $adapterMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
64  $entityMetadataMock = $this->createMock(\Magento\Framework\EntityManager\EntityMetadataInterface::class);
65 
66  $this->metadataPoolMock->expects($this->once())->method('getMetadata')->with($this->stringContains($entityType))
67  ->willReturn($entityMetadataMock);
68  $entityMetadataMock->expects($this->once())->method('getEntityConnectionName')->willReturn($connectionName);
69  $this->resourceConnectionMock->expects($this->once())->method('getConnectionByName')->with($connectionName)
70  ->willReturn($adapterMock);
71  $this->scopeConfigMock->expects($this->once())->method('getValue')->with($this->stringContains('bulk/lifetime'))
72  ->willReturn($bulkLifetimeMultiplier);
73  $this->timeMock->expects($this->once())->method('gmtTimestamp')->willReturn($bulkLifetime*10);
74  $this->dateTimeMock->expects($this->once())->method('formatDate')->with($bulkLifetime*9);
75  $adapterMock->expects($this->once())->method('delete');
76 
77  $this->model->execute();
78  }
79 }