Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CronScriptReadinessCheckTest.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class CronScriptReadinessCheckTest extends \PHPUnit\Framework\TestCase
14 {
18  private $read;
19 
23  private $cronScriptReadinessCheck;
24 
25  public function setUp()
26  {
27  $filesystem = $this->createMock(\Magento\Framework\Filesystem::class);
28  $this->read = $this->createMock(\Magento\Framework\Filesystem\Directory\Read::class);
29  $filesystem->expects($this->once())->method('getDirectoryRead')->willReturn($this->read);
30  $this->cronScriptReadinessCheck = new CronScriptReadinessCheck($filesystem);
31  }
32 
33  public function testCheckSetupNoStatusFile()
34  {
35  $this->read->expects($this->once())
36  ->method('readFile')
37  ->willThrowException(new FileSystemException(new Phrase('message')));
38  $expected = [
39  'success' => false,
40  'error' => 'Cron job has not been configured yet' . CronScriptReadinessCheck::OTHER_CHECKS_WILL_FAIL_MSG
41  ];
42  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkSetup());
43  }
44 
46  {
47  $this->read->expects($this->once())->method('readFile')->willReturn('');
48  $expected = [
49  'success' => false,
50  'error' => 'Cron job has not been configured yet' . CronScriptReadinessCheck::OTHER_CHECKS_WILL_FAIL_MSG
51  ];
52  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkSetup());
53  }
54 
55  public function testCheckSetupCronError()
56  {
57  $json = [
60  'error' => 'error'
61  ]
62  ];
63  $this->read->expects($this->once())->method('readFile')->willReturn(json_encode($json));
64  $expected = ['success' => false, 'error' => 'error'];
65  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkSetup());
66  }
67 
68  public function testCheckSetupBadTime()
69  {
70  $json = [
74  ];
75  $this->read->expects($this->once())->method('readFile')->willReturn(json_encode($json));
76  $expected = [
77  'success' => true,
78  'notice' => 'We recommend you schedule cron to run every 1 minute'
79  ];
80  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkSetup());
81  }
82 
83  public function testCheckSetupUnknownTime()
84  {
85  $json = [
88  ];
89  $this->read->expects($this->once())->method('readFile')->willReturn(json_encode($json));
90  $expected = [
91  'success' => true,
92  'notice' => 'Unable to determine cron time interval. ' .
93  'We recommend you schedule cron to run every 1 minute'
94  ];
95  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkSetup());
96  }
97 
98  public function testCheckSetup()
99  {
100  $json = [
104  ];
105  $this->read->expects($this->once())->method('readFile')->willReturn(json_encode($json));
106  $expected = ['success' => true];
107  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkSetup());
108  }
109 
111  {
112  $this->read->expects($this->once())
113  ->method('readFile')
114  ->willThrowException(new FileSystemException(new Phrase('message')));
115  $expected = ['success' => false, 'error' => 'Cron job has not been configured yet'];
116  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkUpdater());
117  }
118 
120  {
121  $this->read->expects($this->once())->method('readFile')->willReturn('');
122  $expected = ['success' => false, 'error' => 'Cron job has not been configured yet'];
123  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkUpdater());
124  }
125 
126  public function testCheckUpdaterCronError()
127  {
128  $json = [
131  'error' => 'error'
132  ]
133  ];
134  $this->read->expects($this->once())->method('readFile')->willReturn(json_encode($json));
135  $expected = ['success' => false, 'error' => 'error'];
136  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkUpdater());
137  }
138 
139  public function testCheckUpdaterBadTime()
140  {
141  $json = [
144  ],
147  ];
148  $this->read->expects($this->once())->method('readFile')->willReturn(json_encode($json));
149  $expected = [
150  'success' => true,
151  'notice' => 'We recommend you schedule cron to run every 1 minute'
152  ];
153  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkUpdater());
154  }
155 
156  public function testCheckUpdaterUnknownTime()
157  {
158  $json = [
161  ],
163  ];
164  $this->read->expects($this->once())->method('readFile')->willReturn(json_encode($json));
165  $expected = [
166  'success' => true,
167  'notice' => 'Unable to determine cron time interval. ' .
168  'We recommend you schedule cron to run every 1 minute'
169  ];
170  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkUpdater());
171  }
172 
173  public function testCheckUpdater()
174  {
175  $json = [
178  ],
181  ];
182  $this->read->expects($this->once())->method('readFile')->willReturn(json_encode($json));
183  $expected = ['success' => true];
184  $this->assertEquals($expected, $this->cronScriptReadinessCheck->checkUpdater());
185  }
186 }
$filesystem