Skip to content

Commit

Permalink
Test in github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Riimu committed Nov 29, 2020
1 parent ec202f0 commit 79f7d8c
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Remove developer files from exports
tests export-ignore
.gitattributes export-ignore
.github export-ignore
.gitignore export-ignore
.php_cs export-ignore
.travis.yml export-ignore
Expand Down
81 changes: 81 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:

jobs:
tests:
strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --no-progress --prefer-dist --classmap-authoritative --no-interaction
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Test with phpunit
run: vendor/bin/phpunit
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none
tools: cs2pr, php-cs-fixer, phpcs
- name: Run PHP Coding Standards Fixer
run: php-cs-fixer fix --dry-run --using-cache=no --format=checkstyle | cs2pr
- name: Run PHP_CodeSniffer
run: phpcs --standard=PSR12 --exclude=PSR12.Properties.ConstantVisibility -q --report=checkstyle src tests | cs2pr
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: xdebug
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer install --no-progress --prefer-dist --classmap-authoritative --no-interaction
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Test with phpunit
run: vendor/bin/phpunit --coverage-clover coverage.xml
- name: Upload coverage
uses: codecov/codecov-action@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
vendor/
.phpunit.result.cache
examples/dbconf.php
composer.lock
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": "^7.2 || ^6.5 || ^5.7"
"phpunit/phpunit": "^9.4 || ^6.5 || ^5.7"
},
"suggest": {
"ext-gmp": "To convert GMP numbers into PHP code"
Expand Down
4 changes: 2 additions & 2 deletions src/Encoder/ArrayEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private function getAlignedPairs(array $array, callable $encode)
* @param bool $omitted Set to true, if all the keys were omitted, false otherwise
* @return string[] Each of key and value pair encoded as php
*/
private function getPairs(array $array, $space, $omit, callable $encode, & $omitted = true)
private function getPairs(array $array, $space, $omit, callable $encode, &$omitted = true)
{
$pairs = [];
$nextIndex = 0;
Expand All @@ -221,7 +221,7 @@ private function getPairs(array $array, $space, $omit, callable $encode, & $omit
* @param int $nextIndex Next expected key that can be omitted
* @return bool True if the key can be omitted, false if not
*/
private function canOmitKey($key, & $nextIndex)
private function canOmitKey($key, &$nextIndex)
{
$result = $key === $nextIndex;

Expand Down
2 changes: 1 addition & 1 deletion src/PHPEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private function generate($value, $depth, array $options, array $recursion = [])
* @return bool True if values should be recorded, false if not
* @throws \RuntimeException If a recursive value is detected
*/
private function detectRecursion(& $value, array $options, array $recursion)
private function detectRecursion(&$value, array $options, array $recursion)
{
if ($options['recursion.detect']) {
if (array_search($value, $recursion, true) !== false) {
Expand Down
13 changes: 11 additions & 2 deletions tests/tests/EncodingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testNanFloat()
$this->assertSame('NAN', $code);

$value = eval("return $code;");
$this->assertInternalType('float', $value);
$this->assertTypeIsFloat($value);
$this->assertNan($value);
}

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

$evaluated = eval("return $float;");
$this->assertInternalType('float', $evaluated);
$this->assertTypeIsFloat($evaluated);
$this->assertNotSame($value, $evaluated);
}

Expand Down Expand Up @@ -380,4 +380,13 @@ public function testMaxDeathOnNoRecursionDetection()
$this->expectException(\RuntimeException::class);
$encoder->encode($foo);
}

private function assertTypeIsFloat($value)
{
if (method_exists($this, 'assertIsFloat')) {
$this->assertIsFloat($value);
} else {
$this->assertInternalType('float', $value);
}
}
}

0 comments on commit 79f7d8c

Please sign in to comment.