Failed Conditions
Push — master ( 4f9353...7eeb29 )
by Michel
02:37
created

SyncCommandTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
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);
1 ignored issue
show
Bug introduced by
TogglJira\Service\SyncService::class of type string is incompatible with the type array expected by parameter $args of Mockery::mock(). ( Ignorable by Annotation )

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

48
        $this->syncServiceMock = \Mockery::mock(/** @scrutinizer ignore-type */ SyncService::class);
Loading history...
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);
3 ignored issues
show
Bug introduced by
$this->optionsMock of type Mockery\MockInterface is incompatible with the type TogglJira\Options\SyncOptions expected by parameter $syncOptions of TogglJira\Command\SyncCommand::__construct(). ( Ignorable by Annotation )

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

53
        $this->command = new SyncCommand($this->syncServiceMock, /** @scrutinizer ignore-type */ $this->optionsMock, $this->writerMock);
Loading history...
Bug introduced by
$this->writerMock of type Mockery\MockInterface is incompatible with the type Zend\Config\Writer\Json expected by parameter $writer of TogglJira\Command\SyncCommand::__construct(). ( Ignorable by Annotation )

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

53
        $this->command = new SyncCommand($this->syncServiceMock, $this->optionsMock, /** @scrutinizer ignore-type */ $this->writerMock);
Loading history...
Bug introduced by
$this->syncServiceMock of type Mockery\MockInterface is incompatible with the type TogglJira\Service\SyncService expected by parameter $service of TogglJira\Command\SyncCommand::__construct(). ( Ignorable by Annotation )

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

53
        $this->command = new SyncCommand(/** @scrutinizer ignore-type */ $this->syncServiceMock, $this->optionsMock, $this->writerMock);
Loading history...
54
        $this->command->setLogger($this->loggerMock);
1 ignored issue
show
Bug introduced by
$this->loggerMock of type Mockery\MockInterface is incompatible with the type Psr\Log\LoggerInterface expected by parameter $logger of TogglJira\Command\SyncCommand::setLogger(). ( Ignorable by Annotation )

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

54
        $this->command->setLogger(/** @scrutinizer ignore-type */ $this->loggerMock);
Loading history...
55
    }
56
57
    /**
58
     * @return void
59
     * @throws \Exception
60
     */
61
    public function testExecute(): void
62
    {
63
        $dateTime = '2017-04-15T23:35:00+02:00';
64
65
        $requestMock = \Mockery::mock(Request::class);
1 ignored issue
show
Bug introduced by
Zend\Console\Request::class of type string is incompatible with the type array expected by parameter $args of Mockery::mock(). ( Ignorable by Annotation )

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

65
        $requestMock = \Mockery::mock(/** @scrutinizer ignore-type */ Request::class);
Loading history...
66
        $consoleMock = \Mockery::mock(AdapterInterface::class);
67
68
        $this->optionsMock->shouldReceive('getLastSync')->andReturn($dateTime);
3 ignored issues
show
Bug introduced by
$dateTime of type string is incompatible with the type array expected by parameter $args of Mockery\ExpectationInterface::andReturn(). ( Ignorable by Annotation )

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

68
        $this->optionsMock->shouldReceive('getLastSync')->andReturn(/** @scrutinizer ignore-type */ $dateTime);
Loading history...
Bug introduced by
$dateTime of type string is incompatible with the type array<mixed,mixed> expected by parameter $args of Mockery\Expectation::andReturn(). ( Ignorable by Annotation )

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

68
        $this->optionsMock->shouldReceive('getLastSync')->andReturn(/** @scrutinizer ignore-type */ $dateTime);
Loading history...
Bug introduced by
'getLastSync' of type string is incompatible with the type array expected by parameter $methodNames of Mockery\MockInterface::shouldReceive(). ( Ignorable by Annotation )

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

68
        $this->optionsMock->shouldReceive(/** @scrutinizer ignore-type */ 'getLastSync')->andReturn($dateTime);
Loading history...
69
        $this->optionsMock->shouldReceive('setLastSync');
70
        $this->optionsMock->shouldReceive('toArray');
71
        $this->writerMock->shouldReceive('toFile');
72
73
        $this->loggerMock->shouldReceive('info')
74
            ->with("Syncing time entries since {$dateTime}")
1 ignored issue
show
Bug introduced by
'Syncing time entries since '.$dateTime of type string is incompatible with the type array<mixed,mixed> expected by parameter $args of Mockery\Expectation::with(). ( Ignorable by Annotation )

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

74
            ->with(/** @scrutinizer ignore-type */ "Syncing time entries since {$dateTime}")
Loading history...
75
            ->once();
76
77
        $this->loggerMock->shouldReceive('info')
78
            ->with('Updated last sync time')
79
            ->once();
80
81
        $this->syncServiceMock->shouldReceive('sync')->with($dateTime);
82
83
        $this->assertEquals(1, $this->command->execute($requestMock, $consoleMock));
2 ignored issues
show
Bug introduced by
$consoleMock of type Mockery\MockInterface is incompatible with the type Zend\Console\Adapter\AdapterInterface expected by parameter $console of TogglJira\Command\SyncCommand::execute(). ( Ignorable by Annotation )

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

83
        $this->assertEquals(1, $this->command->execute($requestMock, /** @scrutinizer ignore-type */ $consoleMock));
Loading history...
Bug introduced by
$requestMock of type Mockery\MockInterface is incompatible with the type Zend\Console\Request expected by parameter $request of TogglJira\Command\SyncCommand::execute(). ( Ignorable by Annotation )

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

83
        $this->assertEquals(1, $this->command->execute(/** @scrutinizer ignore-type */ $requestMock, $consoleMock));
Loading history...
84
    }
85
86
    /**
87
     * @return void
88
     */
89
    public function testExecuteWithoutStartDate(): void
90
    {
91
        $requestMock = \Mockery::mock(Request::class);
1 ignored issue
show
Bug introduced by
Zend\Console\Request::class of type string is incompatible with the type array expected by parameter $args of Mockery::mock(). ( Ignorable by Annotation )

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

91
        $requestMock = \Mockery::mock(/** @scrutinizer ignore-type */ Request::class);
Loading history...
92
        $consoleMock = \Mockery::mock(AdapterInterface::class);
93
94
        $this->optionsMock->shouldReceive('getLastSync')->andReturn("");
3 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type array<mixed,mixed> expected by parameter $args of Mockery\Expectation::andReturn(). ( Ignorable by Annotation )

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

94
        $this->optionsMock->shouldReceive('getLastSync')->andReturn(/** @scrutinizer ignore-type */ "");
Loading history...
Bug introduced by
'' of type string is incompatible with the type array expected by parameter $args of Mockery\ExpectationInterface::andReturn(). ( Ignorable by Annotation )

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

94
        $this->optionsMock->shouldReceive('getLastSync')->andReturn(/** @scrutinizer ignore-type */ "");
Loading history...
Bug introduced by
'getLastSync' of type string is incompatible with the type array expected by parameter $methodNames of Mockery\MockInterface::shouldReceive(). ( Ignorable by Annotation )

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

94
        $this->optionsMock->shouldReceive(/** @scrutinizer ignore-type */ 'getLastSync')->andReturn("");
Loading history...
95
        $this->optionsMock->shouldReceive('setLastSync');
96
        $this->optionsMock->shouldReceive('toArray');
97
        $this->writerMock->shouldReceive('toFile');
98
99
        $this->loggerMock->shouldReceive('info')
100
            ->with(\Mockery::pattern('/(Syncing time entries since)/'))
1 ignored issue
show
Bug introduced by
Mockery::pattern('/(Sync... time entries since)/') of type Mockery\Matcher\Pattern is incompatible with the type array<mixed,mixed> expected by parameter $args of Mockery\Expectation::with(). ( Ignorable by Annotation )

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

100
            ->with(/** @scrutinizer ignore-type */ \Mockery::pattern('/(Syncing time entries since)/'))
Loading history...
101
            ->once();
102
103
        $this->loggerMock->shouldReceive('info')
104
            ->with('Updated last sync time')
1 ignored issue
show
Bug introduced by
'Updated last sync time' of type string is incompatible with the type array<mixed,mixed> expected by parameter $args of Mockery\Expectation::with(). ( Ignorable by Annotation )

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

104
            ->with(/** @scrutinizer ignore-type */ 'Updated last sync time')
Loading history...
105
            ->once();
106
107
        $this->syncServiceMock->shouldReceive('sync');
108
109
        $this->assertEquals(1, $this->command->execute($requestMock, $consoleMock));
2 ignored issues
show
Bug introduced by
$consoleMock of type Mockery\MockInterface is incompatible with the type Zend\Console\Adapter\AdapterInterface expected by parameter $console of TogglJira\Command\SyncCommand::execute(). ( Ignorable by Annotation )

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

109
        $this->assertEquals(1, $this->command->execute($requestMock, /** @scrutinizer ignore-type */ $consoleMock));
Loading history...
Bug introduced by
$requestMock of type Mockery\MockInterface is incompatible with the type Zend\Console\Request expected by parameter $request of TogglJira\Command\SyncCommand::execute(). ( Ignorable by Annotation )

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

109
        $this->assertEquals(1, $this->command->execute(/** @scrutinizer ignore-type */ $requestMock, $consoleMock));
Loading history...
110
    }
111
}