Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
westy92 committed Dec 29, 2022
1 parent c1b2137 commit eb6983d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public function getEventInfo(string $id, ?int $start = null, ?int $end = null):
'id' => $id,
];
if ($start != null) {
$params['start'] = intval($start);
$params['start'] = strval($start);
}
if ($end != null) {
$params['end'] = intval($end);
$params['end'] = strval($end);
}
return $this->request('event', $params, Model\GetEventInfoResponse::class);
}
Expand Down
18 changes: 6 additions & 12 deletions test/CommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
use GuzzleHttp\Psr7\Request;

require_once 'TestClient.php';

$getEventsDefaultJson = file_get_contents(__DIR__ . '/getEvents-default.json');
require_once 'TestJson.php';

final class CommonTest extends TestCase
{
Expand All @@ -31,8 +30,7 @@ public function testSendsApiKey(): void
$this->mock->append(
function (\GuzzleHttp\Psr7\Request $request) {
$this->assertEquals(['abc123'], $request->getHeader('apikey'));
global $getEventsDefaultJson;
return new Response(200, [], $getEventsDefaultJson);
return new Response(200, [], TestJson::getEventsDefaultJson());
},
);
$client = new TestClient('abc123', $this->mock);
Expand All @@ -44,8 +42,7 @@ public function testSendsUserAgent(): void
$this->mock->append(
function (\GuzzleHttp\Psr7\Request $request) {
$this->assertEquals(['HolidayApiPHP/1.0.0'], $request->getHeader('user-agent'));
global $getEventsDefaultJson;
return new Response(200, [], $getEventsDefaultJson);
return new Response(200, [], TestJson::getEventsDefaultJson());
},
);
$client = new TestClient('abc123', $this->mock);
Expand All @@ -57,8 +54,7 @@ public function testSendsPlatformVersion(): void
$this->mock->append(
function (\GuzzleHttp\Psr7\Request $request) {
$this->assertEquals([phpversion()], $request->getHeader('x-platform-version'));
global $getEventsDefaultJson;
return new Response(200, [], $getEventsDefaultJson);
return new Response(200, [], TestJson::getEventsDefaultJson());
},
);
$client = new TestClient('abc123', $this->mock);
Expand Down Expand Up @@ -127,8 +123,7 @@ function (\GuzzleHttp\Psr7\Request $request) {
},
function (\GuzzleHttp\Psr7\Request $request) {
$this->assertEquals('https://www.google.com', $request->getUri());
global $getEventsDefaultJson;
return new Response(200, [], $getEventsDefaultJson);
return new Response(200, [], TestJson::getEventsDefaultJson());
},
);
$client = new TestClient('abc123', $this->mock);
Expand All @@ -137,12 +132,11 @@ function (\GuzzleHttp\Psr7\Request $request) {

public function testReportsRateLimits(): void
{
global $getEventsDefaultJson;
$this->mock->append(
new Response(200, [
'X-RateLimit-Remaining-Month' => '123',
'X-RateLimit-Limit-Month' => '456',
], $getEventsDefaultJson),
], TestJson::getEventsDefaultJson()),
);
$client = new TestClient('abc123', $this->mock);
$result = $client->getEvents();
Expand Down
11 changes: 3 additions & 8 deletions test/GetEventInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
use PHPUnit\Framework\TestCase;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Psr7\Response;
use Westy92\HolidayEventApi\Model\EventSummary;
use Westy92\HolidayEventApi\Model\Occurrence;

require_once 'TestClient.php';

$getEventInfoDefaultJson = file_get_contents(__DIR__ . '/getEventInfo.json');
$getEventInfoParametersJson = file_get_contents(__DIR__ . '/getEventInfo-parameters.json');
require_once 'TestJson.php';

final class GetEventInfoTest extends TestCase
{
Expand All @@ -32,8 +29,7 @@ public function testGetEventInfoWithDefaultParameters(): void
$this->mock->append(
function (\GuzzleHttp\Psr7\Request $request) {
$this->assertEquals('https://api.apilayer.com/checkiday/event?id=f90b893ea04939d7456f30c54f68d7b4', $request->getUri());
global $getEventInfoDefaultJson;
return new Response(200, [], $getEventInfoDefaultJson);
return new Response(200, [], TestJson::getEventInfoDefaultJson());
},
);
$client = new TestClient('abc123', $this->mock);
Expand All @@ -52,8 +48,7 @@ function (\GuzzleHttp\Psr7\Request $request) {
'start' => '2002',
'end' => '2003',
], $query);
global $getEventInfoParametersJson;
return new Response(200, [], $getEventInfoParametersJson);
return new Response(200, [], TestJson::getEventInfoParametersJson());
},
);
$client = new TestClient('abc123', $this->mock);
Expand Down
10 changes: 3 additions & 7 deletions test/GetEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
use Westy92\HolidayEventApi\Model\EventSummary;

require_once 'TestClient.php';

$getEventsDefaultJson = file_get_contents(__DIR__ . '/getEvents-default.json');
$getEventsParametersJson = file_get_contents(__DIR__ . '/getEvents-parameters.json');
require_once 'TestJson.php';

final class GetEventsTest extends TestCase
{
Expand All @@ -31,8 +29,7 @@ public function testGetEventsWithDefaultParameters(): void
$this->mock->append(
function (\GuzzleHttp\Psr7\Request $request) {
$this->assertEquals('https://api.apilayer.com/checkiday/events?adult=false', $request->getUri());
global $getEventsDefaultJson;
return new Response(200, [], $getEventsDefaultJson);
return new Response(200, [], TestJson::getEventsDefaultJson());
},
);
$client = new TestClient('abc123', $this->mock);
Expand Down Expand Up @@ -61,8 +58,7 @@ function (\GuzzleHttp\Psr7\Request $request) {
'date' => '7/16/1992',
'timezone' => 'America/New_York',
], $query);
global $getEventsParametersJson;
return new Response(200, [], $getEventsParametersJson);
return new Response(200, [], TestJson::getEventsParametersJson());
},
);
$client = new TestClient('abc123', $this->mock);
Expand Down
10 changes: 3 additions & 7 deletions test/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
use Westy92\HolidayEventApi\Model\EventSummary;

require_once 'TestClient.php';

$searchDefaultJson = file_get_contents(__DIR__ . '/search-default.json');
$searchParametersJson = file_get_contents(__DIR__ . '/search-parameters.json');
require_once 'TestJson.php';

final class SearchTest extends TestCase
{
Expand All @@ -36,8 +34,7 @@ function (\GuzzleHttp\Psr7\Request $request) {
'adult' => 'false',
'query' => 'zucchini',
], $query);
global $searchDefaultJson;
return new Response(200, [], $searchDefaultJson);
return new Response(200, [], TestJson::searchDefaultJson());
},
);
$client = new TestClient('abc123', $this->mock);
Expand All @@ -62,8 +59,7 @@ function (\GuzzleHttp\Psr7\Request $request) {
'adult' => 'true',
'query' => 'porch day',
], $query);
global $searchParametersJson;
return new Response(200, [], $searchParametersJson);
return new Response(200, [], TestJson::searchParametersJson());
},
);
$client = new TestClient('abc123', $this->mock);
Expand Down
36 changes: 36 additions & 0 deletions test/TestJson.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Westy92\HolidayEventApi\Tests;

class TestJson
{
public static function getEventsDefaultJson(): string
{
return file_get_contents(__DIR__ . '/getEvents-default.json');
}

public static function getEventsParametersJson(): string
{
return file_get_contents(__DIR__ . '/getEvents-parameters.json');
}

public static function searchDefaultJson(): string
{
return file_get_contents(__DIR__ . '/search-default.json');
}

public static function searchParametersJson(): string
{
return file_get_contents(__DIR__ . '/search-parameters.json');
}

public static function getEventInfoDefaultJson(): string
{
return file_get_contents(__DIR__ . '/getEventInfo.json');
}

public static function getEventInfoParametersJson(): string
{
return file_get_contents(__DIR__ . '/getEventInfo-parameters.json');
}
}

0 comments on commit eb6983d

Please sign in to comment.