|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use P2A\YourMembership\Core\Request; |
|
4
|
|
|
|
|
5
|
|
|
class RequestTest extends \Codeception\Test\Unit |
|
|
|
|
|
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var \UnitTester |
|
9
|
|
|
*/ |
|
10
|
|
|
protected $tester; |
|
11
|
|
|
|
|
12
|
|
|
protected function _before() |
|
13
|
|
|
{ |
|
14
|
|
|
require_once (__DIR__ . '/../../../vendor/autoload.php'); // Autoload files using Composer autoload |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
protected function _after() |
|
18
|
|
|
{ |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
public function testBuildBasePayload() { |
|
23
|
|
|
|
|
24
|
|
|
$apiKey = 'A'; |
|
25
|
|
|
$saPasscode ='B'; |
|
26
|
|
|
$request = new Request($apiKey, $saPasscode); |
|
27
|
|
|
|
|
28
|
|
|
$xml = $request->buildBasePayload(); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertEquals(Request::$API_VERSION, $xml->Version, 'Versions Do Not Match'); |
|
31
|
|
|
$this->assertEquals($apiKey, $xml->ApiKey, 'API Key Does not Match'); |
|
32
|
|
|
$this->assertEquals($saPasscode, $xml->SaPasscode,'Sa Passcode Does not match'); |
|
33
|
|
|
$this->assertEquals('1', $xml->CallID, 'Call ID does not match'); |
|
34
|
|
|
|
|
35
|
|
|
codecept_debug($xml->asXML()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
public function testCreateCallPayLoad() |
|
40
|
|
|
{ |
|
41
|
|
|
//Setup |
|
42
|
|
|
$apiKey = 'A'; |
|
43
|
|
|
$saPasscode ='B'; |
|
44
|
|
|
$method = 'testMethod'; |
|
45
|
|
|
$arguments = ['arg1' => 'value1', 'arg2' => 'value2']; |
|
46
|
|
|
$request = new Request($apiKey, $saPasscode); |
|
47
|
|
|
//Execute |
|
48
|
|
|
$xml = $request->createCallPayload($method, $arguments); |
|
49
|
|
|
|
|
50
|
|
|
$attributes = $xml->attributes(); |
|
51
|
|
|
|
|
52
|
|
|
//Verify Method Signature |
|
53
|
|
|
$this->assertNotEmpty($attributes['method'], 'Call Method Incorrect'); |
|
54
|
|
|
$this->assertEquals($method, $attributes['method'], 'Call Method Incorrect'); |
|
55
|
|
|
|
|
56
|
|
|
$children = $xml->children(); |
|
57
|
|
|
//Verify Method Arguments |
|
58
|
|
|
//Invert Children and Arguments because Children is not Array Iterable... |
|
59
|
|
View Code Duplication |
foreach ($children as $key => $value) { |
|
|
|
|
|
|
60
|
|
|
$this->assertArrayHasKey($key, $arguments, 'Argument Does Not Exist'); |
|
61
|
|
|
$this->assertEquals($value, $arguments[$key], 'Invalid Argument'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
codecept_debug($xml->asXML()); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testBuildXMLPayload() { |
|
68
|
|
|
|
|
69
|
|
|
$apiKey = 'A'; |
|
70
|
|
|
$saPasscode ='B'; |
|
71
|
|
|
$method = 'testMethod'; |
|
72
|
|
|
$arguments = ['arg1' => 'value1', 'arg2' => 'value2']; |
|
73
|
|
|
$request = new Request($apiKey, $saPasscode); |
|
74
|
|
|
|
|
75
|
|
|
$xml = $request->buildXMLPayload($method,$arguments); |
|
76
|
|
|
codecept_debug($xml->asXML()); |
|
77
|
|
|
//Verify |
|
78
|
|
|
$this->assertEquals(Request::$API_VERSION, $xml->Version, 'Versions Do Not Match'); |
|
79
|
|
|
$this->assertEquals($apiKey, $xml->ApiKey, 'API Key Does not Match'); |
|
80
|
|
|
$this->assertEquals($saPasscode, $xml->SaPasscode,'Sa Passcode Does not match'); |
|
81
|
|
|
$this->assertEquals('1', $xml->CallID, 'Call ID does not match'); |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
$attributes = $xml->Call->attributes(); |
|
85
|
|
|
|
|
86
|
|
|
//Verify Method Signature |
|
87
|
|
|
$this->assertNotEmpty($attributes['method'], 'Call Method Incorrect'); |
|
88
|
|
|
$this->assertEquals($method, $attributes['method'], 'Call Method Incorrect'); |
|
89
|
|
|
|
|
90
|
|
|
$children = $xml->Call->children(); |
|
91
|
|
|
//Verify Method Arguments |
|
92
|
|
|
//Invert Children and Arguments because Children is not Array Iterable... |
|
93
|
|
View Code Duplication |
foreach ($children as $key => $value) { |
|
|
|
|
|
|
94
|
|
|
$this->assertArrayHasKey($key, $arguments, 'Argument Does Not Exist'); |
|
95
|
|
|
$this->assertEquals($value, $arguments[$key], 'Invalid Argument'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
codecept_debug($xml->asXML()); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.