1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Kickbox Bundle. |
5
|
|
|
* |
6
|
|
|
* (c) Abdoul Ndiaye <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Andi\KickBoxBundle\Tests\Factory; |
13
|
|
|
|
14
|
|
|
use Andi\KickBoxBundle\Exception\InvalidContentException; |
15
|
|
|
use Andi\KickBoxBundle\Factory\ResponseFactory; |
16
|
|
|
use Andi\KickBoxBundle\Http\Response; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class ResponseFactoryTest |
20
|
|
|
* |
21
|
|
|
* @author Abdoul Ndiaye <[email protected]> |
22
|
|
|
* |
23
|
|
|
* @see Andi\KickBoxBundle\Factory\ResponseFactory |
24
|
|
|
*/ |
25
|
|
|
class ResponseFactoryTest extends \PHPUnit_Framework_TestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
public static $goodHeaders = [ |
31
|
|
|
'X-Kickbox-Balance' => [0 => 1], |
32
|
|
|
'X-Kickbox-Response-Time' => [0 => 5], |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
public static $goodParameters = [ |
39
|
|
|
'domain' => 2, |
40
|
|
|
'email' => 3, |
41
|
|
|
'reason' => 4, |
42
|
|
|
'result' => 6, |
43
|
|
|
'did_you_mean' => 7, |
44
|
|
|
'sendex' => 8, |
45
|
|
|
'user' => 9, |
46
|
|
|
'accept_all' => true, |
47
|
|
|
'free' => false, |
48
|
|
|
'role' => true, |
49
|
|
|
'success' => false, |
50
|
|
|
'disposable' => true, |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @dataProvider getBadValueProvider |
55
|
|
|
* |
56
|
|
|
* @param array $headers |
57
|
|
|
* @param array $parameters |
58
|
|
|
*/ |
59
|
|
|
public function testFactoryWithBadValue(array $headers, array $parameters) |
60
|
|
|
{ |
61
|
|
|
$this->setExpectedException(InvalidContentException::class); |
62
|
|
|
$factory = new ResponseFactory(); |
63
|
|
|
$factory->createResponse($headers, $parameters); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testFactoryWithGoodValue() |
67
|
|
|
{ |
68
|
|
|
$factory = new ResponseFactory(); |
69
|
|
|
$response = $factory->createResponse(self::$goodHeaders, self::$goodParameters); |
70
|
|
|
$this->assertInstanceOf(Response::class, $response); |
71
|
|
|
$this->assertEquals(1, $response->getBalance()); |
72
|
|
|
$this->assertEquals(2, $response->getDomain()); |
73
|
|
|
$this->assertEquals(3, $response->getEmail()); |
74
|
|
|
$this->assertEquals(4, $response->getReason()); |
75
|
|
|
$this->assertEquals(5, $response->getResponseTime()); |
76
|
|
|
$this->assertEquals(6, $response->getResult()); |
77
|
|
|
$this->assertEquals(7, $response->getSuggestion()); |
78
|
|
|
$this->assertEquals(8, $response->getSendex()); |
79
|
|
|
$this->assertEquals(9, $response->getUser()); |
80
|
|
|
|
81
|
|
|
$this->assertTrue($response->isAcceptAll()); |
82
|
|
|
$this->assertTrue($response->isRole()); |
83
|
|
|
$this->assertTrue($response->isDisposable()); |
84
|
|
|
|
85
|
|
|
$this->assertNotTrue($response->isFree()); |
86
|
|
|
$this->assertNotTrue($response->isSuccess()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
public function getBadValueProvider() |
93
|
|
|
{ |
94
|
|
|
return [ |
95
|
|
|
[ |
96
|
|
|
self::$goodHeaders, |
97
|
|
|
[ |
98
|
|
|
'bad value' => '', |
99
|
|
|
], |
100
|
|
|
], |
101
|
|
|
[ |
102
|
|
|
[ |
103
|
|
|
'X--Balance' => [0 => ''], |
104
|
|
|
'X--Response-Time' => [0 => ''], |
105
|
|
|
], |
106
|
|
|
self::$goodParameters, |
107
|
|
|
] |
108
|
|
|
]; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|