|
1
|
|
|
<?php |
|
2
|
|
|
namespace Thunder\SimilarWebApi\Tests; |
|
3
|
|
|
|
|
4
|
|
|
use Thunder\SimilarWebApi\RawResponse; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* @author Tomasz Kowalczyk <[email protected]> |
|
8
|
|
|
*/ |
|
9
|
|
|
class ResponseTest extends \PHPUnit_Framework_TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testInstance() |
|
12
|
|
|
{ |
|
13
|
|
|
$instance = new RawResponse('', array(), array(), array(), array()); |
|
14
|
|
|
$this->assertInstanceOf('Thunder\SimilarWebApi\RawResponse', $instance); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function testMaps() |
|
18
|
|
|
{ |
|
19
|
|
|
$instance = new RawResponse('', array(), array(), array( |
|
20
|
|
|
'one' => array('a' => 'b', 'c' => 'd', 'e' => 'f'), |
|
21
|
|
|
'two' => array('a' => 'b', 'c' => 'd', 'e' => 'f', 'g' => 'h'), |
|
22
|
|
|
), array()); |
|
23
|
|
|
$this->assertEquals(2, count($instance->getMaps())); |
|
24
|
|
|
$this->assertEquals(3, count($instance->getMap('one'))); |
|
25
|
|
|
$this->assertEquals(4, count($instance->getMap('two'))); |
|
26
|
|
|
$this->assertEquals('b', $instance->getMapValue('one', 'a')); |
|
27
|
|
|
$this->assertEquals('a', $instance->getMapKey('one', 'b')); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testArrays() |
|
31
|
|
|
{ |
|
32
|
|
|
$instance = new RawResponse('', array(), array( |
|
33
|
|
|
'one' => array(1), |
|
34
|
|
|
'two' => array(2, 2), |
|
35
|
|
|
'three' => array(3, 3, 3), |
|
36
|
|
|
), array(), array()); |
|
37
|
|
|
$this->assertEquals(3, count($instance->getArrays())); |
|
38
|
|
|
$this->assertEquals(1, count($instance->getArray('one'))); |
|
39
|
|
|
$this->assertEquals(2, count($instance->getArray('two'))); |
|
40
|
|
|
$this->assertEquals(3, count($instance->getArray('three'))); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testValues() |
|
44
|
|
|
{ |
|
45
|
|
|
$instance = new RawResponse('', array( |
|
46
|
|
|
'one' => 'oneValue', |
|
47
|
|
|
'two' => 'twoValue', |
|
48
|
|
|
'three' => 3, |
|
49
|
|
|
), array(), array(), array()); |
|
50
|
|
|
$this->assertEquals(3, count($instance->getValues())); |
|
51
|
|
|
$this->assertEquals('oneValue', $instance->getValue('one')); |
|
52
|
|
|
$this->assertEquals('twoValue', $instance->getValue('two')); |
|
53
|
|
|
$this->assertEquals(3, $instance->getValue('three')); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testTuples() |
|
57
|
|
|
{ |
|
58
|
|
|
$instance = new RawResponse('', array(), array(), array(), array( |
|
59
|
|
|
'xxx' => array('first' => 'one', 'second' => 'two'), |
|
60
|
|
|
'yyy' => array('third' => 'three', 'fourth' => 'four', 'fifth' => 'five'), |
|
61
|
|
|
)); |
|
62
|
|
|
$this->assertEquals(2, count($instance->getTuples())); |
|
63
|
|
|
$this->assertEquals(2, count($instance->getTuple('xxx'))); |
|
64
|
|
|
$this->assertEquals(3, count($instance->getTuple('yyy'))); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testRaw() |
|
68
|
|
|
{ |
|
69
|
|
|
$instance = new RawResponse('response', array(), array(), array(), array()); |
|
70
|
|
|
$this->assertEquals('response', $instance->getRaw()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @expectedException \RuntimeException |
|
75
|
|
|
*/ |
|
76
|
|
|
public function testMapNotFound() |
|
77
|
|
|
{ |
|
78
|
|
|
$instance = new RawResponse('', array(), array(), array(), array()); |
|
79
|
|
|
$instance->getMap('invalid'); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @expectedException \RuntimeException |
|
84
|
|
|
*/ |
|
85
|
|
|
public function testArrayNotFound() |
|
86
|
|
|
{ |
|
87
|
|
|
$instance = new RawResponse('', array(), array(), array(), array()); |
|
88
|
|
|
$instance->getArray('invalid'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @expectedException \RuntimeException |
|
93
|
|
|
*/ |
|
94
|
|
|
public function testValueNotFound() |
|
95
|
|
|
{ |
|
96
|
|
|
$instance = new RawResponse('', array(), array(), array(), array()); |
|
97
|
|
|
$instance->getValue('invalid'); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @expectedException \RuntimeException |
|
102
|
|
|
*/ |
|
103
|
|
|
public function testTupleNotFound() |
|
104
|
|
|
{ |
|
105
|
|
|
$instance = new RawResponse('', array(), array(), array(), array()); |
|
106
|
|
|
$instance->getTuple('invalid'); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|