mirror of
https://github.com/holidayapi/holidayapi-php.git
synced 2025-06-21 04:16:31 +00:00
Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
f8e945bacd | |||
15052790c5 |
6 changed files with 6 additions and 435 deletions
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
|
@ -6,7 +6,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
php-version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
|
||||
php-version: ['8.0', '8.1', '8.2', '8.3', '8.4']
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
@ -23,7 +23,7 @@ jobs:
|
|||
- name: Run Tests
|
||||
run: vendor/bin/phpunit --coverage-clover ./coverage.xml
|
||||
- name: Upload Coverage
|
||||
if: ${{ matrix.php-version == '8.0' }}
|
||||
if: ${{ matrix.php-version == '8.2' }}
|
||||
uses: codecov/codecov-action@v1
|
||||
with:
|
||||
file: ./coverage.xml
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2016, 2017, 2018, 2019, 2020 Gravity Boulevard, LLC
|
||||
Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Gravity Boulevard, LLC
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
[](https://github.com/holidayapi/holidayapi-php/blob/master/LICENSE)
|
||||

|
||||
[](https://github.com/holidayapi/holidayapi-php/actions)
|
||||
[](https://codecov.io/gh/holidayapi/holidayapi-php)
|
||||
|
||||
Official PHP library for [Holiday API](https://holidayapi.com) providing quick
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "holidayapi/holidayapi-php",
|
||||
"description": "Official PHP library for Holiday API",
|
||||
"version": "2.4.0",
|
||||
"version": "4.0.0",
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"calendar",
|
||||
|
@ -17,12 +17,12 @@
|
|||
"homepage": "https://holidayapi.com"
|
||||
}],
|
||||
"require": {
|
||||
"php": ">=5.3",
|
||||
"php": ">=8.0",
|
||||
"ext-json": "*",
|
||||
"ext-curl": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.36 || ^9.0"
|
||||
"phpunit/phpunit": "^9.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
|
@ -64,17 +64,6 @@ class Client
|
|||
|
||||
public function holidays($request)
|
||||
{
|
||||
if (!isset($request['country'])) {
|
||||
throw new \Exception('Missing country');
|
||||
} elseif (!isset($request['year'])) {
|
||||
throw new \Exception('Missing year');
|
||||
} elseif (
|
||||
isset($request['previous'], $request['upcoming'])
|
||||
&& $request['previous'] && $request['upcoming']
|
||||
) {
|
||||
throw new \Exception('Previous and upcoming are mutually exclusive');
|
||||
}
|
||||
|
||||
return $this->request('holidays', $request);
|
||||
}
|
||||
|
||||
|
@ -85,29 +74,11 @@ class Client
|
|||
|
||||
public function workday($request)
|
||||
{
|
||||
if (!isset($request['country'])) {
|
||||
throw new \Exception('Missing country');
|
||||
} elseif (!isset($request['start'])) {
|
||||
throw new \Exception('Missing start date');
|
||||
} elseif (!isset($request['days'])) {
|
||||
throw new \Exception('Missing days');
|
||||
} elseif ($request['days'] < 1) {
|
||||
throw new \Exception('Days must be 1 or more');
|
||||
}
|
||||
|
||||
return $this->request('workday', $request);
|
||||
}
|
||||
|
||||
public function workdays($request)
|
||||
{
|
||||
if (!isset($request['country'])) {
|
||||
throw new \Exception('Missing country');
|
||||
} elseif (!isset($request['start'])) {
|
||||
throw new \Exception('Missing start date');
|
||||
} elseif (!isset($request['end'])) {
|
||||
throw new \Exception('Missing end date');
|
||||
}
|
||||
|
||||
return $this->request('workdays', $request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,108 +113,6 @@ class ClientTest extends TestCase
|
|||
), $client->countries());
|
||||
}
|
||||
|
||||
public function testSearchCountries()
|
||||
{
|
||||
$url = self::BASE_URL . 'countries?key=' . self::KEY . '&search=Sao';
|
||||
|
||||
$request = new Request(array(
|
||||
'execute' => array(
|
||||
$url => function ()
|
||||
{
|
||||
return json_encode(array(
|
||||
'status' => 200,
|
||||
'countries' => array(
|
||||
array(
|
||||
'code' => 'ST',
|
||||
'name' => 'Sao Tome and Principle',
|
||||
),
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
));
|
||||
|
||||
$client = new Client(array('key' => self::KEY, 'handler' => $request));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'status' => 200,
|
||||
'countries' => array(
|
||||
array(
|
||||
'code' => 'ST',
|
||||
'name' => 'Sao Tome and Principle',
|
||||
),
|
||||
),
|
||||
), $client->countries(array('search' => 'Sao')));
|
||||
}
|
||||
|
||||
public function testReturnCountryByCode()
|
||||
{
|
||||
$url = self::BASE_URL . 'countries?key=' . self::KEY . '&country=ST';
|
||||
|
||||
$request = new Request(array(
|
||||
'execute' => array(
|
||||
$url => function ()
|
||||
{
|
||||
return json_encode(array(
|
||||
'status' => 200,
|
||||
'countries' => array(
|
||||
array(
|
||||
'code' => 'ST',
|
||||
'name' => 'Sao Tome and Principle',
|
||||
),
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
));
|
||||
|
||||
$client = new Client(array('key' => self::KEY, 'handler' => $request));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'status' => 200,
|
||||
'countries' => array(
|
||||
array(
|
||||
'code' => 'ST',
|
||||
'name' => 'Sao Tome and Principle',
|
||||
),
|
||||
),
|
||||
), $client->countries(array('country' => 'ST')));
|
||||
}
|
||||
|
||||
public function testReturnCountryWithPublic()
|
||||
{
|
||||
$url = self::BASE_URL . 'countries?key=' . self::KEY . '&public=1';
|
||||
|
||||
$request = new Request(array(
|
||||
'execute' => array(
|
||||
$url => function ()
|
||||
{
|
||||
return json_encode(array(
|
||||
'status' => 200,
|
||||
'countries' => array(
|
||||
array(
|
||||
'code' => 'ST',
|
||||
'name' => 'Sao Tome and Principle',
|
||||
),
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
));
|
||||
|
||||
$client = new Client(array('key' => self::KEY, 'handler' => $request));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'status' => 200,
|
||||
'countries' => array(
|
||||
array(
|
||||
'code' => 'ST',
|
||||
'name' => 'Sao Tome and Principle',
|
||||
),
|
||||
),
|
||||
), $client->countries(array('public' => true)));
|
||||
}
|
||||
|
||||
public function testCountriesRaise4xxErrors()
|
||||
{
|
||||
$url = self::BASE_URL . 'countries?key=' . self::KEY;
|
||||
|
@ -312,106 +210,6 @@ class ClientTest extends TestCase
|
|||
)));
|
||||
}
|
||||
|
||||
public function testSearchHolidays()
|
||||
{
|
||||
$url = self::BASE_URL . 'holidays?key=' . self::KEY . '&country=US&year=2015&search=Independence';
|
||||
|
||||
$request = new Request(array(
|
||||
'execute' => array(
|
||||
$url => function ()
|
||||
{
|
||||
return json_encode(array(
|
||||
'status' => 200,
|
||||
'holidays' => array(
|
||||
array(
|
||||
'name' => 'Independence Day',
|
||||
'date' => '2015-07-04',
|
||||
'observed' => '2015-07-03',
|
||||
'public' => true,
|
||||
),
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
));
|
||||
|
||||
$client = new Client(array('key' => self::KEY, 'handler' => $request));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'status' => 200,
|
||||
'holidays' => array(
|
||||
array(
|
||||
'name' => 'Independence Day',
|
||||
'date' => '2015-07-04',
|
||||
'observed' => '2015-07-03',
|
||||
'public' => true,
|
||||
),
|
||||
),
|
||||
), $client->holidays(array(
|
||||
'country' => 'US',
|
||||
'year' => 2015,
|
||||
'search' => 'Independence',
|
||||
)));
|
||||
}
|
||||
|
||||
public function testHolidaysCountryMissing()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||
$assertRegExp = 'assertMatchesRegularExpression';
|
||||
} else {
|
||||
$assertRegExp = 'assertRegExp';
|
||||
}
|
||||
|
||||
$client = new Client(array('key' => self::KEY));
|
||||
|
||||
try {
|
||||
$client->holidays(array('year' => 2015));
|
||||
} catch (\Exception $e) {
|
||||
$this->$assertRegExp('/missing country/i', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testHolidaysYearMissing()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||
$assertRegExp = 'assertMatchesRegularExpression';
|
||||
} else {
|
||||
$assertRegExp = 'assertRegExp';
|
||||
}
|
||||
|
||||
$client = new Client(array('key' => self::KEY));
|
||||
|
||||
try {
|
||||
$client->holidays(array('country' => 'US'));
|
||||
} catch (\Exception $e) {
|
||||
$this->$assertRegExp('/missing year/i', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testHolidaysBothPreviousAndUpcoming()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||
$assertRegExp = 'assertMatchesRegularExpression';
|
||||
} else {
|
||||
$assertRegExp = 'assertRegExp';
|
||||
}
|
||||
|
||||
$client = new Client(array('key' => self::KEY));
|
||||
|
||||
try {
|
||||
$client->holidays(array(
|
||||
'country' => 'US',
|
||||
'year' => 2015,
|
||||
'month' => 7,
|
||||
'day' => 4,
|
||||
'upcoming' => true,
|
||||
'previous' => true,
|
||||
));
|
||||
} catch (\Exception $e) {
|
||||
$this->$assertRegExp('/previous and upcoming/i', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testHolidaysRaise4xxErrors()
|
||||
{
|
||||
$url = self::BASE_URL . 'holidays?key=' . self::KEY . '&country=US&year=2019';
|
||||
|
@ -500,74 +298,6 @@ class ClientTest extends TestCase
|
|||
), $client->languages());
|
||||
}
|
||||
|
||||
public function testSearchLanguages()
|
||||
{
|
||||
$url = self::BASE_URL . 'languages?key=' . self::KEY . '&search=Eng';
|
||||
|
||||
$request = new Request(array(
|
||||
'execute' => array(
|
||||
$url => function ()
|
||||
{
|
||||
return json_encode(array(
|
||||
'status' => 200,
|
||||
'languages' => array(
|
||||
array(
|
||||
'code' => 'en',
|
||||
'name' => 'English',
|
||||
),
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
));
|
||||
|
||||
$client = new Client(array('key' => self::KEY, 'handler' => $request));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'status' => 200,
|
||||
'languages' => array(
|
||||
array(
|
||||
'code' => 'en',
|
||||
'name' => 'English',
|
||||
),
|
||||
),
|
||||
), $client->languages(array('search' => 'Eng')));
|
||||
}
|
||||
|
||||
public function testReturnLanguageByCode()
|
||||
{
|
||||
$url = self::BASE_URL . 'languages?key=' . self::KEY . '&language=en';
|
||||
|
||||
$request = new Request(array(
|
||||
'execute' => array(
|
||||
$url => function ()
|
||||
{
|
||||
return json_encode(array(
|
||||
'status' => 200,
|
||||
'languages' => array(
|
||||
array(
|
||||
'code' => 'en',
|
||||
'name' => 'English',
|
||||
),
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
));
|
||||
|
||||
$client = new Client(array('key' => self::KEY, 'handler' => $request));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'status' => 200,
|
||||
'languages' => array(
|
||||
array(
|
||||
'code' => 'en',
|
||||
'name' => 'English',
|
||||
),
|
||||
),
|
||||
), $client->languages(array('language' => 'en')));
|
||||
}
|
||||
|
||||
public function testLanguagesRaise4xxErrors()
|
||||
{
|
||||
$url = self::BASE_URL . 'languages?key=' . self::KEY;
|
||||
|
@ -654,81 +384,6 @@ class ClientTest extends TestCase
|
|||
)));
|
||||
}
|
||||
|
||||
public function testWorkdayCountryMissing()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||
$assertRegExp = 'assertMatchesRegularExpression';
|
||||
} else {
|
||||
$assertRegExp = 'assertRegExp';
|
||||
}
|
||||
|
||||
$client = new Client(array('key' => self::KEY));
|
||||
|
||||
try {
|
||||
$client->workday(array());
|
||||
} catch (\Exception $e) {
|
||||
$this->$assertRegExp('/missing country/i', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testWorkdayStartMissing()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||
$assertRegExp = 'assertMatchesRegularExpression';
|
||||
} else {
|
||||
$assertRegExp = 'assertRegExp';
|
||||
}
|
||||
|
||||
$client = new Client(array('key' => self::KEY));
|
||||
|
||||
try {
|
||||
$client->workday(array('country' => 'US'));
|
||||
} catch (\Exception $e) {
|
||||
$this->$assertRegExp('/missing start date/i', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testWorkdayDaysMissing()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||
$assertRegExp = 'assertMatchesRegularExpression';
|
||||
} else {
|
||||
$assertRegExp = 'assertRegExp';
|
||||
}
|
||||
|
||||
$client = new Client(array('key' => self::KEY));
|
||||
|
||||
try {
|
||||
$client->workday(array(
|
||||
'country' => 'US',
|
||||
'start' => '2019-07-01',
|
||||
));
|
||||
} catch (\Exception $e) {
|
||||
$this->$assertRegExp('/missing days/i', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testWorkdayDaysNegative()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||
$assertRegExp = 'assertMatchesRegularExpression';
|
||||
} else {
|
||||
$assertRegExp = 'assertRegExp';
|
||||
}
|
||||
|
||||
$client = new Client(array('key' => self::KEY));
|
||||
|
||||
try {
|
||||
$client->workday(array(
|
||||
'country' => 'US',
|
||||
'start' => '2019-07-01',
|
||||
'days' => -10,
|
||||
));
|
||||
} catch (\Exception $e) {
|
||||
$this->$assertRegExp('/days must be 1 or more/i', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testWorkdayRaise4xxErrors()
|
||||
{
|
||||
$url = self::BASE_URL . 'workday?key=' . self::KEY . '&country=US&start=2019-07-01&days=10';
|
||||
|
@ -819,60 +474,6 @@ class ClientTest extends TestCase
|
|||
)));
|
||||
}
|
||||
|
||||
public function testWorkdaysCountryMissing()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||
$assertRegExp = 'assertMatchesRegularExpression';
|
||||
} else {
|
||||
$assertRegExp = 'assertRegExp';
|
||||
}
|
||||
|
||||
$client = new Client(array('key' => self::KEY));
|
||||
|
||||
try {
|
||||
$client->workdays(array());
|
||||
} catch (\Exception $e) {
|
||||
$this->$assertRegExp('/missing country/i', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testWorkdaysStartMissing()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||
$assertRegExp = 'assertMatchesRegularExpression';
|
||||
} else {
|
||||
$assertRegExp = 'assertRegExp';
|
||||
}
|
||||
|
||||
$client = new Client(array('key' => self::KEY));
|
||||
|
||||
try {
|
||||
$client->workdays(array('country' => 'US'));
|
||||
} catch (\Exception $e) {
|
||||
$this->$assertRegExp('/missing start date/i', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testWorkdaysEndMissing()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||
$assertRegExp = 'assertMatchesRegularExpression';
|
||||
} else {
|
||||
$assertRegExp = 'assertRegExp';
|
||||
}
|
||||
|
||||
$client = new Client(array('key' => self::KEY));
|
||||
|
||||
try {
|
||||
$client->workdays(array(
|
||||
'country' => 'US',
|
||||
'start' => '2019-07-01',
|
||||
));
|
||||
} catch (\Exception $e) {
|
||||
$this->$assertRegExp('/missing end date/i', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testWorkdaysRaise4xxErrors()
|
||||
{
|
||||
$url = self::BASE_URL . 'workdays?key=' . self::KEY . '&country=US&start=2019-07-01&end=2019-07-10';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue