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

Add more tests #3

Merged
merged 4 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions tests/AdministrativeAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function construction(): void
$this->assertInstanceOf(AdministrativeArea::class, $administrativeArea);
$this->assertSame($code, $administrativeArea->getCode());
$this->assertSame($name, $administrativeArea->getName());
$this->assertSame($usa, $administrativeArea->getCountry());
}

/**
Expand Down
66 changes: 32 additions & 34 deletions tests/CountryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,22 @@ class CountryTest extends TestCase
{
/**
* @test
* @dataProvider provideInvalidData
*/
public function invalidConstructionThrowsException(): void
public function invalidConstructionThrowsException(array $data, array $expected): void
{
$isoAlpha2 = 'ZZ';
$isoAlpha3 = 'XYZ';
$isoNumeric = 9999;
$commonName = 'Common Name';
$officialName = 'Official Name';
$continent = 'Asia';
$topLevelDomain = 'tld';
$longDistancePrefix = 99;
$currencyIsoAlpha = 'XYD';

$this->expectException(InvalidArgumentException::class);
$this->expectException($expected[0]);
$this->expectExceptionMessage($expected[1]);
ashkarpetin marked this conversation as resolved.
Show resolved Hide resolved
new Country(
$isoAlpha3,
$isoAlpha3,
$isoNumeric,
$commonName,
$officialName,
$continent,
$longDistancePrefix,
$topLevelDomain,
$currencyIsoAlpha
);

$this->expectException(InvalidArgumentException::class);
new Country(
$isoAlpha2,
$isoAlpha2,
$isoNumeric,
$commonName,
$officialName,
$continent,
$longDistancePrefix,
$topLevelDomain,
$currencyIsoAlpha
$data['isoAlpha2'],
$data['isoAlpha3'],
9999,
'Common Name',
'Official Name',
'Asia',
99,
'tld',
'XYD'
);
}

Expand Down Expand Up @@ -77,6 +56,11 @@ public function construction(): void
);
$this->assertInstanceOf(Country::class, $country);
$this->assertSame($isoAlpha2, $country->getIsoAlpha2());
$this->assertSame($isoAlpha3, $country->getIsoAlpha3());
$this->assertSame($isoAlpha2, (string) $country);
$this->assertSame($longDistancePrefix, $country->getLongDistancePrefix());
$this->assertSame($isoNumeric, $country->getIsoNumeric());
$this->assertSame($currencyIsoAlpha, $country->getCurrencyIsoAlphaCode());
}

/**
Expand Down Expand Up @@ -120,4 +104,18 @@ public function equals(): void

$this->assertTrue($country->equals($canada));
}

public function provideInvalidData(): array
{
return [
[
['isoAlpha2' => 'USA', 'isoAlpha3' => 'USA'],
[InvalidArgumentException::class, 'IsoAlpha2 must be a 2 character string']
],
[
['isoAlpha2' => 'US', 'isoAlpha3' => 'US'],
[InvalidArgumentException::class, 'IsoAlpha3 must be a 3 character string']
],
];
}
}