1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2013 Jan Eichhorn <[email protected]> |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* |
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
* |
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
* See the License for the specific language governing permissions and |
15
|
|
|
* limitations under the License. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace ApaiIO\Test\Configuration; |
19
|
|
|
|
20
|
|
|
use ApaiIO\Configuration\GenericConfiguration; |
21
|
|
|
|
22
|
|
|
class GenericConfigurationTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var \ApaiIO\Configuration\GenericConfiguration |
26
|
|
|
*/ |
27
|
|
|
private $genericConfiguration; |
28
|
|
|
|
29
|
|
|
protected function setUp() |
30
|
|
|
{ |
31
|
|
|
$this->genericConfiguration = new GenericConfiguration(); |
32
|
|
|
parent::setUp(); |
33
|
|
|
} |
34
|
|
|
public function testGettersAndSetters() |
35
|
|
|
{ |
36
|
|
|
$this->genericConfiguration->setAccessKey('ABC'); |
37
|
|
|
$this->genericConfiguration->setSecretKey('DEF'); |
38
|
|
|
$this->genericConfiguration->setAssociateTag('GHI'); |
39
|
|
|
|
40
|
|
|
$this->assertSame('ABC', $this->genericConfiguration->getAccessKey()); |
41
|
|
|
$this->assertSame('DEF', $this->genericConfiguration->getSecretKey()); |
42
|
|
|
$this->assertSame('GHI', $this->genericConfiguration->getAssociateTag()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testSetRequestFactoryExeptsClosure() |
46
|
|
|
{ |
47
|
|
|
$this->genericConfiguration->setRequestFactory(function(){}); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testSetRequestFactoryExeptsCallable() |
51
|
|
|
{ |
52
|
|
|
$this->genericConfiguration->setRequestFactory(array(__NAMESPACE__ . '\CallableClass', 'foo')); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @expectedException InvalidArgumentException |
57
|
|
|
*/ |
58
|
|
|
public function testSetRequestFactoryThrowExceptionIfArgumentIsNotCallable() |
59
|
|
|
{ |
60
|
|
|
$this->genericConfiguration->setRequestFactory(""); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testSetResponseTransformerFactoryExeptsClosure() |
64
|
|
|
{ |
65
|
|
|
$this->genericConfiguration->setResponseTransformerFactory(function(){}); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testSetResponseTransformerExeptsCallable() |
69
|
|
|
{ |
70
|
|
|
$this->genericConfiguration->setResponseTransformerFactory(array(__NAMESPACE__ . '\CallableClass', 'foo')); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @expectedException InvalidArgumentException |
75
|
|
|
*/ |
76
|
|
|
public function testSetResponseTransformerFactoryThrowExceptionIfArgumentIsNotCallable() |
77
|
|
|
{ |
78
|
|
|
$this->genericConfiguration->setResponseTransformerFactory(""); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @expectedException InvalidArgumentException |
83
|
|
|
*/ |
84
|
|
|
public function testCountryException() |
85
|
|
|
{ |
86
|
|
|
$object = new GenericConfiguration(); |
87
|
|
|
$object->setCountry('no country'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testCountrySetter() |
91
|
|
|
{ |
92
|
|
|
$object = new GenericConfiguration(); |
93
|
|
|
$object->setCountry('DE'); |
94
|
|
|
|
95
|
|
|
$this->assertEquals('de', $object->getCountry()); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
class CallableClass |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
public static function foo() |
102
|
|
|
{ |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.