Passed
Push — main ( a1448d...532f1f )
by Peter
03:51
created

FlushCacheTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Console\Commands\AbterPhp;
6
7
use Opulence\Console\Commands\CommandCollection;
8
use Opulence\Console\Responses\IResponse;
9
use PHPUnit\Framework\TestCase;
10
11
class FlushCacheTest extends TestCase
12
{
13
    private FlushCache $sut;
14
15
    public function setUp(): void
16
    {
17
        $this->sut = new FlushCache();
18
    }
19
20
    public function testDoExecuteCallsAllSubCommands()
21
    {
22
        $responseMock          = $this
23
            ->getMockBuilder(IResponse::class)
24
            ->disableOriginalConstructor()
25
            ->getMock();
26
        $commandCollectionMock = $this->getMockBuilder(CommandCollection::class)
27
            ->disableOriginalConstructor()
28
            ->getMock();
29
30
        $commandCollectionMock->expects($this->exactly(4))->method('call');
31
32
        $this->sut->setCommandCollection($commandCollectionMock);
33
        $result = $this->sut->execute($responseMock);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $this->sut->execute($responseMock) targeting Opulence\Console\Commands\Command::execute() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
34
35
        $this->assertNull($result);
36
    }
37
38
    public function testDoExecuteWritesErrorMessageOnException()
39
    {
40
        $ex = new \Exception();
41
42
        $responseMock          = $this
43
            ->getMockBuilder(IResponse::class)
44
            ->disableOriginalConstructor()
45
            ->getMock();
46
        $commandCollectionMock = $this->getMockBuilder(CommandCollection::class)
47
            ->disableOriginalConstructor()
48
            ->getMock();
49
50
        $responseMock->expects($this->exactly(8))->method('writeln');
51
52
        $commandCollectionMock->expects($this->exactly(4))->method('call')->willThrowException($ex);
53
54
        $this->sut->setCommandCollection($commandCollectionMock);
55
        $result = $this->sut->execute($responseMock);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $this->sut->execute($responseMock) targeting Opulence\Console\Commands\Command::execute() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
56
57
        $this->assertNull($result);
58
    }
59
}
60