Skip to content

Commit 79f7d8c

Browse files
committed
Test in github actions
1 parent ec202f0 commit 79f7d8c

8 files changed

Lines changed: 98 additions & 39 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Remove developer files from exports
55
tests export-ignore
66
.gitattributes export-ignore
7+
.github export-ignore
78
.gitignore export-ignore
89
.php_cs export-ignore
910
.travis.yml export-ignore

.github/workflows/main.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
workflow_dispatch:
9+
10+
jobs:
11+
tests:
12+
strategy:
13+
matrix:
14+
operating-system: [ubuntu-latest]
15+
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
16+
runs-on: ${{ matrix.operating-system }}
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v2
20+
- name: Setup PHP
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php-versions }}
24+
coverage: none
25+
- name: Get composer cache directory
26+
id: composer-cache
27+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
28+
- name: Cache composer dependencies
29+
uses: actions/cache@v2
30+
with:
31+
path: ${{ steps.composer-cache.outputs.dir }}
32+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
33+
restore-keys: ${{ runner.os }}-composer-
34+
- name: Install dependencies
35+
run: composer install --no-progress --prefer-dist --classmap-authoritative --no-interaction
36+
- name: Setup problem matchers for PHPUnit
37+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
38+
- name: Test with phpunit
39+
run: vendor/bin/phpunit
40+
lint:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v2
45+
- name: Setup PHP
46+
uses: shivammathur/setup-php@v2
47+
with:
48+
php-version: '7.4'
49+
coverage: none
50+
tools: cs2pr, php-cs-fixer, phpcs
51+
- name: Run PHP Coding Standards Fixer
52+
run: php-cs-fixer fix --dry-run --using-cache=no --format=checkstyle | cs2pr
53+
- name: Run PHP_CodeSniffer
54+
run: phpcs --standard=PSR12 --exclude=PSR12.Properties.ConstantVisibility -q --report=checkstyle src tests | cs2pr
55+
coverage:
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@v2
60+
- name: Setup PHP
61+
uses: shivammathur/setup-php@v2
62+
with:
63+
php-version: '8.0'
64+
coverage: xdebug
65+
- name: Get composer cache directory
66+
id: composer-cache
67+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
68+
- name: Cache composer dependencies
69+
uses: actions/cache@v2
70+
with:
71+
path: ${{ steps.composer-cache.outputs.dir }}
72+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
73+
restore-keys: ${{ runner.os }}-composer-
74+
- name: Install dependencies
75+
run: composer install --no-progress --prefer-dist --classmap-authoritative --no-interaction
76+
- name: Setup problem matchers for PHPUnit
77+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
78+
- name: Test with phpunit
79+
run: vendor/bin/phpunit --coverage-clover coverage.xml
80+
- name: Upload coverage
81+
uses: codecov/codecov-action@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
build/
22
vendor/
3+
.phpunit.result.cache
34
examples/dbconf.php
45
composer.lock

.travis.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"php": ">=5.6.0"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "^7.2 || ^6.5 || ^5.7"
25+
"phpunit/phpunit": "^9.4 || ^6.5 || ^5.7"
2626
},
2727
"suggest": {
2828
"ext-gmp": "To convert GMP numbers into PHP code"

src/Encoder/ArrayEncoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private function getAlignedPairs(array $array, callable $encode)
196196
* @param bool $omitted Set to true, if all the keys were omitted, false otherwise
197197
* @return string[] Each of key and value pair encoded as php
198198
*/
199-
private function getPairs(array $array, $space, $omit, callable $encode, & $omitted = true)
199+
private function getPairs(array $array, $space, $omit, callable $encode, &$omitted = true)
200200
{
201201
$pairs = [];
202202
$nextIndex = 0;
@@ -221,7 +221,7 @@ private function getPairs(array $array, $space, $omit, callable $encode, & $omit
221221
* @param int $nextIndex Next expected key that can be omitted
222222
* @return bool True if the key can be omitted, false if not
223223
*/
224-
private function canOmitKey($key, & $nextIndex)
224+
private function canOmitKey($key, &$nextIndex)
225225
{
226226
$result = $key === $nextIndex;
227227

src/PHPEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private function generate($value, $depth, array $options, array $recursion = [])
196196
* @return bool True if values should be recorded, false if not
197197
* @throws \RuntimeException If a recursive value is detected
198198
*/
199-
private function detectRecursion(& $value, array $options, array $recursion)
199+
private function detectRecursion(&$value, array $options, array $recursion)
200200
{
201201
if ($options['recursion.detect']) {
202202
if (array_search($value, $recursion, true) !== false) {

tests/tests/EncodingTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function testNanFloat()
141141
$this->assertSame('NAN', $code);
142142

143143
$value = eval("return $code;");
144-
$this->assertInternalType('float', $value);
144+
$this->assertTypeIsFloat($value);
145145
$this->assertNan($value);
146146
}
147147

@@ -190,7 +190,7 @@ public function testFloatRounding()
190190
$this->assertSame('1.0E+15', $float);
191191

192192
$evaluated = eval("return $float;");
193-
$this->assertInternalType('float', $evaluated);
193+
$this->assertTypeIsFloat($evaluated);
194194
$this->assertNotSame($value, $evaluated);
195195
}
196196

@@ -380,4 +380,13 @@ public function testMaxDeathOnNoRecursionDetection()
380380
$this->expectException(\RuntimeException::class);
381381
$encoder->encode($foo);
382382
}
383+
384+
private function assertTypeIsFloat($value)
385+
{
386+
if (method_exists($this, 'assertIsFloat')) {
387+
$this->assertIsFloat($value);
388+
} else {
389+
$this->assertInternalType('float', $value);
390+
}
391+
}
383392
}

0 commit comments

Comments
 (0)