mirror of
https://github.com/holidayapi/holidayapi-php.git
synced 2025-06-21 04:16:31 +00:00
Add assertRegExp assertion checking
This commit is contained in:
parent
b398ba5013
commit
c12f512f8a
3 changed files with 89 additions and 17 deletions
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit
|
<phpunit
|
||||||
colors="true"
|
colors="true"
|
||||||
boostrap="./vendor/autoload.php"
|
bootstrap="./vendor/autoload.php"
|
||||||
convertErrorsToExceptions="true"
|
convertErrorsToExceptions="true"
|
||||||
convertNoticesToExceptions="true"
|
convertNoticesToExceptions="true"
|
||||||
convertWarningsToExceptions="true"
|
convertWarningsToExceptions="true"
|
||||||
|
|
|
@ -11,39 +11,63 @@ class ClientTest extends TestCase
|
||||||
|
|
||||||
public function testMissingKey()
|
public function testMissingKey()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$client = new Client(array());
|
new Client(array());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/missing api key/i', $e->getMessage());
|
$this->$assertRegExp('/missing api key/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInvalidKey()
|
public function testInvalidKey()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$client = new Client(array(
|
new Client(array(
|
||||||
'key' => 'zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz',
|
'key' => 'zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz',
|
||||||
));
|
));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/invalid api key/i', $e->getMessage());
|
$this->$assertRegExp('/invalid api key/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVersionTooLow()
|
public function testVersionTooLow()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$client = new Client(array('key' => self::KEY, 'version' => 0));
|
new Client(array('key' => self::KEY, 'version' => 0));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/invalid version/i', $e->getMessage());
|
$this->$assertRegExp('/invalid version/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVersionTooHigh()
|
public function testVersionTooHigh()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$client = new Client(array('key' => self::KEY, 'version' => 2));
|
new Client(array('key' => self::KEY, 'version' => 2));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/invalid version/i', $e->getMessage());
|
$this->$assertRegExp('/invalid version/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,28 +356,46 @@ class ClientTest extends TestCase
|
||||||
|
|
||||||
public function testHolidaysCountryMissing()
|
public function testHolidaysCountryMissing()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
$client = new Client(array('key' => self::KEY));
|
$client = new Client(array('key' => self::KEY));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$client->holidays(array('year' => 2015));
|
$client->holidays(array('year' => 2015));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/missing country/i', $e->getMessage());
|
$this->$assertRegExp('/missing country/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHolidaysYearMissing()
|
public function testHolidaysYearMissing()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
$client = new Client(array('key' => self::KEY));
|
$client = new Client(array('key' => self::KEY));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$client->holidays(array('country' => 'US'));
|
$client->holidays(array('country' => 'US'));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/missing year/i', $e->getMessage());
|
$this->$assertRegExp('/missing year/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHolidaysBothPreviousAndUpcoming()
|
public function testHolidaysBothPreviousAndUpcoming()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
$client = new Client(array('key' => self::KEY));
|
$client = new Client(array('key' => self::KEY));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -366,7 +408,7 @@ class ClientTest extends TestCase
|
||||||
'previous' => true,
|
'previous' => true,
|
||||||
));
|
));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/previous and upcoming/i', $e->getMessage());
|
$this->$assertRegExp('/previous and upcoming/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,28 +656,46 @@ class ClientTest extends TestCase
|
||||||
|
|
||||||
public function testWorkdayCountryMissing()
|
public function testWorkdayCountryMissing()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
$client = new Client(array('key' => self::KEY));
|
$client = new Client(array('key' => self::KEY));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$client->workday(array());
|
$client->workday(array());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/missing country/i', $e->getMessage());
|
$this->$assertRegExp('/missing country/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWorkdayStartMissing()
|
public function testWorkdayStartMissing()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
$client = new Client(array('key' => self::KEY));
|
$client = new Client(array('key' => self::KEY));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$client->workday(array('country' => 'US'));
|
$client->workday(array('country' => 'US'));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/missing start date/i', $e->getMessage());
|
$this->$assertRegExp('/missing start date/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWorkdayDaysMissing()
|
public function testWorkdayDaysMissing()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
$client = new Client(array('key' => self::KEY));
|
$client = new Client(array('key' => self::KEY));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -644,12 +704,18 @@ class ClientTest extends TestCase
|
||||||
'start' => '2019-07-01',
|
'start' => '2019-07-01',
|
||||||
));
|
));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/missing days/i', $e->getMessage());
|
$this->$assertRegExp('/missing days/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWorkdayDaysNegative()
|
public function testWorkdayDaysNegative()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
$client = new Client(array('key' => self::KEY));
|
$client = new Client(array('key' => self::KEY));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -659,7 +725,7 @@ class ClientTest extends TestCase
|
||||||
'days' => -10,
|
'days' => -10,
|
||||||
));
|
));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/days must be 1 or more/i', $e->getMessage());
|
$this->$assertRegExp('/days must be 1 or more/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,12 @@ class RequestTest extends TestCase
|
||||||
|
|
||||||
public function testGet()
|
public function testGet()
|
||||||
{
|
{
|
||||||
|
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
|
||||||
|
$assertRegExp = 'assertMatchesRegularExpression';
|
||||||
|
} else {
|
||||||
|
$assertRegExp = 'assertRegExp';
|
||||||
|
}
|
||||||
|
|
||||||
$url = 'https://holidayapi.com';
|
$url = 'https://holidayapi.com';
|
||||||
|
|
||||||
$request = new Request(array(
|
$request = new Request(array(
|
||||||
|
@ -29,7 +35,7 @@ class RequestTest extends TestCase
|
||||||
try {
|
try {
|
||||||
$request->get($url);
|
$request->get($url);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertRegExp('/empty response/i', $e->getMessage());
|
$this->$assertRegExp('/empty response/i', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue