13 private $metadataPoolMock;
18 private $resourceConnectionMock;
23 private $dateTimeMock;
28 private $scopeConfigMock;
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,
51 $this->scopeConfigMock,
59 $connectionName =
'Connection';
60 $bulkLifetimeMultiplier = 10;
61 $bulkLifetime = 3600 * 24 * $bulkLifetimeMultiplier;
63 $adapterMock = $this->createMock(\
Magento\Framework\DB\Adapter\AdapterInterface::class);
64 $entityMetadataMock = $this->createMock(\
Magento\Framework\EntityManager\EntityMetadataInterface::class);
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');
77 $this->model->execute();