@@ -101,7 +101,7 @@ public function addFile(string $fileIdx, string $filePath, bool $reset = false)
101101 * @return string The method will return the output of the endpoint.
102102 */
103103 public function callEndpoint (WebServicesManager $ manager , string $ requestMethod , string $ apiEndpointName , array $ parameters = [], array $ httpHeaders = []) : string {
104- $ manager ->setOutputStream (fopen (self :: DEFAULT_OUTPUT_STREAM ,'w ' ));
104+ $ manager ->setOutputStream (fopen ($ this -> getOutputFile () ,'w ' ));
105105 $ method = strtoupper ($ requestMethod );
106106 putenv ('REQUEST_METHOD= ' .$ method );
107107
@@ -128,7 +128,7 @@ public function callEndpoint(WebServicesManager $manager, string $requestMethod,
128128 }
129129
130130 $ retVal = $ manager ->readOutputStream ();
131- unlink (self :: DEFAULT_OUTPUT_STREAM );
131+ unlink ($ this -> getOutputFile () );
132132
133133 try {
134134 $ json = Json::decode ($ retVal );
@@ -139,6 +139,28 @@ public function callEndpoint(WebServicesManager $manager, string $requestMethod,
139139 }
140140
141141 }
142+ /**
143+ * Creates a formatted string from calling an API.
144+ *
145+ * This helper method can be used to format JSON output of calling an API
146+ * and use it in assertions. The goal of the method is to initially format
147+ * the out put, display it as string and the developer copies the output
148+ * and modify it as needed.
149+ *
150+ * @param string $output
151+ */
152+ public function format (string $ output ) {
153+ $ expl = explode (self ::NL , $ output );
154+ $ nl = '.self::NL\n ' ;
155+ $ count = count ($ expl );
156+
157+ for ($ x = 0 ; $ x < count ($ expl ) ; $ x ++) {
158+ if ($ x + 1 == $ count ) {
159+ $ nl = '' ;
160+ }
161+ echo ". ' $ expl [$ x ]]' " .$ nl ;
162+ }
163+ }
142164 private function parseVal ($ val ) {
143165 $ type = gettype ($ val );
144166
0 commit comments