jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/365012 )
Change subject: Curl Wrapper fix and use provider config ...................................................................... Curl Wrapper fix and use provider config Change-Id: Ia30ff1ac43fe5f8040a68259992255802a606e14 --- M Core/Http/CurlWrapper.php M PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php M PaymentProviders/Ingenico/Tests/phpunit/IdealStatusProviderTest.php M Tests/BaseSmashPigUnitTestCase.php 4 files changed, 36 insertions(+), 31 deletions(-) Approvals: jenkins-bot: Verified Ejegg: Looks good to me, approved diff --git a/Core/Http/CurlWrapper.php b/Core/Http/CurlWrapper.php index d4a4bd0..45c749c 100644 --- a/Core/Http/CurlWrapper.php +++ b/Core/Http/CurlWrapper.php @@ -130,17 +130,21 @@ } public static function parseResponse( $response, $curlInfo ) { - $parts = explode( "\r\n\r\n", $response, 2 ); - $headerLines = explode( "\r\n", $parts[0] ); + $header_size = $curlInfo['header_size']; + $header = substr($response, 0, $header_size); + $body = substr($response, $header_size); + $header = str_replace("\r", "", $header); + $headerLines = explode( "\n", $header ); $responseHeaders = array(); foreach( $headerLines as $line ) { if ( strstr( $line, ': ' ) !== false ) { + $line = rtrim($line); list( $name, $value ) = explode( ': ', $line, 2 ); $responseHeaders[$name] = $value; } } return array( - 'body' => $parts[1], + 'body' => $body, 'headers' => $responseHeaders, 'status' => (int)$curlInfo['http_code'] ); diff --git a/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php b/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php index bd4b985..749f2e9 100644 --- a/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php +++ b/PaymentProviders/Ingenico/Tests/phpunit/BankPaymentProviderTest.php @@ -5,7 +5,6 @@ use Psr\Cache\CacheItemPoolInterface; use SmashPig\Core\Cache\HashCacheItem; use SmashPig\Core\Context; -use SmashPig\Core\Http\CurlWrapper; use SmashPig\PaymentProviders\Ingenico\BankPaymentProvider; use SmashPig\Tests\BaseSmashPigUnitTestCase; @@ -32,9 +31,7 @@ public function setUp() { parent::setUp(); - $providerConfiguration = $this->setProviderConfiguration( 'ingenico' ); - $this->curlWrapper = $this->getMock( '\SmashPig\Core\Http\CurlWrapper' ); - $providerConfiguration->overrideObjectInstance( 'curl/wrapper', $this->curlWrapper ); + $this->setProviderConfiguration( 'ingenico' ); $globalConfig = Context::get()->getGlobalConfiguration(); $this->cache = $globalConfig->object( 'cache', true ); @@ -49,7 +46,7 @@ } public function testGetBankList() { - $this->setUpResponse( 'productDirectory', 200 ); + $this->setUpResponse( __DIR__ . '/../Data/productDirectory.response', 200 ); $results = $this->provider->getBankList( 'NL', 'EUR' ); $this->assertEquals( array( @@ -60,7 +57,7 @@ } public function testCacheBankList() { - $this->setUpResponse( 'productDirectory', 200 ); + $this->setUpResponse( __DIR__ . '/../Data/productDirectory.response', 200 ); $this->curlWrapper->expects( $this->once() ) ->method( 'execute' ); $results = $this->provider->getBankList( 'NL', 'EUR' ); @@ -78,7 +75,7 @@ * When the lookup returns 404 we should cache the emptiness */ public function testCacheEmptyBankList() { - $this->setUpResponse( 'emptyDirectory', 404 ); + $this->setUpResponse( __DIR__ . '/../Data/emptyDirectory.response', 404 ); $this->curlWrapper->expects( $this->once() ) ->method( 'execute' ); $results = $this->provider->getBankList( 'NL', 'COP' ); @@ -99,7 +96,7 @@ true ); $this->cache->save( $cacheItem ); - $this->setUpResponse( 'productDirectory', 200 ); + $this->setUpResponse( __DIR__ . '/../Data/productDirectory.response', 200 ); $this->curlWrapper->expects( $this->once() ) ->method( 'execute' ); $results = $this->provider->getBankList( 'NL', 'EUR' ); @@ -109,19 +106,5 @@ ), $results ); - } - - /** - * @param string $filename Name of a file in ../Data representing a - * response (headers, blank line, body), which must use dos-style - * \r\n line endings. - * @param integer $statusCode - */ - protected function setUpResponse( $filename, $statusCode ) { - $contents = file_get_contents( __DIR__ . "/../Data/$filename.response" ); - $parsed = CurlWrapper::parseResponse( - $contents, array( 'http_code' => $statusCode ) - ); - $this->curlWrapper->method( 'execute' )->willReturn( $parsed ); } } diff --git a/PaymentProviders/Ingenico/Tests/phpunit/IdealStatusProviderTest.php b/PaymentProviders/Ingenico/Tests/phpunit/IdealStatusProviderTest.php index b859127..e7c4e82 100644 --- a/PaymentProviders/Ingenico/Tests/phpunit/IdealStatusProviderTest.php +++ b/PaymentProviders/Ingenico/Tests/phpunit/IdealStatusProviderTest.php @@ -46,11 +46,7 @@ ), 'availability-url' => 'http://example.org/undocumented/api/GetIssuers' ) ); - $contents = file_get_contents( __DIR__ . "/../Data/availability.response" ); - $parsed = CurlWrapper::parseResponse( - $contents, array( 'http_code' => 200 ) - ); - $this->curlWrapper->method( 'execute' )->willReturn( $parsed ); + $this->setUpResponse(__DIR__ . "/../Data/availability.response", 200); } public function testGetBankStatus() { diff --git a/Tests/BaseSmashPigUnitTestCase.php b/Tests/BaseSmashPigUnitTestCase.php index 676fc91..f93f8d4 100644 --- a/Tests/BaseSmashPigUnitTestCase.php +++ b/Tests/BaseSmashPigUnitTestCase.php @@ -2,15 +2,20 @@ namespace SmashPig\Tests; use SmashPig\Core\Context; - +use SmashPig\Core\Http\CurlWrapper; use PHPUnit_Framework_TestCase; class BaseSmashPigUnitTestCase extends PHPUnit_Framework_TestCase { + /** + * @var PHPUnit_Framework_MockObject_MockObject + */ + protected $curlWrapper; public function setUp() { parent::setUp(); $globalConfig = TestingGlobalConfiguration::create(); TestingContext::init( $globalConfig ); + $this->curlWrapper = $this->getMock( '\SmashPig\Core\Http\CurlWrapper' ); // TODO: create tables for all dbs/queues. // Standard issue CurlWrapper mock would be nice too } @@ -18,6 +23,22 @@ public function tearDown() { Context::set(); // Nullify the context for next run. } + + /** + * @param string $filepath Full path to file representing a + * response (headers, blank line, body), which must use dos-style + * \r\n line endings. + * @param integer $statusCode + */ + protected function setUpResponse( $filepath, $statusCode ) { + $contents = file_get_contents( $filepath ); + $header_size = strpos($contents, "\r\n\r\n") + 4; + $parsed = CurlWrapper::parseResponse( + $contents, array( 'http_code' => $statusCode, 'header_size' => $header_size) + ); + $this->curlWrapper->method( 'execute' )->willReturn( $parsed ); + } + protected function loadJson( $path ) { return json_decode( file_get_contents( $path ), true ); @@ -32,6 +53,7 @@ $globalConfig = $ctx->getGlobalConfiguration(); $config = TestingProviderConfiguration::createForProvider( $provider, $globalConfig ); $ctx->setProviderConfiguration( $config ); + $config->overrideObjectInstance( 'curl/wrapper', $this->curlWrapper ); return $config; } } -- To view, visit https://gerrit.wikimedia.org/r/365012 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ia30ff1ac43fe5f8040a68259992255802a606e14 Gerrit-PatchSet: 8 Gerrit-Project: wikimedia/fundraising/SmashPig Gerrit-Branch: master Gerrit-Owner: Mepps <me...@wikimedia.org> Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org> Gerrit-Reviewer: Ejegg <ej...@ejegg.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits