Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise testGetForecast to not make live API calls #7

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions tests/Functional/BomClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
namespace BomWeather\Tests\Functional\Forecast;

use BomWeather\BomClient;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

/**
Expand All @@ -15,13 +20,42 @@ class BomClientTest extends TestCase {
* @covers ::__construct()
* @covers ::getForecast()
*/
public function testGetForecast() {

$logger = new NullLogger();
$client = new BomClient($logger);
$forecast = $client->getForecast('IDN10064');

$this->assertNotNull($forecast);
public function testGetForecast()
{
$productId = 'IDN10064';
$logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->never())
->method('error');

$responseBody = file_get_contents(__DIR__ . "/../../tests/fixtures/IDN10064.xml");

$mock = new MockHandler([
new Response(
200,
[
'Accept-Ranges' => 'bytes',
'Connection' => 'keep-alive',
'Content-Encoding' => 'gzip',
'Content-Length' => '2010',
'Content-Type' => 'text/xml',
'Date' => 'Wed, 20 Jun 2018 21:41:57 +0000',
'ETag' => '"42b788-49a7-60e2c007ff680"',
'Last-Modified' => 'Wed, 20 Jun 2018 21:41:57 +0000',
'Server' => 'Apache',
'Server-Timing' => 'cdn-cache; desc=REVALIDATE, edge; dur=46, origin; dur=8, ak_p; desc="1704436748525_388610445_1812004694_5393_6883_16_0_-";dur=1',
'Vary' => 'Accept-Encoding',
],
$responseBody
)
]);

$handlerStack = HandlerStack::create($mock);
$httpClient = new Client(['handler' => $handlerStack]);
$client = new BomClient($logger, $httpClient);
$forecast = $client->getForecast($productId);

$this->assertNotNull($forecast);
}

/**
Expand Down
Loading