Skip to content

Commit

Permalink
Merge pull request #39 from summerKK/master
Browse files Browse the repository at this point in the history
feat: Running Test Cases with Github Actions
  • Loading branch information
ip2location authored Jun 25, 2024
2 parents 67c7bf1 + 9618e3d commit fe10165
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 8 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions tests/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testIpv4CountryCode() {

$this->assertEquals(
'US',
$records['countryCode'],
$records['countryCode']
);
}

Expand All @@ -35,7 +35,7 @@ public function testIpv4CountryName() {

$this->assertEquals(
'United States of America',
$records['countryName'],
$records['countryName']
);
}

Expand All @@ -54,7 +54,7 @@ public function testIpv6CountryCode() {

$this->assertEquals(
'US',
$records['countryCode'],
$records['countryCode']
);
}

Expand All @@ -65,7 +65,7 @@ public function testIpv6CountryName() {

$this->assertEquals(
'United States of America',
$records['countryName'],
$records['countryName']
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/IpToolsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/RegionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testRegionCodeField()

$this->assertEquals(
'US-CA',
$region->getRegionCode('US', 'California'),
$region->getRegionCode('US', 'California')
);
}
}
9 changes: 7 additions & 2 deletions tests/WebServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -23,7 +28,7 @@ public function testCountryCode() {

$this->assertEquals(
'US',
$records['country_code'],
$records['country_code']
);
}
}

0 comments on commit fe10165

Please sign in to comment.