Skip to content

Commit 01d374f

Browse files
rogyardmytro-ch
authored andcommitted
Added unit test for CRON converter plugin
1 parent 11f66c4 commit 01d374f

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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\Cron\Test\Unit\Model\System\Config\Initial;
9+
10+
use Magento\Cron\Model\Groups\Config\Data as GroupsConfigModel;
11+
use Magento\Cron\Model\System\Config\Initial\Converter as ConverterPlugin;
12+
use Magento\Framework\App\Config\Initial\Converter;
13+
14+
/**
15+
* Class ConverterTest
16+
*
17+
* Unit test for \Magento\Cron\Model\System\Config\Initial\Converter
18+
*/
19+
class ConverterTest extends \PHPUnit\Framework\TestCase
20+
{
21+
/**
22+
* @var GroupsConfigModel|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $groupsConfigMock;
25+
26+
/**
27+
* @var Converter|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $converterMock;
30+
31+
/**
32+
* @var ConverterPlugin
33+
*/
34+
private $converterPlugin;
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
protected function setUp()
40+
{
41+
$this->groupsConfigMock = $this->getMockBuilder(
42+
GroupsConfigModel::class
43+
)->disableOriginalConstructor()->getMock();
44+
$this->converterMock = $this->getMockBuilder(Converter::class)->getMock();
45+
$this->converterPlugin = new ConverterPlugin($this->groupsConfigMock);
46+
}
47+
48+
/**
49+
* Tests afterConvert method with no $result['data']['default']['system'] set
50+
*/
51+
public function testAfterConvertWithNoData()
52+
{
53+
$expectedResult = ['test'];
54+
$this->groupsConfigMock->expects($this->never())
55+
->method('get');
56+
57+
$result = $this->converterPlugin->afterConvert($this->converterMock, $expectedResult);
58+
59+
self::assertSame($expectedResult, $result);
60+
}
61+
62+
/**
63+
* Tests afterConvert method with $result['data']['default']['system'] set
64+
*/
65+
public function testAfterConvertWithData()
66+
{
67+
$groups = [
68+
'group1' => ['val1' => ['value' => '1']],
69+
'group2' => ['val2' => ['value' => '2']]
70+
];
71+
$expectedResult['data']['default']['system']['cron'] = [
72+
'group1' => [
73+
'val1' => '1'
74+
],
75+
'group2' => [
76+
'val2' => '2'
77+
]
78+
];
79+
$result['data']['default']['system']['cron'] = '1';
80+
81+
$this->groupsConfigMock->expects($this->once())
82+
->method('get')
83+
->willReturn($groups);
84+
85+
$result = $this->converterPlugin->afterConvert($this->converterMock, $result);
86+
87+
self::assertEquals($expectedResult, $result);
88+
}
89+
}

0 commit comments

Comments
 (0)