Completed
Push — 1.0 ( 96ad2d...e7718b )
by David
06:45
created

ClientTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace Mouf\AmqpClient\Objects;
4
5
use Mouf\AmqpClient\Client;
6
use Mouf\AmqpClient\Consumer;
7
use Mouf\AmqpClient\ConsumerService;
8
use PhpAmqpLib\Message\AMQPMessage;
9
10
class ClientTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var Client
14
     */
15
    private $client;
16
    private $exchange;
17
    private $queue;
18
    private $msgReceived;
19
20
    protected function setUp()
21
    {
22
        global $rabbitmq_host;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
23
        global $rabbitmq_port;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
24
        global $rabbitmq_user;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
25
        global $rabbitmq_password;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
26
27
        $this->client = new Client($rabbitmq_host, $rabbitmq_port, $rabbitmq_user, $rabbitmq_password);
28
        $this->client->setPrefetchCount(1);
29
30
        $this->exchange = new Exchange($this->client, 'test_exchange', 'fanout');
31
        $this->queue = new Queue($this->client, 'test_queue', [
32
            new Consumer(function(AMQPMessage $msg) {
33
                $this->msgReceived = $msg;
34
            })
35
        ]);
36
        $this->queue->setDurable(true);
37
38
        $binding = new Binding($this->exchange, $this->queue);
39
        $this->client->register($binding);
40
    }
41
42
43
44
    public function testExchange()
45
    {
46
        $this->exchange->publish(new Message('my message'), 'key');
47
    }
48
49
    /**
50
     * @depends testExchange
51
     */
52
    public function testQueue()
53
    {
54
        $consumerService = new ConsumerService($this->client, [
55
            $this->queue
56
        ]);
57
58
        $consumerService->run(true);
59
60
        $this->assertEquals('my message', $this->msgReceived->getBody());
61
    }
62
}
63