Skip to content

Commit 96bd035

Browse files
authored
Fix issues with case sensitive country retrieval (#39)
* add test * positive test * split test * test lowercase first uppercase first loads the class, then lowercase test passes * fix * update actions
1 parent 735f003 commit 96bd035

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v5
1111
- uses: php-actions/composer@v6
12-
- uses: php-actions/phpunit@v3
12+
- uses: php-actions/phpunit@v4
1313
with:
1414
configuration: ./phpunit.xml
1515
php_version: 7.4

src/Country/CountryHelper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class CountryHelper
4444
public static function getCountry($code, $default = null)
4545
{
4646
$code = $code ?: $default;
47+
if(is_string($code))
48+
{
49+
$code = strtoupper($code);
50+
}
4751
$className = sprintf('\Packaged\Rwd\Country\Countries\%sCountry', $code);
4852
if(class_exists($className))
4953
{

tests/Country/CountryTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Packaged\Tests\Rwd\Country;
4+
5+
use Packaged\Rwd\Country\CountryHelper;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class CountryTest extends TestCase
9+
{
10+
public function testCountryLowercase()
11+
{
12+
$us = CountryHelper::getCountry('us');
13+
self::assertEquals('United States', $us->getName());
14+
15+
$us = CountryHelper::getCountry('US');
16+
self::assertEquals('United States', $us->getName());
17+
}
18+
}

0 commit comments

Comments
 (0)