1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the beebot package. |
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
5
|
|
|
* file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Bee4 2015 |
8
|
|
|
* @author Stephane HULARD <[email protected]> |
9
|
|
|
* @package Bee4\Test\Transport\Message |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Bee4\Test\Transport\Message; |
13
|
|
|
|
14
|
|
|
use Bee4\Transport\Message\Response; |
15
|
|
|
use Bee4\Transport\Url; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Response unit test definition |
19
|
|
|
* @package Bee4\Test\Transport\Message |
20
|
|
|
*/ |
21
|
|
|
class ResponseTest extends \PHPUnit_Framework_TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Response |
25
|
|
|
*/ |
26
|
|
|
protected $object; |
27
|
|
|
|
28
|
|
|
public function setUp() |
29
|
|
|
{ |
30
|
|
|
$this->object = new Response(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testIntegrity() |
34
|
|
|
{ |
35
|
|
|
$uses = class_uses(get_class($this->object)); |
36
|
|
|
$this->assertContains('Bee4\Transport\Message\WithBodyTrait', $uses); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testSetters() |
40
|
|
|
{ |
41
|
|
|
$request = $this->getMockForAbstractClass( |
42
|
|
|
'\Bee4\Transport\Message\Request\AbstractRequest', |
43
|
|
|
[ new Url('http://www.bee4.fr') ] |
44
|
|
|
); |
45
|
|
|
$this->object->setRequest($request); |
46
|
|
|
$this->assertEquals($request, $this->object->getRequest()); |
47
|
|
|
|
48
|
|
|
$this->object->setStatus(200); |
49
|
|
|
$this->assertEquals(200, $this->object->getStatus()); |
50
|
|
|
|
51
|
|
|
$this->object->setTransactionTime(1.5); |
52
|
|
|
$this->assertEquals(1.5, $this->object->getTransactionTime()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function badResponseTimeProvider() |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
|
|
['hello_world'], |
59
|
|
|
[-0.8] |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
/** |
63
|
|
|
* @dataProvider badResponseTimeProvider |
64
|
|
|
* @param string $value |
65
|
|
|
* @expectedException \RuntimeException |
66
|
|
|
*/ |
67
|
|
|
public function testResponseTimeFormatCheck($value) |
68
|
|
|
{ |
69
|
|
|
$this->object->setTransactionTime($value); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @expectedException \RuntimeException |
74
|
|
|
*/ |
75
|
|
|
public function testJson() |
76
|
|
|
{ |
77
|
|
|
$this->object->setBody('{"key":"value"}'); |
78
|
|
|
$this->assertEquals(["key"=>"value"], $this->object->json()); |
79
|
|
|
|
80
|
|
|
$this->object->setBody('{invalidJson}'); |
81
|
|
|
$this->object->json(); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|