Skip to content

Commit 645cf23

Browse files
committed
MC-37093: Create automated test for "Collect data default data definition by cron"
1 parent 6bc8dc4 commit 645cf23

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Analytics\Cron;
9+
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Filesystem;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Checks data collection process behaviour
18+
*
19+
* @see \Magento\Analytics\Cron\CollectData
20+
*
21+
* @magentoAppArea adminhtml
22+
*/
23+
class CollectDataTest extends TestCase
24+
{
25+
/** @var ObjectManagerInterface */
26+
private $objectManager;
27+
28+
/** @var CollectData */
29+
private $collectDataService;
30+
31+
/** @var Filesystem */
32+
private $fileSystem;
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
protected function setUp(): void
38+
{
39+
parent::setUp();
40+
41+
$this->objectManager = Bootstrap::getObjectManager();
42+
$this->collectDataService = $this->objectManager->get(CollectData::class);
43+
$this->fileSystem = $this->objectManager->get(Filesystem::class);
44+
$this->removeAnalyticsDirectory();
45+
}
46+
47+
/**
48+
* @inheritdoc
49+
*/
50+
protected function tearDown(): void
51+
{
52+
$this->removeAnalyticsDirectory();
53+
54+
parent::tearDown();
55+
}
56+
57+
/**
58+
* @magentoConfigFixture current_store analytics/subscription/enabled 1
59+
* @magentoConfigFixture default/analytics/general/token 123
60+
*
61+
* @return void
62+
*/
63+
public function testExecute(): void
64+
{
65+
$this->collectDataService->execute();
66+
$mediaDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::MEDIA);
67+
$this->assertTrue(
68+
$mediaDirectory->isDirectory('analytics'),
69+
'Analytics was not created'
70+
);
71+
$files = $mediaDirectory->getDriver()->readDirectoryRecursively($mediaDirectory->getAbsolutePath('analytics'));
72+
$file = array_filter($files, function ($element) {
73+
return substr($element, -8) === 'data.tgz';
74+
});
75+
$this->assertNotEmpty($file, 'File was not created');
76+
}
77+
78+
/**
79+
* Remove Analytics directory
80+
*
81+
* @return void
82+
*/
83+
private function removeAnalyticsDirectory(): void
84+
{
85+
$mediaDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::MEDIA);
86+
$directoryToRemove = $mediaDirectory->getAbsolutePath('analytics');
87+
if ($mediaDirectory->isDirectory($directoryToRemove)) {
88+
$mediaDirectory->delete($directoryToRemove);
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)