/
ConfigurationTest.php
120 lines (102 loc) · 3.37 KB
/
ConfigurationTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace VCR;
/**
*
*/
class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->config = new Configuration;
}
public function testGetLibraryHooks()
{
$this->assertEquals(
array(
'VCR\LibraryHooks\StreamWrapper',
'VCR\LibraryHooks\Curl',
'VCR\LibraryHooks\Soap',
),
$this->config->getLibraryHooks()
);
}
public function testEnableLibraryHooks()
{
$this->config->enableLibraryHooks(array('stream_wrapper'));
$this->assertEquals(
array(
'VCR\LibraryHooks\StreamWrapper',
),
$this->config->getLibraryHooks()
);
}
public function testEnableSingleLibraryHook()
{
$this->config->enableLibraryHooks('stream_wrapper');
$this->assertEquals(
array(
'VCR\LibraryHooks\StreamWrapper',
),
$this->config->getLibraryHooks()
);
}
public function testEnableLibraryHooksFailsWithWrongHookName()
{
$this->setExpectedException('InvalidArgumentException', "Library hooks don't exist: non_existing");
$this->config->enableLibraryHooks(array('non_existing'));
}
public function testEnableRequestMatchers()
{
$actual = $this->config->enableRequestMatchers(array('body', 'headers'));
$this->assertEquals(
array(
array('VCR\RequestMatcher', 'matchHeaders'),
array('VCR\RequestMatcher', 'matchBody'),
),
$this->config->getRequestMatchers()
);
}
public function testAddRequestMatcherFailsWithNoName()
{
$this->setExpectedException('VCR\VCRException', "A request matchers name must be at least one character long. Found ''");
$expected = function($first, $second) {
return true;
};
$actual = $this->config->addRequestMatcher('', $expected);
}
public function testAddRequestMatcherFailsWithWrongCallback()
{
$this->setExpectedException('VCR\VCRException', "Request matcher 'example' is not callable.");
$actual = $this->config->addRequestMatcher('example', array());
}
public function testAddRequestMatchers()
{
$expected = function($first, $second) {
return true;
};
$actual = $this->config->addRequestMatcher('new_matcher', $expected);
$this->assertContains($expected, $this->config->getRequestMatchers());
}
public function testSetStorageInvalidName()
{
$this->setExpectedException('VCR\VCRException', "Storage 'Does not exist' not available.");
$this->config->setStorage('Does not exist');
}
public function testGetStorage()
{
$class = $this->config->getStorage();
$this->assertTrue(in_array("VCR\Storage\StorageInterface", class_implements($class)));
}
public function testWhitelist()
{
$expected = array('Tux', 'Gnu');
$this->config->setWhiteList($expected);
$this->assertEquals($expected, $this->config->getWhiteList());
}
public function testBlacklist()
{
$expected = array('Tux', 'Gnu');
$this->config->setBlackList($expected);
$this->assertEquals($expected, $this->config->getBlackList());
}
}