testProcessMessageWithNotifyMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 15
c 2
b 1
f 0
nc 1
nop 0
dl 0
loc 22
rs 9.7666
1
<?php
2
3
namespace OldSound\RabbitMqBundle\Tests\RabbitMq;
4
5
use OldSound\RabbitMqBundle\RabbitMq\RpcClient;
6
use PhpAmqpLib\Exception\AMQPTimeoutException;
7
use PhpAmqpLib\Message\AMQPMessage;
8
use PHPUnit\Framework\TestCase;
9
10
class RpcClientTest extends TestCase
11
{
12
    public function testProcessMessageWithCustomUnserializer()
13
    {
14
        /** @var RpcClient $client */
15
        $client = $this->getMockBuilder('\OldSound\RabbitMqBundle\RabbitMq\RpcClient')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

15
        $client = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\OldSound\RabbitMqBundle\RabbitMq\RpcClient')

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...
16
            ->setMethods(array('sendReply', 'maybeStopConsumer'))
17
            ->disableOriginalConstructor()
18
            ->getMock();
19
        /** @var AMQPMessage $message */
20
        $message = $this->getMockBuilder('\PhpAmqpLib\Message\AMQPMessage')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

20
        $message = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\PhpAmqpLib\Message\AMQPMessage')

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...
21
            ->setMethods(array('get'))
22
            ->setConstructorArgs(array('message'))
23
            ->getMock();
24
        $serializer = $this->getMockBuilder('\Symfony\Component\Serializer\SerializerInterface')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

24
        $serializer = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\Symfony\Component\Serializer\SerializerInterface')

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...
25
            ->setMethods(array('serialize', 'deserialize'))
26
            ->getMock();
27
        $serializer->expects($this->once())->method('deserialize')->with('message', 'json', null);
28
        $client->initClient(true);
29
        $client->setUnserializer(function($data) use ($serializer) {
30
            $serializer->deserialize($data, 'json','');
31
        });
32
        $client->processMessage($message);
33
    }
34
35
    public function testProcessMessageWithNotifyMethod()
36
    {
37
        /** @var RpcClient $client */
38
        $client = $this->getMockBuilder('\OldSound\RabbitMqBundle\RabbitMq\RpcClient')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

38
        $client = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\OldSound\RabbitMqBundle\RabbitMq\RpcClient')

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...
39
            ->setMethods(array('sendReply', 'maybeStopConsumer'))
40
            ->disableOriginalConstructor()
41
            ->getMock();
42
        $expectedNotify = 'message';
43
        /** @var AMQPMessage $message */
44
        $message = $this->getMockBuilder('\PhpAmqpLib\Message\AMQPMessage')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

44
        $message = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\PhpAmqpLib\Message\AMQPMessage')

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...
45
            ->setMethods(array('get'))
46
            ->setConstructorArgs(array($expectedNotify))
47
            ->getMock();
48
        $notified = false;
49
        $client->notify(function ($message) use (&$notified) {
50
            $notified = $message;
51
        });
52
53
        $client->initClient(false);
54
        $client->processMessage($message);
55
56
        $this->assertSame($expectedNotify, $notified);
57
    }
58
59
    public function testInvalidParameterOnNotify()
60
    {
61
        /** @var RpcClient $client */
62
        $client = $this->getMockBuilder('\OldSound\RabbitMqBundle\RabbitMq\RpcClient')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

62
        $client = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\OldSound\RabbitMqBundle\RabbitMq\RpcClient')

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...
63
            ->setMethods(array('sendReply', 'maybeStopConsumer'))
64
            ->disableOriginalConstructor()
65
            ->getMock();
66
67
        $this->expectException('\InvalidArgumentException');
68
69
        $client->notify('not a callable');
70
    }
71
72
    public function testChannelCancelOnGetRepliesException()
73
    {
74
        $client = $this->getMockBuilder('\OldSound\RabbitMqBundle\RabbitMq\RpcClient')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

74
        $client = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\OldSound\RabbitMqBundle\RabbitMq\RpcClient')

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...
75
            ->setMethods(null)
76
            ->disableOriginalConstructor()
77
            ->getMock();
78
79
        $channel = $this->createMock('\PhpAmqpLib\Channel\AMQPChannel');
80
        $channel->expects($this->any())
81
            ->method('getChannelId')
82
            ->willReturn('test');
83
        $channel->expects($this->once())
84
            ->method('wait')
85
            ->willThrowException(new AMQPTimeoutException());
86
87
        $this->expectException('\PhpAmqpLib\Exception\AMQPTimeoutException');
88
89
        $channel->expects($this->once())
90
            ->method('basic_cancel');
91
92
        $client->setChannel($channel);
93
        $client->addRequest('a', 'b', 'c');
94
95
        $client->getReplies();
96
    }
97
}
98