From 4ec13c4e6abd89b11e74b24f7ec028dd1a219e32 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Fri, 28 Apr 2023 16:10:19 +0100 Subject: [PATCH 1/2] ci: consistent test config --- .github/workflows/ci.yml | 2 - composer.lock | 130 +++++++++++++----------- test/phpunit/phpunit.xml => phpunit.xml | 27 +++-- 3 files changed, 84 insertions(+), 75 deletions(-) rename test/phpunit/phpunit.xml => phpunit.xml (52%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbe6308..fa84933 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,8 +58,6 @@ jobs: with: php_version: ${{ matrix.php }} php_extensions: xdebug - configuration: test/phpunit/phpunit.xml - bootstrap: vendor/autoload.php coverage_text: _coverage/coverage.txt coverage_clover: _coverage/clover.xml diff --git a/composer.lock b/composer.lock index 539c077..9a09a6c 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "phpgt/dataobject", - "version": "v1.0.4", + "version": "v1.0.5", "source": { "type": "git", "url": "https://github.com/PhpGt/DataObject.git", - "reference": "dde4c5ba9e4cd0e048e4558107da32ce3f9ce7e4" + "reference": "d8edf5fc6f8dd4a2f3674f034ae8802873a4e1ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PhpGt/DataObject/zipball/dde4c5ba9e4cd0e048e4558107da32ce3f9ce7e4", - "reference": "dde4c5ba9e4cd0e048e4558107da32ce3f9ce7e4", + "url": "https://api.github.com/repos/PhpGt/DataObject/zipball/d8edf5fc6f8dd4a2f3674f034ae8802873a4e1ce", + "reference": "d8edf5fc6f8dd4a2f3674f034ae8802873a4e1ce", "shasum": "" }, "require": { @@ -26,8 +26,10 @@ "phpgt/typesafegetter": "^1.0" }, "require-dev": { - "phpstan/phpstan": "^v1.8", - "phpunit/phpunit": "^v9.5" + "phpmd/phpmd": "^2.13", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^10.1", + "squizlabs/php_codesniffer": "^3.7" }, "type": "library", "autoload": { @@ -48,7 +50,7 @@ "description": " Structured, type-safe, immutable data transfer.", "support": { "issues": "https://github.com/PhpGt/DataObject/issues", - "source": "https://github.com/PhpGt/DataObject/tree/v1.0.4" + "source": "https://github.com/PhpGt/DataObject/tree/v1.0.5" }, "funding": [ { @@ -56,28 +58,30 @@ "type": "github" } ], - "time": "2022-09-15T09:21:05+00:00" + "time": "2023-04-28T15:05:31+00:00" }, { "name": "phpgt/typesafegetter", - "version": "v1.2.4", + "version": "v1.3.2", "source": { "type": "git", "url": "https://github.com/PhpGt/TypeSafeGetter.git", - "reference": "ebffd758e69b8a0eebcad30f3daf408915b9ddf3" + "reference": "f760c05a37b1cc188dcbf800c5fdfab8a926b4b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PhpGt/TypeSafeGetter/zipball/ebffd758e69b8a0eebcad30f3daf408915b9ddf3", - "reference": "ebffd758e69b8a0eebcad30f3daf408915b9ddf3", + "url": "https://api.github.com/repos/PhpGt/TypeSafeGetter/zipball/f760c05a37b1cc188dcbf800c5fdfab8a926b4b0", + "reference": "f760c05a37b1cc188dcbf800c5fdfab8a926b4b0", "shasum": "" }, "require": { "php": ">=8.0" }, "require-dev": { - "phpstan/phpstan": "v1.8.0", - "phpunit/phpunit": "v9.5.21" + "phpmd/phpmd": "^2.13", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^10.1", + "squizlabs/php_codesniffer": "^3.7" }, "type": "library", "autoload": { @@ -98,7 +102,7 @@ "description": "An interface for objects that expose type-safe getter methods.", "support": { "issues": "https://github.com/PhpGt/TypeSafeGetter/issues", - "source": "https://github.com/PhpGt/TypeSafeGetter/tree/v1.2.4" + "source": "https://github.com/PhpGt/TypeSafeGetter/tree/v1.3.2" }, "funding": [ { @@ -106,7 +110,7 @@ "type": "github" } ], - "time": "2022-07-08T17:17:42+00:00" + "time": "2023-04-28T14:42:27+00:00" } ], "packages-dev": [ @@ -615,16 +619,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.8", + "version": "1.10.14", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "0166aef76e066f0dd2adc2799bdadfa1635711e9" + "reference": "d232901b09e67538e5c86a724be841bea5768a7c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0166aef76e066f0dd2adc2799bdadfa1635711e9", - "reference": "0166aef76e066f0dd2adc2799bdadfa1635711e9", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d232901b09e67538e5c86a724be841bea5768a7c", + "reference": "d232901b09e67538e5c86a724be841bea5768a7c", "shasum": "" }, "require": { @@ -673,20 +677,20 @@ "type": "tidelift" } ], - "time": "2023-03-24T10:28:16+00:00" + "time": "2023-04-19T13:47:27+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "10.0.2", + "version": "10.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "20800e84296ea4732f9a125e08ce86b4004ae3e4" + "reference": "884a0da7f9f46f28b2cb69134217fd810b793974" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/20800e84296ea4732f9a125e08ce86b4004ae3e4", - "reference": "20800e84296ea4732f9a125e08ce86b4004ae3e4", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/884a0da7f9f46f28b2cb69134217fd810b793974", + "reference": "884a0da7f9f46f28b2cb69134217fd810b793974", "shasum": "" }, "require": { @@ -705,7 +709,7 @@ "theseer/tokenizer": "^1.2.0" }, "require-dev": { - "phpunit/phpunit": "^10.0" + "phpunit/phpunit": "^10.1" }, "suggest": { "ext-pcov": "PHP extension that provides line coverage", @@ -714,7 +718,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "10.0-dev" + "dev-main": "10.1-dev" } }, "autoload": { @@ -742,7 +746,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.0.2" + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.1" }, "funding": [ { @@ -750,7 +755,7 @@ "type": "github" } ], - "time": "2023-03-06T13:00:19+00:00" + "time": "2023-04-17T12:15:40+00:00" }, { "name": "phpunit/php-file-iterator", @@ -995,16 +1000,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.0.19", + "version": "10.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "20c23e85c86e5c06d63538ba464e8054f4744e62" + "reference": "6f0cd95be71add539f8fd2be25b2a4a29789000b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/20c23e85c86e5c06d63538ba464e8054f4744e62", - "reference": "20c23e85c86e5c06d63538ba464e8054f4744e62", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6f0cd95be71add539f8fd2be25b2a4a29789000b", + "reference": "6f0cd95be71add539f8fd2be25b2a4a29789000b", "shasum": "" }, "require": { @@ -1018,7 +1023,7 @@ "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=8.1", - "phpunit/php-code-coverage": "^10.0", + "phpunit/php-code-coverage": "^10.1.1", "phpunit/php-file-iterator": "^4.0", "phpunit/php-invoker": "^4.0", "phpunit/php-text-template": "^3.0", @@ -1044,7 +1049,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "10.0-dev" + "dev-main": "10.1-dev" } }, "autoload": { @@ -1076,7 +1081,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.0.19" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.1.2" }, "funding": [ { @@ -1092,7 +1097,7 @@ "type": "tidelift" } ], - "time": "2023-03-27T11:46:33+00:00" + "time": "2023-04-22T07:38:19+00:00" }, { "name": "psr/container", @@ -1566,16 +1571,16 @@ }, { "name": "sebastian/environment", - "version": "6.0.0", + "version": "6.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "b6f3694c6386c7959915a0037652e0c40f6f69cc" + "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/b6f3694c6386c7959915a0037652e0c40f6f69cc", - "reference": "b6f3694c6386c7959915a0037652e0c40f6f69cc", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/43c751b41d74f96cbbd4e07b7aec9675651e2951", + "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951", "shasum": "" }, "require": { @@ -1617,7 +1622,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/6.0.0" + "security": "https://github.com/sebastianbergmann/environment/security/policy", + "source": "https://github.com/sebastianbergmann/environment/tree/6.0.1" }, "funding": [ { @@ -1625,7 +1631,7 @@ "type": "github" } ], - "time": "2023-02-03T07:03:04+00:00" + "time": "2023-04-11T05:39:26+00:00" }, { "name": "sebastian/exporter", @@ -2242,16 +2248,16 @@ }, { "name": "symfony/dependency-injection", - "version": "v6.2.7", + "version": "v6.2.10", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "83369dd4ec84bba9673524d25b79dfbde9e6e84c" + "reference": "d732a66a2672669232c0b4536c8c96724a679780" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/83369dd4ec84bba9673524d25b79dfbde9e6e84c", - "reference": "83369dd4ec84bba9673524d25b79dfbde9e6e84c", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/d732a66a2672669232c0b4536c8c96724a679780", + "reference": "d732a66a2672669232c0b4536c8c96724a679780", "shasum": "" }, "require": { @@ -2309,7 +2315,7 @@ "description": "Allows you to standardize and centralize the way objects are constructed in your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/dependency-injection/tree/v6.2.7" + "source": "https://github.com/symfony/dependency-injection/tree/v6.2.10" }, "funding": [ { @@ -2325,7 +2331,7 @@ "type": "tidelift" } ], - "time": "2023-02-16T14:11:02+00:00" + "time": "2023-04-21T15:42:15+00:00" }, { "name": "symfony/deprecation-contracts", @@ -2396,16 +2402,16 @@ }, { "name": "symfony/filesystem", - "version": "v6.2.7", + "version": "v6.2.10", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "82b6c62b959f642d000456f08c6d219d749215b3" + "reference": "fd588debf7d1bc16a2c84b4b3b71145d9946b894" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/82b6c62b959f642d000456f08c6d219d749215b3", - "reference": "82b6c62b959f642d000456f08c6d219d749215b3", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/fd588debf7d1bc16a2c84b4b3b71145d9946b894", + "reference": "fd588debf7d1bc16a2c84b4b3b71145d9946b894", "shasum": "" }, "require": { @@ -2439,7 +2445,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v6.2.7" + "source": "https://github.com/symfony/filesystem/tree/v6.2.10" }, "funding": [ { @@ -2455,7 +2461,7 @@ "type": "tidelift" } ], - "time": "2023-02-14T08:44:56+00:00" + "time": "2023-04-18T13:46:08+00:00" }, { "name": "symfony/polyfill-ctype", @@ -2709,16 +2715,16 @@ }, { "name": "symfony/var-exporter", - "version": "v6.2.7", + "version": "v6.2.10", "source": { "type": "git", "url": "https://github.com/symfony/var-exporter.git", - "reference": "86062dd0103530e151588c8f60f5b85a139f1442" + "reference": "9a07920c2058bafee921ce4d90aeef2193837d63" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-exporter/zipball/86062dd0103530e151588c8f60f5b85a139f1442", - "reference": "86062dd0103530e151588c8f60f5b85a139f1442", + "url": "https://api.github.com/repos/symfony/var-exporter/zipball/9a07920c2058bafee921ce4d90aeef2193837d63", + "reference": "9a07920c2058bafee921ce4d90aeef2193837d63", "shasum": "" }, "require": { @@ -2758,12 +2764,12 @@ "export", "hydrate", "instantiate", - "lazy loading", + "lazy-loading", "proxy", "serialize" ], "support": { - "source": "https://github.com/symfony/var-exporter/tree/v6.2.7" + "source": "https://github.com/symfony/var-exporter/tree/v6.2.10" }, "funding": [ { @@ -2779,7 +2785,7 @@ "type": "tidelift" } ], - "time": "2023-02-24T10:42:00+00:00" + "time": "2023-04-21T08:33:05+00:00" }, { "name": "theseer/tokenizer", diff --git a/test/phpunit/phpunit.xml b/phpunit.xml similarity index 52% rename from test/phpunit/phpunit.xml rename to phpunit.xml index b26aff2..5e1b5d9 100644 --- a/test/phpunit/phpunit.xml +++ b/phpunit.xml @@ -1,23 +1,28 @@ - - - - ../../src - - - + + - ./ + ./test/phpunit/ - + + + + + + + src/ + + + From 69b833e8d51a1693dc85ef340cf180d56cdfeb46 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Fri, 28 Apr 2023 16:14:43 +0100 Subject: [PATCH 2/2] docs: add basic examples --- example/01-basic-usage.php | 51 ++++++++++++++++++++++++++++++++++++++ example/02-typed-array.php | 39 +++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 example/01-basic-usage.php create mode 100644 example/02-typed-array.php diff --git a/example/01-basic-usage.php b/example/01-basic-usage.php new file mode 100644 index 0000000..a2651d7 --- /dev/null +++ b/example/01-basic-usage.php @@ -0,0 +1,51 @@ +fromJsonString($jsonString); + +echo "Type of object: ", $json->getString("object"), PHP_EOL; + +/** @var JsonObject $available */ +foreach($json->getArray("available") as $available) { + echo PHP_EOL; + echo "Currency: ", $available->getString("currency"), PHP_EOL; + echo "Amount: ", number_format($available->getInt("amount") / 100), PHP_EOL; +} + +/* Example output: +Type of object: balance + +Currency: cad +Amount: 22,177 + +Currency: gbp +Amount: 72,548 +*/ diff --git a/example/02-typed-array.php b/example/02-typed-array.php new file mode 100644 index 0000000..5533409 --- /dev/null +++ b/example/02-typed-array.php @@ -0,0 +1,39 @@ +fromJsonString($jsonString); + +echo "Logged in users: ", implode(", ", $json->getArray("logged_in_user_ids", "int")), PHP_EOL; + + +echo "Attempt 2:", PHP_EOL; + +$jsonString = <<fromJsonString($jsonString); + +echo "Logged in users: ", implode(", ", $json->getArray("logged_in_user_ids", "int")), PHP_EOL; + +/* Example output: +Attempt 1: +Logged in users: 10521, 21042, 999991 +Attempt 2: +Logged in users: PHP Fatal error: Uncaught TypeError: Array index 1 must be of type int, boolean given +*/