diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..99bafec --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,38 @@ +name: PHP Tests + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + php-version: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: bcmath, curl, json + coverage: none + + - name: Install Composer dependencies + run: | + if [ "${{ matrix.php-version }}" = "7.2" ]; then + composer require --dev phpunit/phpunit:^8.0 --no-update + fi + composer install --no-progress --prefer-dist + + - name: Run tests + run: vendor/bin/phpunit diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index d3e3330..d3c52e4 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -24,7 +24,7 @@ public function testIpv4CountryCode() { $this->assertEquals( 'US', - $records['countryCode'], + $records['countryCode'] ); } @@ -35,7 +35,7 @@ public function testIpv4CountryName() { $this->assertEquals( 'United States of America', - $records['countryName'], + $records['countryName'] ); } @@ -54,7 +54,7 @@ public function testIpv6CountryCode() { $this->assertEquals( 'US', - $records['countryCode'], + $records['countryCode'] ); } @@ -65,7 +65,7 @@ public function testIpv6CountryName() { $this->assertEquals( 'United States of America', - $records['countryName'], + $records['countryName'] ); } diff --git a/tests/IpToolsTest.php b/tests/IpToolsTest.php index fcb150a..53d36b8 100644 --- a/tests/IpToolsTest.php +++ b/tests/IpToolsTest.php @@ -139,7 +139,7 @@ public function testCidrToIpv6() $this->assertEqualsCanonicalizing( [ - 'ip_start' => '2002:0000:0000:1234:abcd:ffff:c0a8:0101', + 'ip_start' => '2002:0000:0000:1234:0000:0000:0000:0000', 'ip_end' => '2002:0000:0000:1234:ffff:ffff:ffff:ffff', ], $ipTools->cidrToIpv6('2002::1234:abcd:ffff:c0a8:101/64') diff --git a/tests/RegionTest.php b/tests/RegionTest.php index b6fac9d..76394a8 100644 --- a/tests/RegionTest.php +++ b/tests/RegionTest.php @@ -14,7 +14,7 @@ public function testRegionCodeField() $this->assertEquals( 'US-CA', - $region->getRegionCode('US', 'California'), + $region->getRegionCode('US', 'California') ); } } diff --git a/tests/WebServiceTest.php b/tests/WebServiceTest.php index f973e28..bfc90e4 100644 --- a/tests/WebServiceTest.php +++ b/tests/WebServiceTest.php @@ -11,7 +11,12 @@ class WebServiceTest extends TestCase { public function testCredit() { $ws = new \IP2Location\WebService('demo', 'WS24', true); - $this->assertMatchesRegularExpression('/^[0-9]+$/', (string) $ws->getCredit()); + if (method_exists($this, 'assertMatchesRegularExpression')) { + $this->assertMatchesRegularExpression('/^[0-9]+$/', (string) $ws->getCredit()); + }else{ + // Compatible with php 7.2 && phpunit 8.x + $this->assertRegExp('/^[0-9]+$/', (string) $ws->getCredit()); + } } public function testCountryCode() { @@ -23,7 +28,7 @@ public function testCountryCode() { $this->assertEquals( 'US', - $records['country_code'], + $records['country_code'] ); } }