Passed
Push — master ( 2bbdf9...f98864 )
by Michel
03:35 queued 10s
created

SyncCommandTest::testExecuteWithoutStartDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
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 \DateTimeImmutable('2017-04-15T23:35:00+02:00');
64
65
        $requestMock = \Mockery::mock(Request::class);
66
        $requestMock->shouldReceive('getParam')->with('startDate', null)->andReturnNull();
0 ignored issues
show
Bug introduced by
The method andReturnNull() does not exist on Mockery\ExpectationInterface. Did you maybe mean andReturn()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        $requestMock->shouldReceive('getParam')->with('startDate', null)->/** @scrutinizer ignore-call */ andReturnNull();

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.

Loading history...
67
        $requestMock->shouldReceive('getParam')->with('endDate', null)->andReturn('tomorrow');
68
        $requestMock->shouldReceive('getParam')->with('overwrite', false)->andReturnTrue();
0 ignored issues
show
Bug introduced by
The method andReturnTrue() does not exist on Mockery\ExpectationInterface. Did you maybe mean andReturn()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

68
        $requestMock->shouldReceive('getParam')->with('overwrite', false)->/** @scrutinizer ignore-call */ andReturnTrue();

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.

Loading history...
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