Skip to content

Commit

Permalink
Merge pull request #47 from zumba/php-8
Browse files Browse the repository at this point in the history
Covering PHP 8.0 on test cases
  • Loading branch information
jrbasso committed Jun 9, 2021
2 parents 1288ee1 + 2cd7af4 commit d91d5a2
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['7.0', '7.1', '7.2', '7.3', '7.4']
php-version: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
name: PHP ${{ matrix.php-version }}
steps:
- uses: actions/checkout@v2
Expand All @@ -31,12 +31,4 @@ jobs:
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run test suite
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml

- name: Upload coverage results to Coveralls
if: matrix.php-version == '7.0'
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer require php-coveralls/php-coveralls
vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.phpunit.result.cache
vendor
composer.lock
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# Json Serializer for PHP

[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.txt)
[![Build Status](https://img.shields.io/travis/zumba/json-serializer/master.svg?style=flat-square)](https://travis-ci.org/zumba/json-serializer)
[![Code Coverage](https://img.shields.io/coveralls/zumba/json-serializer/master.svg)](https://coveralls.io/github/zumba/json-serializer)
[![Scrutinizer](https://scrutinizer-ci.com/g/zumba/json-serializer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/zumba/json-serializer/)
<p align="center">
<a href="LICENSE.txt" target="_blank">
<img alt="Software License" src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square">
</a>
<img alt="Build Status" src="https://github.com/zumba/json-serializer/actions/workflows/php.yml/badge.svg?branch=master">
<a href="https://packagist.org/packages/zumba/json-serializer" target="_blank">
<img alt="Total Downloads" src="https://img.shields.io/packagist/dt/zumba/json-serializer.svg?style=flat-square">
</a>
<a href="https://packagist.org/packages/zumba/json-serializer" target="_blank">
<img alt="Latest Stable Version" src="https://img.shields.io/packagist/v/zumba/json-serializer.svg?style=flat-square&label=stable">
</a>
</p>

This is a library to serialize PHP variables in JSON format. It is similar of the `serialize()` function in PHP,
but the output is a string JSON encoded. You can also unserialize the JSON generated by this tool and have you
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"jeremeamia/superclosure": "Allow to serialize PHP closures"
},
"require-dev": {
"phpunit/phpunit": "6.*"
"phpunit/phpunit": ">=6.0 <10.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 1 addition & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="true"
strict="true"
colors="true">
<testsuites>
<testsuite>
<testsuite name="JsonSerializerTests">
<directory>./tests</directory>
</testsuite>
</testsuites>
Expand Down
18 changes: 11 additions & 7 deletions tests/JsonSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use stdClass;
use SuperClosure\Serializer as ClosureSerializer;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;

class JsonSerializerTest extends TestCase
{
Expand All @@ -21,11 +22,11 @@ class JsonSerializerTest extends TestCase
/**
* Test case setup
*
* @before
* @return void
*/
public function setUp()
public function setUpSerializer()
{
parent::setUp();
$customObjectSerializerMap['Zumba\\JsonSerializer\\Test\\SupportClasses\\MyType'] = new \Zumba\JsonSerializer\Test\SupportClasses\MyTypeSerializer();
$this->serializer = new JsonSerializer(null, $customObjectSerializerMap);
}
Expand Down Expand Up @@ -226,16 +227,19 @@ public function testUnserializeObjects()
$obj = $this->serializer->unserialize($serialized);
$this->assertInstanceOf('Zumba\JsonSerializer\Test\SupportClasses\AllVisibilities', $obj);
$this->assertInstanceOf('Zumba\JsonSerializer\Test\SupportClasses\EmptyClass', $obj->pub);
$this->assertAttributeSame('protected', 'prot', $obj);
$this->assertAttributeSame('dont tell anyone', 'priv', $obj);
$prop = new ReflectionProperty($obj, 'prot');
$prop->setAccessible(true);
$this->assertSame('protected', $prop->getValue($obj));
$prop = new ReflectionProperty($obj, 'priv');
$prop->setAccessible(true);
$this->assertSame('dont tell anyone', $prop->getValue($obj));

$serialized = '{"instance":{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\EmptyClass"}}';
$array = $this->serializer->unserialize($serialized);
$this->assertTrue(is_array($array));
$this->assertInstanceOf('Zumba\JsonSerializer\Test\SupportClasses\EmptyClass', $array['instance']);
}


/**
* Test serialization of objects using the custom serializers
*
Expand All @@ -259,8 +263,8 @@ public function testCustomObjectsUnserializer()
$serialized = '{"@type":"Zumba\\\\JsonSerializer\\\\Test\\\\SupportClasses\\\\MyType","fields":"x y"}';
$obj = $this->serializer->unserialize($serialized);
$this->assertInstanceOf('Zumba\JsonSerializer\Test\SupportClasses\MyType', $obj);
$this->assertAttributeSame('x', 'field1', $obj);
$this->assertAttributeSame('y', 'field2', $obj);
$this->assertSame('x', $obj->field1);
$this->assertSame('y', $obj->field2);
}

/**
Expand Down

0 comments on commit d91d5a2

Please sign in to comment.