6
6
namespace Magento \Cron \Test \Unit \Console \Command ;
7
7
8
8
use Magento \Cron \Console \Command \CronCommand ;
9
+ use Magento \Framework \App \DeploymentConfig ;
10
+ use Magento \Framework \App \ObjectManagerFactory ;
11
+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
9
12
use Symfony \Component \Console \Tester \CommandTester ;
10
13
11
14
class CronCommandTest extends \PHPUnit \Framework \TestCase
12
15
{
16
+ /**
17
+ * @var ObjectManagerFactory|MockObject
18
+ */
19
+ private $ objectManagerFactory ;
20
+
21
+ /**
22
+ * @var DeploymentConfig|MockObject
23
+ */
24
+ private $ deploymentConfigMock ;
25
+
26
+ protected function setUp ()
27
+ {
28
+ $ this ->objectManagerFactory = $ this ->createMock (ObjectManagerFactory::class);
29
+ $ this ->deploymentConfigMock = $ this ->createMock (DeploymentConfig::class);
30
+ }
31
+
13
32
/**
14
33
* Test command with disables cron
15
34
*
16
35
* @return void
17
36
*/
18
37
public function testExecuteWithDisabledCrons ()
19
38
{
20
- $ objectManagerFactory = $ this ->createMock (\Magento \Framework \App \ObjectManagerFactory::class);
21
- $ deploymentConfigMock = $ this ->createMock (\Magento \Framework \App \DeploymentConfig::class);
22
-
23
- $ objectManagerFactory ->expects ($ this ->never ())
39
+ $ this ->objectManagerFactory ->expects ($ this ->never ())
24
40
->method ('create ' );
25
- $ deploymentConfigMock ->expects ($ this ->once ())
41
+ $ this -> deploymentConfigMock ->expects ($ this ->once ())
26
42
->method ('get ' )
27
43
->with ('cron/enabled ' , 1 )
28
44
->willReturn (0 );
29
- $ commandTester = new CommandTester (new CronCommand ($ objectManagerFactory , $ deploymentConfigMock ));
45
+ $ commandTester = new CommandTester (
46
+ new CronCommand ($ this ->objectManagerFactory , $ this ->deploymentConfigMock )
47
+ );
30
48
$ commandTester ->execute ([]);
31
49
$ expectedMsg = 'Cron is disabled. Jobs were not run. ' . PHP_EOL ;
32
50
$ this ->assertEquals ($ expectedMsg , $ commandTester ->getDisplay ());
@@ -39,23 +57,23 @@ public function testExecuteWithDisabledCrons()
39
57
*/
40
58
public function testExecute ()
41
59
{
42
- $ objectManagerFactory = $ this ->createMock (\Magento \Framework \App \ObjectManagerFactory::class);
43
- $ deploymentConfigMock = $ this ->createMock (\Magento \Framework \App \DeploymentConfig::class);
44
60
$ objectManager = $ this ->createMock (\Magento \Framework \ObjectManagerInterface::class);
45
61
$ cron = $ this ->createMock (\Magento \Framework \App \Cron::class);
46
62
$ objectManager ->expects ($ this ->once ())
47
63
->method ('create ' )
48
64
->willReturn ($ cron );
49
65
$ cron ->expects ($ this ->once ())
50
66
->method ('launch ' );
51
- $ objectManagerFactory ->expects ($ this ->once ())
67
+ $ this -> objectManagerFactory ->expects ($ this ->once ())
52
68
->method ('create ' )
53
69
->willReturn ($ objectManager );
54
- $ deploymentConfigMock ->expects ($ this ->once ())
70
+ $ this -> deploymentConfigMock ->expects ($ this ->once ())
55
71
->method ('get ' )
56
72
->with ('cron/enabled ' , 1 )
57
73
->willReturn (1 );
58
- $ commandTester = new CommandTester (new CronCommand ($ objectManagerFactory , $ deploymentConfigMock ));
74
+ $ commandTester = new CommandTester (
75
+ new CronCommand ($ this ->objectManagerFactory , $ this ->deploymentConfigMock )
76
+ );
59
77
$ commandTester ->execute ([]);
60
78
$ expectedMsg = 'Ran jobs by schedule. ' . PHP_EOL ;
61
79
$ this ->assertEquals ($ expectedMsg , $ commandTester ->getDisplay ());
0 commit comments