Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CollectionTimeTest.php
Go to the documentation of this file.
1 <?php
7 
12 use Psr\Log\LoggerInterface;
13 
14 class CollectionTimeTest extends \PHPUnit\Framework\TestCase
15 {
19  private $configWriterMock;
20 
24  private $loggerMock;
25 
29  private $objectManagerHelper;
30 
34  private $collectionTime;
35 
39  protected function setUp()
40  {
41  $this->configWriterMock = $this->getMockBuilder(WriterInterface::class)
42  ->disableOriginalConstructor()
43  ->getMock();
44 
45  $this->loggerMock = $this->getMockBuilder(LoggerInterface::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48 
49  $this->objectManagerHelper = new ObjectManagerHelper($this);
50 
51  $this->collectionTime = $this->objectManagerHelper->getObject(
52  CollectionTime::class,
53  [
54  'configWriter' => $this->configWriterMock,
55  '_logger' => $this->loggerMock,
56  ]
57  );
58  }
59 
63  public function testAfterSave()
64  {
65  $this->collectionTime->setData('value', '05,04,03');
66 
67  $this->configWriterMock
68  ->expects($this->once())
69  ->method('save')
70  ->with(CollectionTime::CRON_SCHEDULE_PATH, join(' ', ['04', '05', '*', '*', '*']));
71 
72  $this->assertInstanceOf(
73  Value::class,
74  $this->collectionTime->afterSave()
75  );
76  }
77 
82  public function testAfterSaveWrongValue()
83  {
84  $this->collectionTime->setData('value', '00,01');
85  $this->collectionTime->afterSave();
86  }
87 
93  {
94  $exception = new \Exception('Test message');
95  $this->collectionTime->setData('value', '05,04,03');
96 
97  $this->configWriterMock
98  ->expects($this->once())
99  ->method('save')
100  ->with(CollectionTime::CRON_SCHEDULE_PATH, join(' ', ['04', '05', '*', '*', '*']))
101  ->willThrowException($exception);
102  $this->loggerMock
103  ->expects($this->once())
104  ->method('error')
105  ->with($exception->getMessage());
106  $this->collectionTime->afterSave();
107  }
108 }