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
|
|
|
|