1 | <?php |
||
25 | final class CURLPostRequestTest extends AbstractCURLRequestTest { |
||
26 | |||
27 | /** |
||
28 | * Tests __construct() method. |
||
29 | * |
||
30 | * @return void |
||
31 | */ |
||
32 | public function testConstructor() { |
||
33 | |||
34 | $obj = new CURLPostRequest($this->configuration, self::RESOURCE_PATH); |
||
35 | |||
36 | $this->assertEquals($this->configuration, $obj->getConfiguration()); |
||
37 | $this->assertEquals([], $obj->getHeaders()); |
||
38 | $this->assertEquals(CURLPostRequest::METHOD_POST, $obj->getMethod()); |
||
39 | $this->assertEquals([], $obj->getPostData()); |
||
40 | $this->assertEquals([], $obj->getQueryData()); |
||
41 | $this->assertEquals("testCall.php", $obj->getResourcePath()); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Tests addPostData() method. |
||
46 | * |
||
47 | * @return void |
||
48 | */ |
||
49 | public function testAddPostData() { |
||
50 | |||
51 | $obj = new CURLPostRequest($this->configuration, self::RESOURCE_PATH); |
||
52 | |||
53 | try { |
||
54 | $obj->addPostData(1, "value"); |
||
55 | } catch (Exception $ex) { |
||
56 | $this->assertInstanceOf(StringArgumentException::class, $ex); |
||
57 | $this->assertEquals("The argument \"1\" is not a string", $ex->getMessage()); |
||
58 | } |
||
59 | |||
60 | $obj->addPostData("name", "value"); |
||
61 | |||
62 | $res = ["name" => "value"]; |
||
63 | $this->assertEquals($res, $obj->getPostData()); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Tests call() method. |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | public function testCall() { |
||
72 | |||
73 | $obj = new CURLPostRequest($this->configuration, self::RESOURCE_PATH); |
||
74 | |||
75 | $obj->addHeader("header", "header"); |
||
76 | $obj->addQueryData("queryData", "queryData"); |
||
77 | |||
78 | $res = $obj->call(); |
||
79 | |||
80 | $this->assertContains("header: header", $res->getRequestHeader()); |
||
81 | $this->assertContains("queryData=queryData", $res->getRequestURL()); |
||
82 | $this->assertEquals(CURLPostRequest::METHOD_POST, json_decode($res->getResponseBody(), true)["method"]); |
||
83 | $this->assertEquals(200, $res->getResponseInfo()["http_code"]); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Tests the clearPostData() method. |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | public function testClearPostData() { |
||
92 | |||
93 | $obj = new CURLPostRequest($this->configuration, self::RESOURCE_PATH); |
||
94 | |||
95 | $obj->addPostData("name", "value"); |
||
96 | $this->assertCount(1, $obj->getPostData()); |
||
97 | |||
98 | $obj->clearPostData(); |
||
99 | $this->assertCount(0, $obj->getPostData()); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Tests removePostData() method. |
||
104 | * |
||
105 | * @return void |
||
106 | */ |
||
107 | public function testRemovePostData() { |
||
108 | |||
109 | $obj = new CURLPostRequest($this->configuration, self::RESOURCE_PATH); |
||
110 | |||
111 | $obj->addPostData("name", "value"); |
||
112 | $this->assertCount(1, $obj->getPostData()); |
||
113 | |||
114 | $obj->removePostData("Name"); |
||
115 | $this->assertCount(1, $obj->getPostData()); |
||
116 | |||
117 | $obj->removePostData("name"); |
||
118 | $this->assertCount(0, $obj->getPostData()); |
||
119 | } |
||
120 | |||
121 | } |
||
122 |