Skip to content

Commit fe10165

Browse files
authored
Merge pull request #39 from summerKK/master
feat: Running Test Cases with Github Actions
2 parents 67c7bf1 + 9618e3d commit fe10165

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

.github/workflows/test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: PHP Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
php-version: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up PHP ${{ matrix.php-version }}
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: ${{ matrix.php-version }}
27+
extensions: bcmath, curl, json
28+
coverage: none
29+
30+
- name: Install Composer dependencies
31+
run: |
32+
if [ "${{ matrix.php-version }}" = "7.2" ]; then
33+
composer require --dev phpunit/phpunit:^8.0 --no-update
34+
fi
35+
composer install --no-progress --prefer-dist
36+
37+
- name: Run tests
38+
run: vendor/bin/phpunit

tests/DatabaseTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testIpv4CountryCode() {
2424

2525
$this->assertEquals(
2626
'US',
27-
$records['countryCode'],
27+
$records['countryCode']
2828
);
2929
}
3030

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

3636
$this->assertEquals(
3737
'United States of America',
38-
$records['countryName'],
38+
$records['countryName']
3939
);
4040
}
4141

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

5555
$this->assertEquals(
5656
'US',
57-
$records['countryCode'],
57+
$records['countryCode']
5858
);
5959
}
6060

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

6666
$this->assertEquals(
6767
'United States of America',
68-
$records['countryName'],
68+
$records['countryName']
6969
);
7070
}
7171

tests/IpToolsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function testCidrToIpv6()
139139

140140
$this->assertEqualsCanonicalizing(
141141
[
142-
'ip_start' => '2002:0000:0000:1234:abcd:ffff:c0a8:0101',
142+
'ip_start' => '2002:0000:0000:1234:0000:0000:0000:0000',
143143
'ip_end' => '2002:0000:0000:1234:ffff:ffff:ffff:ffff',
144144
],
145145
$ipTools->cidrToIpv6('2002::1234:abcd:ffff:c0a8:101/64')

tests/RegionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function testRegionCodeField()
1414

1515
$this->assertEquals(
1616
'US-CA',
17-
$region->getRegionCode('US', 'California'),
17+
$region->getRegionCode('US', 'California')
1818
);
1919
}
2020
}

tests/WebServiceTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ class WebServiceTest extends TestCase
1111
{
1212
public function testCredit() {
1313
$ws = new \IP2Location\WebService('demo', 'WS24', true);
14-
$this->assertMatchesRegularExpression('/^[0-9]+$/', (string) $ws->getCredit());
14+
if (method_exists($this, 'assertMatchesRegularExpression')) {
15+
$this->assertMatchesRegularExpression('/^[0-9]+$/', (string) $ws->getCredit());
16+
}else{
17+
// Compatible with php 7.2 && phpunit 8.x
18+
$this->assertRegExp('/^[0-9]+$/', (string) $ws->getCredit());
19+
}
1520
}
1621

1722
public function testCountryCode() {
@@ -23,7 +28,7 @@ public function testCountryCode() {
2328

2429
$this->assertEquals(
2530
'US',
26-
$records['country_code'],
31+
$records['country_code']
2732
);
2833
}
2934
}

0 commit comments

Comments
 (0)