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 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
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
51 changes: 51 additions & 0 deletions tests/CountryRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ public function findByIsoAlpha2ReturnsCorrectCountry(): void
self::assertSame($expectedTLD, $result->getTopLevelDomain());
}

/**
* @test
*/
public function findByIsoAlpha2WithInvalidIsoAlpha2ThrowsException(): void
{
$this->expectExceptionObject(
new RecordNotFoundException('Cannot find country with isoAlpha2 XY')
);
$this->subject->findByIsoAlpha2('XY');
}

/**
* @test
*/
Expand All @@ -61,6 +72,17 @@ public function findByNameFindsCorrectCountry(): void
self::assertSame($expectedTLD, $result->getTopLevelDomain());
}

/**
* @test
*/
public function findByNameWithInvalidNameThrowsException(): void
{
$this->expectExceptionObject(
new RecordNotFoundException('Cannot find country with name Invalid Country')
);
$this->subject->findByName('Invalid Country');
}

/**
* @test
*/
Expand Down Expand Up @@ -91,6 +113,24 @@ public function findByOfficialNameWithInvalidNameThrowsException(): void
$this->subject->findByOfficialName('Rebilly');
}

/**
* @test
*/
public function hasWithOfficialName(): void
{
$this->assertTrue($this->subject->hasWithOfficialName('United States of America'));
$this->assertFalse($this->subject->hasWithOfficialName('United States'));
}

/**
* @test
*/
public function hasWithCommonName(): void
{
$this->assertTrue($this->subject->hasWithCommonName('United States'));
$this->assertFalse($this->subject->hasWithCommonName('United States of America'));
}

/**
* @test
*/
Expand Down Expand Up @@ -184,6 +224,17 @@ public function findByIsoAlpha3ReturnsCorrectCountry(): void
self::assertSame($expectedTLD, $result->getTopLevelDomain());
}

/**
* @test
*/
public function findByIsoAlpha3WithInvalidIsoAlpha3ThrowsException(): void
{
$this->expectExceptionObject(
new RecordNotFoundException('Cannot find country with isoAlpha3 XYZ')
);
$this->subject->findByIsoAlpha3('XYZ');
}

/**
* @test
*/
Expand Down
71 changes: 37 additions & 34 deletions tests/CountryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,21 @@ class CountryTest extends TestCase
{
/**
* @test
* @dataProvider provideInvalidData
*/
public function invalidConstructionThrowsException(): void
public function invalidConstructionThrowsException(array $data): 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->expectExceptionObject($data['exception']);
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 +55,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 +103,24 @@ public function equals(): void

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

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