Skip to content

Commit

Permalink
Fix issue with Unit tests for PayPal API.
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Aug 24, 2023
1 parent 43dd825 commit f85d269
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</coverage>
<testsuites>
<testsuite name="PayPal Test Suite">
<directory>tests/Feature</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist.php8
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</coverage>
<testsuites>
<testsuite name="PayPal Test Suite">
<directory>tests/Feature</directory>
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
Expand Down
3 changes: 2 additions & 1 deletion tests/MockClientClasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Handler\MockHandler as HttpMockHandler;
use GuzzleHttp\HandlerStack as HttpHandlerStack;
use GuzzleHttp\Psr7\Response as HttpResponse;
use GuzzleHttp\Psr7\Stream as HttpStream;
use GuzzleHttp\Utils;
use Psr\Http\Message\ResponseInterface;
use Srmklive\PayPal\Services\PayPal as PayPalClient;
Expand Down Expand Up @@ -38,7 +39,7 @@ private function mock_http_request($expectedResponse, $expectedEndpoint, $expect
->getMock();
$mockResponse->expects($this->exactly(1))
->method('getBody')
->willReturn($expectedResponse);
->willReturn(new HttpStream(fopen('data://text/plain,' . $expectedResponse, 'r')));

$mockHttpClient = $this->getMockBuilder(HttpClient::class)
->{$set_method_name}([$expectedMethod])
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Client/ReportingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public function it_can_list_transactions()
];

$mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get');
$mockResponse = $mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody();

$this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true));
$this->assertArrayHasKey('transaction_details', Utils::jsonDecode($mockResponse, true));
}

/** @test */
Expand Down

0 comments on commit f85d269

Please sign in to comment.