BasePublisherCommandTest.php$0 ➔ __construct()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 5
rs 10
c 2
b 0
f 0
1
<?php
2
namespace NeedleProject\LaravelRabbitMq\Command;
3
4
use NeedleProject\LaravelRabbitMq\Container;
5
use NeedleProject\LaravelRabbitMq\PublisherInterface;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class BasePublisherCommandTest extends TestCase
11
{
12
    public function testHandle()
13
    {
14
        $containerMock = $this->getMockBuilder(Container::class)
15
            ->disableOriginalConstructor()
16
            ->getMock();
17
18
        $inputMock = $this->getMockBuilder(InputInterface::class)
19
            ->getMock();
20
        $outputMock = $this->getMockBuilder(OutputInterface::class)
21
            ->getMock();
22
        $publisherMock = $this->getMockBuilder(PublisherInterface::class)
23
            ->getMock();
24
25
        $command = new class($inputMock, $outputMock, $containerMock) extends BasePublisherCommand {
26
            public function __construct($inputMock, $outputMock, $containerMock)
27
            {
28
                $this->input = $inputMock;
29
                $this->output = $outputMock;
30
                parent::__construct($containerMock);
31
            }
32
        };
33
34
        $publisherMock->expects($this->once())
35
            ->method('publish')
36
            ->with('bar')
37
            ->willReturn(null);
38
39
        $inputMock->expects($this->exactly(2))
40
            ->method('getArgument')
41
            ->with(
42
                $this->logicalOr(
43
                    $this->equalTo('publisher'),
44
                    $this->equalTo('message')
45
                )
46
            )
47
            ->will($this->returnCallback(function ($argument) {
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\TestCase::returnCallback() has been deprecated: Use <code>$double->willReturnCallback()</code> instead of <code>$double->will($this->returnCallback())</code> ( Ignorable by Annotation )

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

47
            ->will(/** @scrutinizer ignore-deprecated */ $this->returnCallback(function ($argument) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
48
                return $argument === 'publisher' ? 'fooPublisher' : 'bar';
49
            }));
50
51
        $containerMock->expects($this->once())
52
            ->method('getPublisher')
53
            ->with('fooPublisher')
54
            ->willReturn($publisherMock);
55
56
        $command->handle();
57
    }
58
}
59