Skip to content

Commit bd78299

Browse files
authored
Merge pull request #2 from sj-i/support-running-tests-on-php70
Support running tests on php70
2 parents 154df95 + 7b8324c commit bd78299

7 files changed

Lines changed: 231 additions & 77 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
jobs:
12+
13+
phpunit-test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Setup PHP Action
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: 7.4
22+
extensions: dom, mbstring
23+
coverage: pcov
24+
25+
- name: Get Composer Cache Directory
26+
id: composer-cache
27+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
28+
29+
- name: Cache dependencies
30+
uses: actions/cache@v1
31+
with:
32+
path: ${{ steps.composer-cache.outputs.dir }}
33+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
34+
restore-keys: ${{ runner.os }}-composer-
35+
36+
- name: Validate composer.json and composer.lock
37+
run: composer validate --strict
38+
39+
- name: Install dependencies
40+
run: composer install --prefer-dist --no-progress --no-suggest
41+
42+
- name: Setup problem matchers for PHP
43+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
44+
45+
- name: Setup Problem Matchers for PHPUnit
46+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
47+
48+
- name: Run test suite
49+
run: |
50+
mkdir -p build/logs
51+
./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
52+
53+
- name: Send to Coveralls
54+
env:
55+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
run: ./vendor/bin/php-coveralls -v

.github/workflows/phpcs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
php-version: 7.4
2323
extensions: dom, mbstring
2424
coverage: none
25-
tools: cs2pr
25+
tools: cs2pr, phpcs
2626

2727
- name: Get Composer Cache Directory
2828
id: composer-cache
@@ -39,4 +39,4 @@ jobs:
3939
run: composer install --prefer-dist --no-progress --no-suggest
4040

4141
- name: Run phpcs
42-
run: vendor/bin/phpcs --standard=./phpcs.xml --report=checkstyle -q ./src ./tests | cs2pr
42+
run: phpcs --standard=./phpcs.xml --report=checkstyle -q ./src ./tests | cs2pr

.github/workflows/phpunit.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ on:
1111
jobs:
1212

1313
phpunit-test:
14-
name: phpunit test
1514
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
php-versions: ['7.0', '7.1', '7.2', '7.3', '7.4']
18+
name: PHP ${{ matrix.php-versions }} Test
1619
steps:
1720
- uses: actions/checkout@v2
1821

1922
- name: Setup PHP Action
2023
uses: shivammathur/setup-php@v2
2124
with:
22-
php-version: 7.4
25+
php-version: ${{ matrix.php-versions }}
2326
extensions: dom, mbstring
24-
coverage: pcov
2527

2628
- name: Get Composer Cache Directory
2729
id: composer-cache
@@ -49,9 +51,4 @@ jobs:
4951
- name: Run test suite
5052
run: |
5153
mkdir -p build/logs
52-
./vendor/bin/phpunit --do-not-cache-result --coverage-clover build/logs/clover.xml
53-
54-
- name: Send to Coveralls
55-
env:
56-
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57-
run: ./vendor/bin/php-coveralls -v
54+
./vendor/bin/phpunit

.github/workflows/static-analysis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
php-version: 7.4
2323
extensions: dom, mbstring
2424
coverage: none
25+
tools: psalm
2526

2627
- name: Get Composer Cache Directory
2728
id: composer-cache
@@ -44,4 +45,4 @@ jobs:
4445
run: composer install --prefer-dist --no-progress --no-suggest
4546

4647
- name: Run psalm
47-
run: ./vendor/bin/psalm --shepherd --show-info=true --diff --diff-methods --output-format=github
48+
run: psalm --shepherd --show-info=true --diff --diff-methods --output-format=github

composer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^7.4 || ^8.0"
17+
"php": "^7.0 || ^8.0"
1818
},
1919
"require-dev": {
2020
"phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0",
21-
"vimeo/psalm": "^3.12",
22-
"squizlabs/php_codesniffer": "^3.5",
2321
"twinh/php-coveralls": "^2.3"
2422
},
2523
"autoload": {

tests/PhpCast/CastTest.php

Lines changed: 88 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
class CastTest extends TestCase
2424
{
25-
public function testToInt(): void
25+
public function testToInt()
2626
{
2727
$this->assertSame(0, Cast::toInt(0));
2828
$this->assertSame(1, Cast::toInt(1));
@@ -35,30 +35,57 @@ public function testToInt(): void
3535
$this->assertSame(0, Cast::toInt(false));
3636
$this->assertSame(1, Cast::toInt(true));
3737

38-
$this->assertTypeError(fn () => Cast::toInt(''));
39-
$this->assertTypeError(fn () => Cast::toInt('a'));
40-
$this->assertTypeError(fn () => Cast::toInt('ok'));
41-
$this->assertTypeError(fn () => Cast::toInt('true'));
42-
$this->assertTypeError(fn () => Cast::toInt('null'));
43-
$this->assertTypeError(fn () => Cast::toInt(null));
44-
$this->assertTypeError(fn () => Cast::toInt([]));
45-
$this->assertTypeError(fn () => Cast::toInt((object)[]));
46-
$this->assertTypeError(fn () => Cast::toInt(PHP_INT_MAX + 1));
47-
$this->assertTypeError(fn () => Cast::toInt(-9223372036854776833));
38+
$this->assertTypeError(function () {
39+
return Cast::toInt('');
40+
});
41+
$this->assertTypeError(function () {
42+
return Cast::toInt('a');
43+
});
44+
$this->assertTypeError(function () {
45+
return Cast::toInt('ok');
46+
});
47+
$this->assertTypeError(function () {
48+
return Cast::toInt('true');
49+
});
50+
$this->assertTypeError(function () {
51+
return Cast::toInt('null');
52+
});
53+
$this->assertTypeError(function () {
54+
return Cast::toInt(null);
55+
});
56+
$this->assertTypeError(function () {
57+
return Cast::toInt([]);
58+
});
59+
$this->assertTypeError(function () {
60+
return Cast::toInt((object)[]);
61+
});
62+
$this->assertTypeError(function () {
63+
return Cast::toInt(PHP_INT_MAX + 1);
64+
});
65+
$this->assertTypeError(function () {
66+
return Cast::toInt(-9223372036854776833);
67+
});
4868

4969
try {
5070
Cast::toInt('123abc');
5171
} catch (\Throwable $e) {
5272
}
53-
$this->assertTrue(isset($e));
54-
$this->assertInstanceOf(TypeError::class, $e);
55-
$this->assertInstanceOf(Exception::class, $e->getPrevious());
56-
$this->assertSame('A non well formed numeric value encountered', $e->getPrevious()->getMessage());
73+
if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
74+
$this->assertTrue(isset($e));
75+
if (version_compare(PHP_VERSION, '7.4.0') >= 0) {
76+
$this->assertInstanceOf(TypeError::class, $e);
77+
$this->assertInstanceOf(Exception::class, $e->getPrevious());
78+
$this->assertSame('A non well formed numeric value encountered', $e->getPrevious()->getMessage());
79+
} else {
80+
$this->assertInstanceOf(Exception::class, $e);
81+
$this->assertSame('A non well formed numeric value encountered', $e->getMessage());
82+
}
83+
}
5784
$result = @Cast::toInt('123abc');
5885
$this->assertSame(123, $result);
5986
}
6087

61-
public function testToFloat(): void
88+
public function testToFloat()
6289
{
6390
$this->assertSame(0.0, Cast::toFloat(0));
6491
$this->assertSame(1.0, Cast::toFloat(1));
@@ -73,17 +100,33 @@ public function testToFloat(): void
73100
$this->assertSame(PHP_INT_MAX + 1, Cast::toFloat(PHP_INT_MAX + 1));
74101
$this->assertSame(-9223372036854776833, Cast::toFloat(-9223372036854776833));
75102

76-
$this->assertTypeError(fn () => Cast::toFloat(''));
77-
$this->assertTypeError(fn () => Cast::toFloat('a'));
78-
$this->assertTypeError(fn () => Cast::toFloat('ok'));
79-
$this->assertTypeError(fn () => Cast::toFloat('true'));
80-
$this->assertTypeError(fn () => Cast::toFloat('null'));
81-
$this->assertTypeError(fn () => Cast::toFloat(null));
82-
$this->assertTypeError(fn () => Cast::toFloat([]));
83-
$this->assertTypeError(fn () => Cast::toFloat((object)[]));
103+
$this->assertTypeError(function () {
104+
return Cast::toFloat('');
105+
});
106+
$this->assertTypeError(function () {
107+
return Cast::toFloat('a');
108+
});
109+
$this->assertTypeError(function () {
110+
return Cast::toFloat('ok');
111+
});
112+
$this->assertTypeError(function () {
113+
return Cast::toFloat('true');
114+
});
115+
$this->assertTypeError(function () {
116+
return Cast::toFloat('null');
117+
});
118+
$this->assertTypeError(function () {
119+
return Cast::toFloat(null);
120+
});
121+
$this->assertTypeError(function () {
122+
return Cast::toFloat([]);
123+
});
124+
$this->assertTypeError(function () {
125+
return Cast::toFloat((object)[]);
126+
});
84127
}
85128

86-
public function testToString(): void
129+
public function testToString()
87130
{
88131
$this->assertSame('0', Cast::toString(0));
89132
$this->assertSame('1', Cast::toString(1));
@@ -106,12 +149,18 @@ public function __toString()
106149
)
107150
);
108151

109-
$this->assertTypeError(fn () => Cast::toString(null));
110-
$this->assertTypeError(fn () => Cast::toString([]));
111-
$this->assertTypeError(fn () => Cast::toString((object)[]));
152+
$this->assertTypeError(function () {
153+
return Cast::toString(null);
154+
});
155+
$this->assertTypeError(function () {
156+
return Cast::toString([]);
157+
});
158+
$this->assertTypeError(function () {
159+
return Cast::toString((object)[]);
160+
});
112161
}
113162

114-
public function testToBool(): void
163+
public function testToBool()
115164
{
116165
$this->assertFalse(Cast::toBool(0));
117166
$this->assertTrue(Cast::toBool(1));
@@ -130,12 +179,18 @@ public function testToBool(): void
130179
$this->assertTrue(Cast::toBool('true'));
131180
$this->assertTrue(Cast::toBool('null'));
132181

133-
$this->assertTypeError(fn () => Cast::toBool(null));
134-
$this->assertTypeError(fn () => Cast::toBool([]));
135-
$this->assertTypeError(fn () => Cast::toBool((object)[]));
182+
$this->assertTypeError(function () {
183+
return Cast::toBool(null);
184+
});
185+
$this->assertTypeError(function () {
186+
return Cast::toBool([]);
187+
});
188+
$this->assertTypeError(function () {
189+
return Cast::toBool((object)[]);
190+
});
136191
}
137192

138-
private function assertTypeError(callable $func): void
193+
private function assertTypeError(callable $func)
139194
{
140195
try {
141196
$func();

0 commit comments

Comments
 (0)