SenderTest::testInterface()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Alawar\NginxPushStreamBundle\Tests\Sender;
4
5
use Alawar\NginxPushStreamBundle\Http\Sender;
6
use Guzzle\Http\Client;
7
use Guzzle\Http\Message\Request;
8
use Guzzle\Http\Message\Response;
9
10
class SenderTest extends \PHPUnit_Framework_TestCase
11
{
12
    public function testInterface()
13
    {
14
        $sender = new Sender();
15
        $this->assertInstanceOf("Alawar\\NginxPushStreamBundle\\Http\\SenderInterface", $sender);
16
    }
17
18
    public function testSend()
19
    {
20
        $url = 'http://localhost/pub?id=123';
21
        $body = '{"token":"123"}' . "\r\n";
22
        $headers = array(
23
            'Event-ID'     => '123',
24
            'Event-Type'   => 'new_message',
25
            'Content-Type' => 'application/json'
26
        );
27
28
        $mockResponse = $this->getMock('Guzzle\Http\Message\Response', array(), array('200'));
29
        $mockResponse->expects($this->once())->method('isSuccessful')->will($this->returnValue(true));
30
31
        $mockRequest = $this->getMock('Guzzle\Http\Message\Request', array(), array('post', $url));
32
        $mockRequest->expects($this->once())->method('send')->will($this->returnValue($mockResponse));
33
34
        $mock = $this->getMock('Guzzle\Http\Client');
35
        $mock->expects($this->once())->method('post')->with($url, $headers, $body)->will($this->returnValue($mockRequest));
36
37
        $sender = new Sender();
38
        $sender->setClient($mock);
39
        $result = $sender->send($url, $body, $headers);
40
        $this->assertEquals(true, $result);
41
    }
42
}
43