Passed
Pull Request — master (#661)
by
unknown
10:08
created

JsonSchemaTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 26
c 2
b 0
f 1
dl 0
loc 47
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConsumer() 0 3 1
A prepareAMQPConnection() 0 5 1
A prepareAMQPChannel() 0 5 1
A testValidateJsonMessageFunction() 0 26 1
1
<?php
2
3
namespace OldSound\RabbitMqBundle\Tests\RabbitMq;
4
5
use OldSound\RabbitMqBundle\RabbitMq\Consumer;
6
use PhpAmqpLib\Channel\AMQPChannel;
7
use PhpAmqpLib\Connection\AMQPStreamConnection;
8
use PHPUnit\Framework\TestCase;
9
10
class JsonSchemaTest extends TestCase
11
{
12
    protected function getConsumer($amqpConnection, $amqpChannel)
13
    {
14
        return new Consumer($amqpConnection, $amqpChannel);
15
    }
16
17
    protected function prepareAMQPConnection()
18
    {
19
        return $this->getMockBuilder(AMQPStreamConnection::class)
20
            ->disableOriginalConstructor()
21
            ->getMock();
22
    }
23
24
    protected function prepareAMQPChannel()
25
    {
26
        return $this->getMockBuilder(AMQPChannel::class)
27
            ->disableOriginalConstructor()
28
            ->getMock();
29
    }
30
31
    public function testValidateJsonMessageFunction()
32
    {
33
        $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer')
34
            ->disableOriginalConstructor()
35
            ->getMock();;
36
37
        
38
        $amqpConnection = $this->prepareAMQPConnection();
39
        $amqpChannel = $this->prepareAMQPChannel();
40
        $consumer = $this->getConsumer($amqpConnection, $amqpChannel);
41
        // disable autosetup fabric so we do not mock more objects
42
        $consumer->disableAutoSetupFabric();
43
        $consumer->setChannel($amqpChannel);
44
45
        $this->assertEquals(false, $producer->jsonSchemaCheck);
0 ignored issues
show
Bug introduced by
Accessing jsonSchemaCheck on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
46
        $producer->setJsonSchemaCheck(true);
47
48
        $json_msg = <<<'JSON'
49
        {
50
            "firstName": "John",
51
            "lastName": "Doe",
52
            "age": 21
53
        }
54
        JSON;
55
        
56
        $producer->publish($json_msg);
57
    }
58
}
59