|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace TogglJiraTest\Command; |
|
5
|
|
|
|
|
6
|
|
|
use Mockery\MockInterface; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Psr\Log\LoggerInterface; |
|
9
|
|
|
use TogglJira\Command\SyncCommand; |
|
10
|
|
|
use TogglJira\Options\SyncOptions; |
|
11
|
|
|
use TogglJira\Service\SyncService; |
|
12
|
|
|
use Zend\Config\Writer\Json; |
|
13
|
|
|
use Zend\Console\Adapter\AdapterInterface; |
|
14
|
|
|
use Zend\Console\Request; |
|
15
|
|
|
|
|
16
|
|
|
class SyncCommandTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var SyncCommand |
|
20
|
|
|
*/ |
|
21
|
|
|
private $command; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var MockInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
private $syncServiceMock; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var MockInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $optionsMock; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var MockInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $writerMock; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var MockInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
private $loggerMock; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return void |
|
45
|
|
|
*/ |
|
46
|
|
|
public function setUp(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->syncServiceMock = \Mockery::mock(SyncService::class); |
|
49
|
|
|
$this->optionsMock = \Mockery::mock(SyncOptions::class); |
|
50
|
|
|
$this->writerMock = \Mockery::mock(Json::class); |
|
51
|
|
|
$this->loggerMock = \Mockery::mock(LoggerInterface::class); |
|
52
|
|
|
|
|
53
|
|
|
$this->command = new SyncCommand($this->syncServiceMock, $this->optionsMock, $this->writerMock); |
|
54
|
|
|
$this->command->setLogger($this->loggerMock); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return void |
|
59
|
|
|
* @throws \Exception |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testExecute(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$startDate = new \DateTime('2017-04-15T23:35:00+02:00'); |
|
64
|
|
|
|
|
65
|
|
|
$requestMock = \Mockery::mock(Request::class); |
|
66
|
|
|
$requestMock->shouldReceive('getParam')->with('startDate', null)->andReturnNull(); |
|
|
|
|
|
|
67
|
|
|
$requestMock->shouldReceive('getParam')->with('endDate', null)->andReturn('tomorrow'); |
|
68
|
|
|
$requestMock->shouldReceive('getParam')->with('overwrite', false)->andReturnTrue(); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
$consoleMock = \Mockery::mock(AdapterInterface::class); |
|
71
|
|
|
|
|
72
|
|
|
$this->optionsMock->shouldReceive('getLastSync')->andReturn($startDate); |
|
73
|
|
|
$this->optionsMock->shouldReceive('setLastSync'); |
|
74
|
|
|
$this->optionsMock->shouldReceive('toArray'); |
|
75
|
|
|
$this->writerMock->shouldReceive('toFile'); |
|
76
|
|
|
|
|
77
|
|
|
$this->loggerMock->shouldReceive('info') |
|
78
|
|
|
->with('Syncing time entries', ['lastSync' => '2017-04-15T23:35:00+02:00']) |
|
79
|
|
|
->once(); |
|
80
|
|
|
|
|
81
|
|
|
$this->loggerMock->shouldReceive('info') |
|
82
|
|
|
->with('Updated last sync time') |
|
83
|
|
|
->once(); |
|
84
|
|
|
|
|
85
|
|
|
$this->syncServiceMock->shouldReceive('sync')->once(); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEquals(0, $this->command->execute($requestMock, $consoleMock)); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.