2929
3030function curl_exec ($ ch )
3131{
32- $ data = array ('response ' =>'{"content": "Mocked response content"} ' );
33- return '{"content": "Mocked response content"} ' ;
32+ // mock response
33+ // Note: The X's are set to a length to make the header = 200, which is necessary to force a correct
34+ // boundary between the header and body.
35+ $ mock_response = 'HTTP/1.1 200 OK ' .PHP_EOL ;
36+ $ mock_response .= 'Content-Type: application/json ' .PHP_EOL ;
37+ $ mock_response .= 'Date: Thu, 31 Mar 2016 13:12:00 GMT ' .PHP_EOL ;
38+ $ mock_response .= 'Server: openresty/1.9.7.3 ' .PHP_EOL ;
39+ $ mock_response .= 'X-RosetteAPI-Request-Id: XXXXXXXXXXXXXXXXXXXXXXXX ' .PHP_EOL ;
40+ $ mock_response .= 'Content-Length: 95 ' .PHP_EOL ;
41+ $ mock_response .= 'Connection: keep-alive ' .PHP_EOL ;
42+ $ mock_response .= PHP_EOL ;
43+ $ mock_response .= '{"name":"Rosette API","version":"0.10.3","buildNumber":"","buildTime":"","versionChecked":true} ' ;
44+
45+ return $ mock_response ;
3446}
3547
3648function curl_getinfo ($ ch )
@@ -71,9 +83,6 @@ public static function setupBeforeClass()
7183 */
7284 private function getMockedResponse ($ filename )
7385 {
74- //$response = json_decode(\file_get_contents(self::$responseDir . $filename . '.json'), true);
75-
76- //return $response;
7786 return curl_exec ($ ch = null );
7887 }
7988
@@ -86,7 +95,6 @@ private function getMockedResponse($filename)
8695 */
8796 private function getMockedResponseCode ($ filename )
8897 {
89- //return intval(\file_get_contents(self::$responseDir . $filename . '.status'));
9098 return curl_getinfo ($ ch = null );
9199 }
92100
@@ -110,37 +118,37 @@ private function setUpApi($userKey)
110118
111119 /**
112120 * @group posts
113- * @expectedException \rosette\api\RosetteException
114121 */
115122 public function testCheckVersion ()
116123 {
117124 $ this ->userKey = 'checkVersion ' ;
118125 $ api = $ this ->setUpApi ($ this ->userKey );
119- $ api ->checkVersion ('http://rosette.basistech.com ' );
126+ $ result = $ api ->checkVersion ('http://rosette.basistech.com ' );
127+ $ this ->assertTrue ($ result );
120128 }
121129
122130 /**
123131 * @group gets
124132 */
125133 public function testInfo ()
126134 {
127- $ expected = $ this -> getMockedResponse ( ' info ' ) ;
135+ $ expected = " Rosette API " ;
128136 $ this ->userKey = 'info ' ;
129137 $ api = $ this ->setUpApi ($ this ->userKey );
130138 $ result = $ api ->info ();
131- $ this ->assertSame ($ expected , $ result [0 ]);
139+ $ this ->assertSame ($ expected , $ result [" name " ]);
132140 }
133141
134142 /**
135143 * @group gets
136144 */
137145 public function testPing ()
138146 {
139- $ expected = $ this -> getMockedResponse ( ' ping ' ) ;
147+ $ expected = " Rosette API " ;
140148 $ this ->userKey = 'ping ' ;
141149 $ api = $ this ->setUpApi ($ this ->userKey );
142150 $ result = $ api ->ping ();
143- $ this ->assertSame ($ expected , $ result [0 ]);
151+ $ this ->assertSame ($ expected , $ result [" name " ]);
144152 }
145153
146154 /**
@@ -198,7 +206,7 @@ public function testEndpoints($filename, $endpoint)
198206 $ api ->skipVersionCheck (); // need to set it so it doesn't call the mocked info()
199207 $ api ->setDebug (true );
200208 $ input = $ this ->getRequestData ($ this ->userKey );
201- $ expected = $ this -> getMockedResponse ( $ this -> userKey ) ;
209+ $ expected = " Rosette API " ;
202210 if ($ endpoint === 'name-similarity ' ) {
203211 $ sourceName = new Name (
204212 $ input ['name1 ' ]['text ' ],
@@ -232,43 +240,34 @@ public function testEndpoints($filename, $endpoint)
232240 // If it does not throw an exception, check that it was not supposed to and if so check that it
233241 // returns the correct thing.
234242 // If it throws an exception, check that it was supposed to and if so pass otherwise fail test.
235- //try {
236- $ result = '' ;
237- if ($ endpoint === 'categories ' ) {
238- $ result = $ api ->categories ($ params );
239- }
240- if ($ endpoint === 'entities ' ) {
241- $ result = $ api ->entities ($ params );
242- }
243- if ($ endpoint === 'entities_linked ' ) {
244- $ result = $ api ->entities ($ params , true );
245- }
246- if ($ endpoint === 'language ' ) {
247- $ result = $ api ->language ($ params );
248- }
249- if ($ endpoint === 'name-similarity ' ) {
250- $ result = $ api ->nameSimilarity ($ params );
251- }
252- if ($ endpoint === 'morphology_complete ' ) {
253- $ result = $ api ->morphology ($ params );
254- }
255- if ($ endpoint === 'sentiment ' ) {
256- $ result = $ api ->sentiment ($ params );
257- }
258- if ($ endpoint === 'name-translation ' ) {
259- $ result = $ api ->nameTranslation ($ params );
260- }
261- if ($ endpoint === 'relationships ' ) {
262- $ result = $ api ->relationships ($ params );
263- }
264- // If there is a "code" key, it means an exception should be thrown
265- //if (!array_key_exists('code', $expected)) {
266- $ this ->assertEquals ($ expected , $ result [0 ]);
267-
268- //}
269- //} catch (RosetteException $exception) {
270- // $this->assertSame('unsupportedLanguage', $expected['code']);
271- //}
243+ $ result = '' ;
244+ if ($ endpoint === 'categories ' ) {
245+ $ result = $ api ->categories ($ params );
246+ }
247+ if ($ endpoint === 'entities ' ) {
248+ $ result = $ api ->entities ($ params );
249+ }
250+ if ($ endpoint === 'entities_linked ' ) {
251+ $ result = $ api ->entities ($ params , true );
252+ }
253+ if ($ endpoint === 'language ' ) {
254+ $ result = $ api ->language ($ params );
255+ }
256+ if ($ endpoint === 'name-similarity ' ) {
257+ $ result = $ api ->nameSimilarity ($ params );
258+ }
259+ if ($ endpoint === 'morphology_complete ' ) {
260+ $ result = $ api ->morphology ($ params );
261+ }
262+ if ($ endpoint === 'sentiment ' ) {
263+ $ result = $ api ->sentiment ($ params );
264+ }
265+ if ($ endpoint === 'name-translation ' ) {
266+ $ result = $ api ->nameTranslation ($ params );
267+ }
268+ if ($ endpoint === 'relationships ' ) {
269+ $ result = $ api ->relationships ($ params );
270+ }
271+ $ this ->assertEquals ($ expected , $ result ["name " ]);
272272 }
273-
274273}
0 commit comments