Skip to content

Commit

Permalink
Fix test for php7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Jun 26, 2021
1 parent cf1993b commit 5cfd645
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 52 deletions.
3 changes: 1 addition & 2 deletions lib/HttpClient/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ public function executeStreamingRequestWithRetries($opts, $absUrl, $readBodyChun
&$numRetries,
&$rcode,
&$lastRHeaders,
&$errno,
&$message
&$errno
) {
$lastRHeaders = $rheaders;
$errno = \curl_errno($this->curlHandle);
Expand Down
40 changes: 1 addition & 39 deletions tests/Stripe/HttpClient/CurlClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,44 +374,6 @@ public function tearDownTestServer()
$this->stopTestServer();
}

// This is a pretty flaky/uncertain way to try and get an
// http server to deliver the body in separate "chunks".
//
// It seems to work but feel free to just skip or delete
// if this flakes.
public function testExecuteRequestWithRetriesCallsWriteFunctionWithChunks()
{
$chunk1 = 'First, bytes';
$chunk2 = 'more bytes';
$chunk3 = 'final bytes';
$serverCode = <<<EOF
<?php
echo "{$chunk1}";
ob_flush();
flush();
\\usleep(1000);
echo "{$chunk2}";
ob_flush();
flush();
\\usleep(1000);
echo "{$chunk3}";
ob_end_flush();
exit();
EOF;
$absUrl = $this->startTestServer($serverCode);
$opts = [];
$opts[\CURLOPT_HTTPGET] = 1;
$opts[\CURLOPT_URL] = $absUrl;
$opts[\CURLOPT_HTTPHEADER] = ['Authorization: Basic c2tfdGVzdF94eXo6'];
$curl = new CurlClient();
$receivedChunks = [];
$curl->executeStreamingRequestWithRetries($opts, $absUrl, function ($chunk) use (&$receivedChunks) {
$receivedChunks[] = $chunk;
});
static::assertSame([$chunk1, $chunk2, $chunk3], $receivedChunks);
$this->stopTestServer();
}

public function testExecuteStreamingRequestWithRetriesRetries()
{
$serverCode = <<<'EOF'
Expand Down Expand Up @@ -492,7 +454,7 @@ public function testExecuteStreamingRequestWithRetriesPersistentConnection()
$curl = new CurlClient();
$coupon = \Stripe\Coupon::retrieve('coupon_xyz');

$absUrl = \Stripe\Stripe::$apiBase . "/v1/coupons/xyz";
$absUrl = \Stripe\Stripe::$apiBase . '/v1/coupons/xyz';
$opts[\CURLOPT_HTTPGET] = 1;
$opts[\CURLOPT_URL] = $absUrl;
$opts[\CURLOPT_HTTPHEADER] = ['Authorization: Basic c2tfdGVzdF94eXo6'];
Expand Down
21 changes: 10 additions & 11 deletions tests/TestServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ trait TestServer
// value to `stripe-mock`'s standard 12111.
protected $serverPort = 12113;


private function lint($path)
{
$output = '';
$exitCode = null;
\exec("php -l {$path}", $output, $exitCode);
if (0 !== $exitCode) {
$text = \implode("\n", $output);
throw new \Exception("Error in test server code: {$text}");
}
$output = '';
$exitCode = null;
\exec("php -l {$path}", $output, $exitCode);
if (0 !== $exitCode) {
$text = \implode("\n", $output);

throw new \Exception("Error in test server code: {$text}");
}
}

/**
* Makes a directory in a temporary path containing only an `index.php` file with
* the specified content ($code).
Expand All @@ -59,6 +60,7 @@ private function makeTemporaryServerDirectory($code)
\fclose($handle);

$this->lint($indexPHP);

return $dir;
}

Expand Down Expand Up @@ -129,9 +131,6 @@ public function stopTestServer()
foreach ($lines as $line) {
if (self::isPHPTestServerRequestLogLine($line)) {
++$n;
} else {
\flush();
\ob_flush();
}
}

Expand Down

0 comments on commit 5cfd645

Please sign in to comment.