Implement option to capture output of Curl::diagnose()

This commit is contained in:
Zach Borboa
2021-07-20 23:28:20 -04:00
parent 7348de72f3
commit 1226bb1a6c
3 changed files with 34 additions and 8 deletions
+1 -1
View File
@@ -203,7 +203,7 @@ Curl::call()
Curl::close()
Curl::complete($callback)
Curl::delete($url, $query_parameters = [], $data = [])
Curl::diagnose()
Curl::diagnose($return = false)
Curl::disableTimeout()
Curl::download($url, $mixed_filename)
Curl::error($callback)
+12 -1
View File
@@ -1436,9 +1436,14 @@ class Curl
* Diagnose
*
* @access public
* @param bool $return
*/
public function diagnose()
public function diagnose($return = false)
{
if ($return) {
ob_start();
}
echo "\n";
echo '--- Begin PHP Curl Class diagnostic output ---' . "\n";
echo 'PHP Curl Class version: ' . self::VERSION . "\n";
@@ -1527,6 +1532,12 @@ class Curl
echo '--- End PHP Curl Class diagnostic output ---' . "\n";
echo "\n";
if ($return) {
$output = ob_get_contents();
ob_end_clean();
return $output;
}
}
/**
+21 -6
View File
@@ -4030,12 +4030,25 @@ class CurlTest extends \PHPUnit\Framework\TestCase
public function testDiagnose()
{
$test = new Test();
$test->server('error_message', 'GET');
// Test diagnose() with default parameters.
$test_1 = new Test();
$test_1->server('error_message', 'GET');
ob_start();
$test->curl->diagnose();
$output = ob_get_contents();
$test_1->curl->diagnose();
$test_1_output = ob_get_contents();
ob_end_clean();
// Test diagnose() with return=true.
$test_2 = new Test();
$test_2->server('error_message', 'GET');
$test_2_output = $test_2->curl->diagnose(true);
// Test diagnose() with return=false.
$test_3 = new Test();
$test_3->server('error_message', 'GET');
ob_start();
$test_3->curl->diagnose(false);
$test_3_output = ob_get_contents();
ob_end_clean();
foreach ([
@@ -4049,7 +4062,9 @@ class CurlTest extends \PHPUnit\Framework\TestCase
'Received an empty response body (response="").',
'--- End PHP Curl Class diagnostic output ---',
] as $expected_string) {
$this->assertStringContainsString($expected_string, $output);
$this->assertStringContainsString($expected_string, $test_1_output);
$this->assertStringContainsString($expected_string, $test_2_output);
$this->assertStringContainsString($expected_string, $test_3_output);
}
}
}