diff --git a/.gitattributes b/.gitattributes
index 46604d0..e860f36 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -2,11 +2,13 @@
* text eol=lf
# Remove developer files from exports
+.github export-ignore
tests export-ignore
+
.gitattributes export-ignore
-.github export-ignore
.gitignore export-ignore
-.php_cs export-ignore
+.php-cs-fixer.php export-ignore
+.phpcs.xml export-ignore
.travis.yml export-ignore
phpunit.xml export-ignore
sami_config.php export-ignore
diff --git a/.github/actions/setup-composer/action.yml b/.github/actions/setup-composer/action.yml
new file mode 100644
index 0000000..8a18738
--- /dev/null
+++ b/.github/actions/setup-composer/action.yml
@@ -0,0 +1,19 @@
+name: "Setup Composer"
+description: "Sets up the composer dependencies"
+runs:
+ using: "composite"
+ steps:
+ - name: Get Composer Cache Directory
+ id: composer-cache
+ shell: bash
+ run: |
+ echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
+ - uses: actions/cache@v3
+ with:
+ path: ${{ steps.composer-cache.outputs.dir }}
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
+ restore-keys: |
+ ${{ runner.os }}-composer-
+ - name: Install dependencies
+ run: composer install --no-progress --prefer-dist --classmap-authoritative --no-interaction
+ shell: bash
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 0d91b87..e631cdd 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -8,74 +8,88 @@ on:
workflow_dispatch:
jobs:
- tests:
+ PHPUnit:
strategy:
matrix:
- operating-system: [ubuntu-latest]
- php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
+ operating-system: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
+ php-versions: [ '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' , '8.2']
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- 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
+ ini-values: error_reporting=E_ALL
+ - name: Setup Composer
+ uses: ./.github/actions/setup-composer
+ - name: Install PHPUnit
+ run: composer require --dev phpunit/phpunit
+ - name: Run PHPUnit
+ run: composer test
+ PHP_CodeSniffer:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ - name: Setup PHP
+ uses: shivammathur/setup-php@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:
+ php-version: latest
+ coverage: none
+ tools: phpcs
+ - name: Setup Composer
+ uses: ./.github/actions/setup-composer
+ - name: Run PHP_CodeSniffer
+ run: composer phpcs -- --no-cache
+ PHP-CS-Fixer:
runs-on: ubuntu-latest
+ env:
+ PHP_CS_FIXER_IGNORE_ENV: 1
steps:
- name: Checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: '7.4'
+ php-version: latest
coverage: none
- tools: cs2pr, php-cs-fixer, phpcs
+ tools: php-cs-fixer
+ - name: Setup Composer
+ uses: ./.github/actions/setup-composer
- 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
+ run: composer php-cs-fixer -- --dry-run --diff --using-cache=no
+ composer-normalize:
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: latest
+ coverage: none
+ tools: composer-normalize
+ - name: Setup Composer
+ uses: ./.github/actions/setup-composer
+ - name: Run composer-normalize
+ run: composer-normalize --dry-run
coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
- php-version: '8.0'
+ php-version: latest
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
+ tools: phpunit
+ - name: Setup Composer
+ uses: ./.github/actions/setup-composer
+ - name: Run PHPUnit with coverage
+ run: composer test -- --do-not-cache-result --coverage-clover coverage.xml
- name: Upload coverage
- uses: codecov/codecov-action@v1
+ uses: codecov/codecov-action@v3
diff --git a/.gitignore b/.gitignore
index ee024b5..8ef8497 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
build/
vendor/
-.phpunit.result.cache
+.phpunit.cache
+.php-cs-fixer.cache
examples/dbconf.php
composer.lock
diff --git a/.php_cs b/.php-cs-fixer.php
similarity index 60%
rename from .php_cs
rename to .php-cs-fixer.php
index 91c6fec..fb488d3 100644
--- a/.php_cs
+++ b/.php-cs-fixer.php
@@ -4,52 +4,43 @@
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests');
-return \PhpCsFixer\Config::create()
+return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
- '@PSR2' => true,
+ '@PSR12' => true,
- 'align_multiline_comment' => true,
- 'array_indentation' => true,
- 'array_syntax' => ['syntax' => 'short'],
- 'backtick_to_shell_exec' => true,
+ 'array_syntax' => [
+ 'syntax' => 'short'
+ ],
'binary_operator_spaces' => true,
'blank_line_after_opening_tag' => true,
'cast_spaces' => true,
- 'class_attributes_separation' => ['elements' => ['method']],
- 'combine_consecutive_issets' => true,
+ 'class_attributes_separation' => ['elements' => ['method' => 'one']],
'combine_consecutive_unsets' => true,
- 'concat_space' => ['spacing' => 'one'],
+ 'concat_space' => [
+ 'spacing' => 'one'
+ ],
'declare_equal_normalize' => true,
'dir_constant' => true,
'ereg_to_preg' => true,
- 'fully_qualified_strict_types' => true,
'function_to_constant' => true,
'function_typehint_space' => true,
'heredoc_to_nowdoc' => true,
'include' => true,
'is_null' => true,
- 'list_syntax' => ['syntax' => 'short'],
- 'logical_operators' => true,
'lowercase_cast' => true,
- 'lowercase_static_reference' => true,
'magic_constant_casing' => true,
- 'modernize_types_casting' => true,
- 'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => true,
- 'native_constant_invocation' => true,
+ 'modernize_types_casting' => true,
'native_function_casing' => true,
- 'native_function_invocation' => ['include' => ['@compiler_optimized']],
'new_with_braces' => true,
'no_alias_functions' => true,
- 'no_binary_string' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
- 'no_homoglyph_names' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => true,
@@ -58,12 +49,8 @@
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
- 'no_trailing_comma_in_list_call' => true,
- 'no_trailing_comma_in_singleline_array' => true,
+ 'no_trailing_comma_in_singleline' => true,
'no_unneeded_control_parentheses' => true,
- 'no_unneeded_curly_braces' => true,
- 'no_unneeded_final_method' => true,
- 'no_unreachable_default_argument_value' => true,
'no_unused_imports' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
@@ -71,55 +58,42 @@
'non_printable_character' => true,
'normalize_index_brace' => true,
'object_operator_without_whitespace' => true,
- 'ordered_class_elements' => ['order' => ['use_trait', 'constant', 'property', 'construct', 'method']],
+ 'ordered_class_elements' => [
+ 'order' => ['use_trait', 'constant', 'property', 'construct', 'method'],
+ ],
'ordered_imports' => true,
'php_unit_construct' => true,
- 'php_unit_dedicate_assert' => ['target' => 'newest'],
- 'php_unit_expectation' => true,
- 'php_unit_mock' => true,
- 'php_unit_namespaced' => true,
- 'php_unit_no_expectation_annotation' => true,
- 'php_unit_set_up_tear_down_visibility' => true,
+ 'php_unit_dedicate_assert' => true,
'php_unit_strict' => true,
- 'php_unit_test_case_static_method_calls' => ['call_type' => 'this'],
'phpdoc_add_missing_param_annotation' => true,
- 'phpdoc_align' => ['align' => 'left'],
'phpdoc_annotation_without_dot' => true,
'phpdoc_indent' => true,
- 'phpdoc_inline_tag' => true,
+ 'phpdoc_inline_tag_normalizer' => true,
'phpdoc_no_access' => true,
'phpdoc_no_alias_tag' => true,
'phpdoc_no_package' => true,
- 'phpdoc_no_useless_inheritdoc' => true,
- 'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_summary' => true,
- 'phpdoc_to_comment' => true,
'phpdoc_trim' => true,
- 'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'pow_to_exponentiation' => true,
- 'psr4' => true,
+ 'psr_autoloading' => true,
'return_type_declaration' => true,
'self_accessor' => true,
- 'semicolon_after_instruction' => true,
- 'set_type_to_cast' => true,
'short_scalar_cast' => true,
- 'simplified_null_return' => true,
'single_blank_line_before_namespace' => true,
'single_line_comment_style' => true,
'single_quote' => true,
'space_after_semicolon' => true,
- 'standardize_increment' => true,
'standardize_not_equals' => true,
'strict_comparison' => true,
'strict_param' => true,
'ternary_operator_spaces' => true,
- 'ternary_to_null_coalescing' => true,
- 'trailing_comma_in_multiline_array' => true,
+ 'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
+ 'visibility_required' => ['elements' => ['property', 'method']],
'whitespace_after_comma_in_array' => true,
])
->setFinder($finder);
diff --git a/.phpcs.xml b/.phpcs.xml
new file mode 100644
index 0000000..f82fd08
--- /dev/null
+++ b/.phpcs.xml
@@ -0,0 +1,14 @@
+
+
+ The coding standard configuration used for this project
+
+ ./src/
+ ./tests/
+
+ */vendor/*
+
+
+
+
+
+
diff --git a/CHANGES.md b/CHANGES.md
index 3a5776a..74fbbfa 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,10 @@
# Changelog #
+## v2.4.2 (2022-12-10) ##
+
+ * Added tests to ensure PHP 8.2 compatibility
+ * Changed `export` type object conversion have more consistent index order
+
## v2.4.1 (2020-11-29) ##
* Migrated to Github actions for CI
diff --git a/LICENSE b/LICENSE
index 56daac4..1465189 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,18 +1,21 @@
-Copyright (c) 2013-2020 Riikka Kalliomäki
+MIT License
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
+Copyright (c) 2013-2022 Riikka Kalliomäki
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index 2c2f3ba..7e81b74 100644
--- a/README.md
+++ b/README.md
@@ -288,6 +288,6 @@ apply to following calls.
## Credits ##
-This library is Copyright (c) 2013-2020 Riikka Kalliomäki.
+This library is Copyright (c) 2013-2022 Riikka Kalliomäki.
See LICENSE for license and copying information.
diff --git a/composer.json b/composer.json
index de3ba73..5444ca6 100644
--- a/composer.json
+++ b/composer.json
@@ -1,8 +1,8 @@
{
"name": "riimu/kit-phpencoder",
- "type": "library",
"description": "Highly customizable alternative to var_export for PHP code generation",
- "homepage": "http://kit.riimu.net",
+ "license": "MIT",
+ "type": "library",
"keywords": [
"variable",
"export",
@@ -10,7 +10,6 @@
"generator",
"encoder"
],
- "license": "MIT",
"authors": [
{
"name": "Riikka Kalliomäki",
@@ -18,15 +17,10 @@
"homepage": "http://riimu.net"
}
],
+ "homepage": "http://kit.riimu.net",
"require": {
"php": ">=5.6.0"
},
- "require-dev": {
- "phpunit/phpunit": "^9.4 || ^6.5 || ^5.7"
- },
- "suggest": {
- "ext-gmp": "To convert GMP numbers into PHP code"
- },
"autoload": {
"psr-4": {
"Riimu\\Kit\\PHPEncoder\\": "src/"
@@ -37,5 +31,16 @@
"Riimu\\Kit\\PHPEncoder\\": "tests/tests/",
"Riimu\\Kit\\PHPEncoder\\Test\\": "tests/extra/"
}
+ },
+ "scripts": {
+ "ci-all": [
+ "composer test -- --do-not-cache-result",
+ "composer phpcs -- --no-cache",
+ "composer php-cs-fixer -- --dry-run --diff --using-cache=no",
+ "composer normalize --dry-run"
+ ],
+ "php-cs-fixer": "php-cs-fixer fix -v",
+ "phpcs": "phpcs -p",
+ "test": "phpunit"
}
}
diff --git a/phpunit.xml b/phpunit.xml
index 6feeaba..5de9948 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,16 +1,29 @@
-
-
-
- tests/tests/
-
-
-
-
- src/
-
- src/autoload.php
-
-
-
+
+
+
+ tests
+
+
+
+
+
+ src
+
+
+ src/autoload.php
+
+
diff --git a/src/Encoder/ObjectEncoder.php b/src/Encoder/ObjectEncoder.php
index febc22c..6f20690 100644
--- a/src/Encoder/ObjectEncoder.php
+++ b/src/Encoder/ObjectEncoder.php
@@ -115,7 +115,9 @@ private function getObjectArray($object, $format)
private function getObjectState($object)
{
$class = new \ReflectionClass($object);
- $visibility = \ReflectionProperty::IS_PRIVATE | \ReflectionProperty::IS_PROTECTED;
+ $visibility = \ReflectionProperty::IS_PRIVATE
+ | \ReflectionProperty::IS_PROTECTED
+ | \ReflectionProperty::IS_PUBLIC;
$values = [];
do {
@@ -126,8 +128,9 @@ private function getObjectState($object)
$class = $class->getParentClass();
$visibility = \ReflectionProperty::IS_PRIVATE;
- } while ($class);
+ } while ($class !== false);
- return get_object_vars($object) + $values;
+ // Use get_object_vars to include dynamic properties
+ return $values + get_object_vars($object);
}
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
deleted file mode 100644
index 6c8c4f5..0000000
--- a/tests/bootstrap.php
+++ /dev/null
@@ -1,3 +0,0 @@
-assertEncode('1.123456789012', $float, ['float.precision' => false]);
+ $this->assertEncode(
+ '1.123456789012',
+ 1.123456789012,
+ ['float.precision' => false],
+ 1.1234567890123456
+ );
ini_set('serialize_precision', $serialize);
}
diff --git a/tests/tests/ObjectEncodingTest.php b/tests/tests/ObjectEncodingTest.php
index d2c14cd..116c956 100644
--- a/tests/tests/ObjectEncodingTest.php
+++ b/tests/tests/ObjectEncodingTest.php
@@ -98,8 +98,10 @@ public function testObjectExport()
$obj = new ExtendsTestMockObject();
$obj->var = true;
$this->assertSame(
- sprintf("\%s::__set_state(['bazC'=>'E','baz'=>'C',", ExtendsTestMockObject::class) .
- "'var'=>true,'fooC'=>'D','bar'=>'B','foo'=>'A'])",
+ sprintf(
+ "\%s::__set_state(['fooC'=>'D','bazC'=>'E','bar'=>'B','baz'=>'C','foo'=>'A','var'=>true])",
+ ExtendsTestMockObject::class
+ ),
$encoder->encode($obj)
);
}