From ceba2e72165671d9e34d7058061308a1ce9f5d45 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Mon, 29 Jan 2024 21:30:00 +0100 Subject: [PATCH 1/2] deps: allow brick/math 0.12 (#54) deps: other dev deps update --- .editorconfig | 52 +- .gitattributes | 1 + .github/ISSUE_TEMPLATE/1_Bug_report.yaml | 50 +- .github/ISSUE_TEMPLATE/2_Feature_request.yaml | 18 +- .github/ISSUE_TEMPLATE/3_Documentation.yaml | 8 +- .github/ISSUE_TEMPLATE/config.yml | 8 +- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .github/dependabot.yml | 12 +- .github/stale.yml | 6 +- .github/workflows/integrate.yml | 15 +- composer.json | 14 +- ecs.php | 11 +- phpstan-baseline.neon | 36 ++ phpstan.neon | 28 +- phpunit.xml.dist | 34 +- rector.php | 14 +- src/AbstractCBORObject.php | 2 +- src/Decoder.php | 18 +- src/IndefiniteLengthListObject.php | 2 +- src/IndefiniteLengthMapObject.php | 2 +- src/LengthCalculator.php | 2 +- src/ListObject.php | 7 +- src/MapObject.php | 4 +- .../DoublePrecisionFloatObject.php | 2 +- src/OtherObject/HalfPrecisionFloatObject.php | 2 +- src/OtherObject/OtherObjectManager.php | 2 +- src/OtherObject/SimpleObject.php | 2 +- .../SinglePrecisionFloatObject.php | 2 +- src/Tag/BigFloatTag.php | 4 +- src/Tag/DatetimeTag.php | 2 +- src/Tag/DecimalFractionTag.php | 4 +- src/Tag/TagManager.php | 2 +- tests/ByteStringObjectTest.php | 11 +- tests/FloatTest.php | 36 +- tests/GlobalTest.php | 58 +- .../IndefiniteLengthByteStringObjectTest.php | 15 +- .../IndefiniteLengthTextStringObjectTest.php | 15 +- tests/InvalidTypeTest.php | 543 +++++++++--------- tests/OtherObject/AllTest.php | 274 ++++----- tests/OtherTest.php | 11 +- tests/SignedIntegerTest.php | 29 +- tests/Tag/DatetimeTagTest.php | 16 +- tests/TextStringObjectTest.php | 11 +- tests/UnsignedIntegerTest.php | 31 +- tests/VectorTest.php | 2 +- 45 files changed, 767 insertions(+), 653 deletions(-) create mode 100644 phpstan-baseline.neon diff --git a/.editorconfig b/.editorconfig index 60b603d..767b17b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,24 +1,64 @@ -# https://EditorConfig.org +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org root = true [*] +# Change these settings to your own preference indent_style = space -# Reduce tab size on GitHub indent_size = 4 + +# We recommend you to keep these unchanged end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -block_comment_start = /* -block_comment = * -block_comment_end = */ -[{*.yml,*.yaml}] +[*.{js,html,ts,tsx}] +indent_size = 2 + +[*.json] indent_size = 2 [*.md] trim_trailing_whitespace = false +[*.sh] +indent_style = tab + +[*.xml{,.dist}] +indent_style = space +indent_size = 4 + +[*.{yaml,yml}] +trim_trailing_whitespace = false + +[.github/workflows/*.yml] +indent_size = 2 + +[deptrac.yaml] +indent_size = 2 + +[.gitmodules] +indent_style = tab + +[.php_cs{,.dist}] +indent_style = space +indent_size = 4 + +[composer.json] +indent_size = 4 + +[{,docker-}compose{,.*}.{yaml,yml}] +indent_style = space +indent_size = 2 + +[{,*.*}Dockerfile] +indent_style = tab + +[{,*.*}Caddyfile] +indent_style = tab + [Makefile] indent_style = tab diff --git a/.gitattributes b/.gitattributes index 9110993..06f47c0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11,5 +11,6 @@ /infection.json.dist export-ignore /Makefile export-ignore /phpstan.neon export-ignore +/phpstan-baseline.neon export-ignore /phpunit.xml.dist export-ignore /rector.php export-ignore diff --git a/.github/ISSUE_TEMPLATE/1_Bug_report.yaml b/.github/ISSUE_TEMPLATE/1_Bug_report.yaml index d3f26cf..4e88b94 100644 --- a/.github/ISSUE_TEMPLATE/1_Bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/1_Bug_report.yaml @@ -2,41 +2,41 @@ name: 🐛 Bug Report description: ⚠️ NEVER report security issues, email security AT spomky-labs.com instead labels: Bug body: - - type: input + - type: input id: affected-versions attributes: - label: Version(s) affected - placeholder: x.y.z + label: Version(s) affected + placeholder: x.y.z validations: - required: true - - type: textarea + required: true + - type: textarea id: description attributes: - label: Description - description: A clear and concise description of the problem + label: Description + description: A clear and concise description of the problem validations: - required: true - - type: textarea + required: true + - type: textarea id: how-to-reproduce attributes: - label: How to reproduce - description: | - ⚠️ This is the most important part of the report ⚠️ - Without a way to easily reproduce your issue, there is little chance we will be able to help you and work on a fix. - Please, take the time to show us some code and/or config that is needed for others to reproduce the problem easily. - Most of the time, creating a "bug reproducer" is the best way to help us and increases the chances someone - will have a look at it. + label: How to reproduce + description: | + ⚠️ This is the most important part of the report ⚠️ + Without a way to easily reproduce your issue, there is little chance we will be able to help you and work on a fix. + Please, take the time to show us some code and/or config that is needed for others to reproduce the problem easily. + Most of the time, creating a "bug reproducer" is the best way to help us and increases the chances someone + will have a look at it. validations: - required: true - - type: textarea + required: true + - type: textarea id: possible-solution attributes: - label: Possible Solution - description: | - Optional: only if you have suggestions on a fix/reason for the bug - Don't hesitate to create a pull request with your solution, it helps get faster feedback. - - type: textarea + label: Possible Solution + description: | + Optional: only if you have suggestions on a fix/reason for the bug + Don't hesitate to create a pull request with your solution, it helps get faster feedback. + - type: textarea id: additional-context attributes: - label: Additional Context - description: "Optional: any other context about the problem: log messages, screenshots, etc." + label: Additional Context + description: "Optional: any other context about the problem: log messages, screenshots, etc." diff --git a/.github/ISSUE_TEMPLATE/2_Feature_request.yaml b/.github/ISSUE_TEMPLATE/2_Feature_request.yaml index 52b3de7..74947c5 100644 --- a/.github/ISSUE_TEMPLATE/2_Feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/2_Feature_request.yaml @@ -1,17 +1,17 @@ name: 🚀 Feature Request description: RFC and ideas for new features and improvements body: - - type: textarea + - type: textarea id: description attributes: - label: Description - description: A clear and concise description of the new feature + label: Description + description: A clear and concise description of the new feature validations: - required: true - - type: textarea + required: true + - type: textarea id: example attributes: - label: Example - description: | - A simple example of the new feature in action (include PHP code, YAML config, etc.) - If the new feature changes an existing feature, include a simple before/after comparison. + label: Example + description: | + A simple example of the new feature in action (include PHP code, YAML config, etc.) + If the new feature changes an existing feature, include a simple before/after comparison. diff --git a/.github/ISSUE_TEMPLATE/3_Documentation.yaml b/.github/ISSUE_TEMPLATE/3_Documentation.yaml index 1c5ac89..30d82ea 100644 --- a/.github/ISSUE_TEMPLATE/3_Documentation.yaml +++ b/.github/ISSUE_TEMPLATE/3_Documentation.yaml @@ -1,10 +1,10 @@ name: 📖 Documentation Issue description: To report typo or obsolete section in the documentation body: - - type: textarea + - type: textarea id: description attributes: - label: Description - description: A clear and concise description of the error you found in the documentation + label: Description + description: A clear and concise description of the error you found in the documentation validations: - required: true + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index d9e01de..d1aa0b7 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,8 +1,8 @@ blank_issues_enabled: false contact_links: - - name: Support Question + - name: Support Question url: https://spomky-labs.com/contact/ about: | - We use GitHub issues only to discuss about bugs and new features. - For this kind of questions about using the framework or third-party bundles, - please email us contact AT spomky-labs.com for quoting + We use GitHub issues only to discuss about bugs and new features. + For this kind of questions about using the framework or third-party bundles, + please email us contact AT spomky-labs.com for quoting diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 029817b..df5254b 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,4 +1,4 @@ -Target branch: +Target branch: Resolves issue # diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ae2faa4..ee5284b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,19 +1,19 @@ version: 2 updates: - - package-ecosystem: "composer" + - package-ecosystem: "composer" directory: "/" schedule: - interval: "weekly" - day: "friday" + interval: "weekly" + day: "friday" versioning-strategy: "widen" open-pull-requests-limit: 20 allow: - - dependency-type: all + - dependency-type: all labels: [ "Dependencies" ] - - package-ecosystem: "github-actions" + - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "monthly" + interval: "monthly" open-pull-requests-limit: 20 labels: [ "Dependencies" ] diff --git a/.github/stale.yml b/.github/stale.yml index 3c84124..40899bb 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -2,7 +2,7 @@ daysUntilStale: 60 daysUntilClose: 7 staleLabel: wontfix markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. Thank you - for your contributions. + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. closeComment: false diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml index 57b43d4..98731bc 100644 --- a/.github/workflows/integrate.yml +++ b/.github/workflows/integrate.yml @@ -31,7 +31,7 @@ jobs: - name: "Set up PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "8.1" + php-version: "8.3" coverage: "none" - name: "Checkout code" @@ -56,6 +56,8 @@ jobs: - "ubuntu-latest" php-version: - "8.1" + - "8.2" + - "8.3" dependencies: - "lowest" - "highest" @@ -98,7 +100,7 @@ jobs: - name: "Set up PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "8.1" + php-version: "8.3" extensions: "ctype, dom, json, libxml, mbstring, openssl, phar, simplexml, tokenizer, xml, xmlwriter" coverage: "none" @@ -130,16 +132,13 @@ jobs: - name: "Set up PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "8.1" + php-version: "8.3" extensions: "ctype, dom, json, libxml, mbstring, openssl, phar, simplexml, tokenizer, xml, xmlwriter" coverage: "none" - name: "Checkout code" uses: "actions/checkout@v3" - - name: "Check adherence to EditorConfig" - uses: "greut/eclint-action@v0" - - name: "Install dependencies" uses: "ramsey/composer-install@v2" with: @@ -163,7 +162,7 @@ jobs: - name: "Set up PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "8.1" + php-version: "8.3" extensions: "ctype, dom, json, libxml, mbstring, openssl, phar, simplexml, tokenizer, xml, xmlwriter" coverage: "xdebug" @@ -192,7 +191,7 @@ jobs: - name: "Set up PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "8.1" + php-version: "8.3" extensions: "ctype, dom, json, libxml, mbstring, openssl, phar, simplexml, tokenizer, xml, xmlwriter" coverage: "xdebug" diff --git a/composer.json b/composer.json index 473a148..13925d3 100644 --- a/composer.json +++ b/composer.json @@ -25,24 +25,24 @@ }, "require": { "php": ">=8.0", - "brick/math": "^0.9|^0.10|^0.11", - "ext-mbstring": "*" + "ext-mbstring": "*", + "brick/math": "^0.9|^0.10|^0.11|^0.12" }, "require-dev": { "ext-json": "*", "ekino/phpstan-banned-code": "^1.0", - "infection/infection": "^0.26", + "infection/infection": "^0.27", "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^1.0", "phpstan/phpstan-beberlei-assert": "^1.0", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-phpunit": "^1.0", "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/phpunit": "^10.0", - "rector/rector": "^0.15", + "phpunit/phpunit": "^10.1", + "rector/rector": "^0.19", "roave/security-advisories": "dev-latest", - "symfony/var-dumper": "^6.0", - "symplify/easy-coding-standard": "^11.1", + "symfony/var-dumper": "^6.0|^7.0", + "symplify/easy-coding-standard": "^12.0", "php-parallel-lint/php-parallel-lint": "^1.3", "qossmic/deptrac-shim": "^1.0" }, diff --git a/ecs.php b/ecs.php index fb39cda..2d4767b 100644 --- a/ecs.php +++ b/ecs.php @@ -2,7 +2,6 @@ declare(strict_types=1); -use PhpCsFixer\Fixer\Alias\MbStrFunctionsFixer; use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; use PhpCsFixer\Fixer\ClassNotation\ProtectedToPrivateFixer; use PhpCsFixer\Fixer\Comment\HeaderCommentFixer; @@ -26,7 +25,6 @@ use PhpCsFixer\Fixer\Strict\StrictComparisonFixer; use PhpCsFixer\Fixer\Strict\StrictParamFixer; use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer; -use PhpCsFixer\Fixer\Whitespace\CompactNullableTypehintFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; @@ -47,7 +45,6 @@ $config->import(SetList::NAMESPACES); $config->import(SetList::STRICT); - $services = $config->services(); $config->rule(StrictParamFixer::class); $config->rule(StrictComparisonFixer::class); $config->rule(ArrayIndentationFixer::class); @@ -55,11 +52,9 @@ $config->rule(ProtectedToPrivateFixer::class); $config->rule(DeclareStrictTypesFixer::class); $config->rule(NativeConstantInvocationFixer::class); - $config->rule(MbStrFunctionsFixer::class); $config->rule(LinebreakAfterOpeningTagFixer::class); $config->rule(CombineConsecutiveIssetsFixer::class); $config->rule(CombineConsecutiveUnsetsFixer::class); - $config->rule(CompactNullableTypehintFixer::class); $config->rule(NoSuperfluousElseifFixer::class); $config->rule(NoSuperfluousPhpdocTagsFixer::class); $config->rule(PhpdocTrimConsecutiveBlankLineSeparationFixer::class); @@ -89,9 +84,9 @@ 'import_functions' => true, ]); - $config->services() - ->remove(PhpUnitTestClassRequiresCoversFixer::class); $config->parallel(); $config->paths([__DIR__]); - $config->skip([__DIR__ . '/.github', __DIR__ . '/build', __DIR__ . '/vendor']); + $config->skip( + [__DIR__ . '/.github', __DIR__ . '/build', __DIR__ . '/vendor', PhpUnitTestClassRequiresCoversFixer::class] + ); }; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..8de4af4 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,36 @@ +parameters: + ignoreErrors: + - + message: "#^Instanceof between CBOR\\\\MapItem and CBOR\\\\MapItem will always evaluate to true\\.$#" + count: 1 + path: src/MapObject.php + + - + message: "#^Parameter \\#1 \\$value of static method CBOR\\\\Utils\\:\\:binToBigInteger\\(\\) expects string, string\\|null given\\.$#" + count: 3 + path: src/OtherObject/DoublePrecisionFloatObject.php + + - + message: "#^Parameter \\#1 \\$value of static method CBOR\\\\Utils\\:\\:binToBigInteger\\(\\) expects string, string\\|null given\\.$#" + count: 3 + path: src/OtherObject/HalfPrecisionFloatObject.php + + - + message: "#^PHPDoc tag @var with type CBOR\\\\OtherObject is not subtype of native type string\\.$#" + count: 1 + path: src/OtherObject/OtherObjectManager.php + + - + message: "#^Parameter \\#1 \\$value of static method CBOR\\\\Utils\\:\\:binToBigInteger\\(\\) expects string, string\\|null given\\.$#" + count: 3 + path: src/OtherObject/SinglePrecisionFloatObject.php + + - + message: "#^PHPDoc tag @var with type CBOR\\\\Tag is not subtype of native type string\\.$#" + count: 1 + path: src/Tag/TagManager.php + + - + message: "#^Parameter \\#1 \\$value of static method CBOR\\\\Utils\\:\\:binToInt\\(\\) expects string, string\\|null given\\.$#" + count: 1 + path: src/Tag/TagManager.php diff --git a/phpstan.neon b/phpstan.neon index fefdf35..e400f30 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,28 +3,6 @@ parameters: paths: - src treatPhpDocTypesAsCertain: false - ignoreErrors: - - - message: '#Parameter .* of static method CBOR\\Utils\:\:binToBigInteger\(\) expects string, string\|null given\.#' - count: 3 - path: src/OtherObject/SinglePrecisionFloatObject.php - - - message: '#Parameter .* of static method CBOR\\Utils\:\:binToBigInteger\(\) expects string, string\|null given\.#' - count: 3 - path: src/OtherObject/DoublePrecisionFloatObject.php - - - message: '#Parameter .* of static method CBOR\\Utils\:\:binToBigInteger\(\) expects string, string\|null given\.#' - count: 3 - path: src/OtherObject/HalfPrecisionFloatObject.php - - - message: '#Parameter .* of static method CBOR\\Utils\:\:binToInt\(\) expects string, string\|null given\.#' - count: 1 - path: src/Tag/TagManager.php - - - message: '#Instanceof between CBOR\\CBORObject and CBOR\\CBORObject will always evaluate to true\.#' - count: 1 - path: src/ListObject.php - - - message: '#Instanceof between CBOR\\MapItem and CBOR\\MapItem will always evaluate to true\.#' - count: 1 - path: src/MapObject.php +includes: + - vendor/phpstan/phpstan/conf/bleedingEdge.neon + - phpstan-baseline.neon diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0769eb4..5e6c56f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,23 +1,23 @@ - - - ./src - - - - - ./tests/ - - - - - - - - + + + ./tests/ + + + + + + + + + + + src + + diff --git a/rector.php b/rector.php index 8f09dd1..0e6ac9a 100644 --- a/rector.php +++ b/rector.php @@ -3,12 +3,13 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use Rector\Core\ValueObject\PhpVersion; +use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector; use Rector\PHPUnit\Set\PHPUnitLevelSetList; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; use Rector\Symfony\Set\SymfonySetList; +use Rector\ValueObject\PhpVersion; return static function (RectorConfig $config): void { $config->import(SetList::DEAD_CODE); @@ -16,12 +17,15 @@ $config->import(SymfonySetList::SYMFONY_CODE_QUALITY); $config->import(PHPUnitLevelSetList::UP_TO_PHPUNIT_100); $config->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY); - $config->import(PHPUnitSetList::PHPUNIT_EXCEPTION); - $config->import(PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD); - $config->import(PHPUnitSetList::PHPUNIT_YIELD_DATA_PROVIDER); $config->parallel(); $config->paths([__DIR__ . '/src', __DIR__ . '/tests']); - $config->skip([__DIR__ . '/src/IndefiniteLengthMapObject.php', __DIR__ . '/src/MapObject.php']); + $config->skip( + [ + __DIR__ . '/src/IndefiniteLengthMapObject.php', + __DIR__ . '/src/MapObject.php', + PreferPHPUnitThisCallRector::class, + ] + ); $config->phpVersion(PhpVersion::PHP_80); $config->importNames(); $config->importShortClasses(); diff --git a/src/AbstractCBORObject.php b/src/AbstractCBORObject.php index 52f0126..0e0351d 100644 --- a/src/AbstractCBORObject.php +++ b/src/AbstractCBORObject.php @@ -4,8 +4,8 @@ namespace CBOR; -use function chr; use Stringable; +use function chr; abstract class AbstractCBORObject implements CBORObject, Stringable { diff --git a/src/Decoder.php b/src/Decoder.php index 2b5b7d5..67e98f7 100644 --- a/src/Decoder.php +++ b/src/Decoder.php @@ -33,8 +33,8 @@ use CBOR\Tag\UnsignedBigIntegerTag; use CBOR\Tag\UriTag; use InvalidArgumentException; -use function ord; use RuntimeException; +use function ord; use const STR_PAD_LEFT; final class Decoder implements DecoderInterface @@ -150,7 +150,7 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR } return $object; - case CBORObject::MAJOR_TYPE_TEXT_STRING: //3 + case CBORObject::MAJOR_TYPE_TEXT_STRING : //3 $object = IndefiniteLengthTextStringObject::create(); while (! ($it = $this->process($stream, true)) instanceof BreakObject) { if (! $it instanceof TextStringObject) { @@ -162,7 +162,7 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR } return $object; - case CBORObject::MAJOR_TYPE_LIST: //4 + case CBORObject::MAJOR_TYPE_LIST : //4 $object = IndefiniteLengthListObject::create(); $it = $this->process($stream, true); while (! $it instanceof BreakObject) { @@ -171,23 +171,23 @@ private function processInfinite(Stream $stream, int $mt, bool $breakable): CBOR } return $object; - case CBORObject::MAJOR_TYPE_MAP: //5 + case CBORObject::MAJOR_TYPE_MAP : //5 $object = IndefiniteLengthMapObject::create(); while (! ($it = $this->process($stream, true)) instanceof BreakObject) { $object->add($it, $this->process($stream, false)); } return $object; - case CBORObject::MAJOR_TYPE_OTHER_TYPE: //7 + case CBORObject::MAJOR_TYPE_OTHER_TYPE : //7 if (! $breakable) { throw new InvalidArgumentException('Cannot parse the data. No enclosing indefinite.'); } return BreakObject::create(); - case CBORObject::MAJOR_TYPE_UNSIGNED_INTEGER: //0 - case CBORObject::MAJOR_TYPE_NEGATIVE_INTEGER: //1 - case CBORObject::MAJOR_TYPE_TAG: //6 - default: + case CBORObject::MAJOR_TYPE_UNSIGNED_INTEGER : //0 + case CBORObject::MAJOR_TYPE_NEGATIVE_INTEGER : //1 + case CBORObject::MAJOR_TYPE_TAG : //6 + default : throw new InvalidArgumentException(sprintf( 'Cannot parse the data. Found infinite length for Major Type "%s" (%d).', str_pad(decbin($mt), 5, '0', STR_PAD_LEFT), diff --git a/src/IndefiniteLengthListObject.php b/src/IndefiniteLengthListObject.php index 1aef00d..e1bef93 100644 --- a/src/IndefiniteLengthListObject.php +++ b/src/IndefiniteLengthListObject.php @@ -4,12 +4,12 @@ namespace CBOR; -use function array_key_exists; use ArrayAccess; use ArrayIterator; use InvalidArgumentException; use Iterator; use IteratorAggregate; +use function array_key_exists; /** * @phpstan-implements ArrayAccess diff --git a/src/IndefiniteLengthMapObject.php b/src/IndefiniteLengthMapObject.php index 3a68a9d..ece69f2 100644 --- a/src/IndefiniteLengthMapObject.php +++ b/src/IndefiniteLengthMapObject.php @@ -4,12 +4,12 @@ namespace CBOR; -use function array_key_exists; use ArrayAccess; use ArrayIterator; use InvalidArgumentException; use Iterator; use IteratorAggregate; +use function array_key_exists; /** * @phpstan-implements ArrayAccess diff --git a/src/LengthCalculator.php b/src/LengthCalculator.php index 11485b4..ec8c678 100644 --- a/src/LengthCalculator.php +++ b/src/LengthCalculator.php @@ -5,9 +5,9 @@ namespace CBOR; use Brick\Math\BigInteger; +use InvalidArgumentException; use function chr; use function count; -use InvalidArgumentException; use const STR_PAD_LEFT; final class LengthCalculator diff --git a/src/ListObject.php b/src/ListObject.php index 940200c..4f8da72 100644 --- a/src/ListObject.php +++ b/src/ListObject.php @@ -4,14 +4,14 @@ namespace CBOR; -use function array_key_exists; use ArrayAccess; use ArrayIterator; -use function count; use Countable; use InvalidArgumentException; use Iterator; use IteratorAggregate; +use function array_key_exists; +use function count; /** * @phpstan-implements ArrayAccess @@ -36,9 +36,6 @@ public function __construct(array $data = []) { [$additionalInformation, $length] = LengthCalculator::getLengthOfArray($data); array_map(static function ($item): void { - if (! $item instanceof CBORObject) { - throw new InvalidArgumentException('The list must contain only CBORObject objects.'); - } }, $data); parent::__construct(self::MAJOR_TYPE, $additionalInformation); diff --git a/src/MapObject.php b/src/MapObject.php index a93849a..72a7431 100644 --- a/src/MapObject.php +++ b/src/MapObject.php @@ -4,14 +4,14 @@ namespace CBOR; -use function array_key_exists; use ArrayAccess; use ArrayIterator; -use function count; use Countable; use InvalidArgumentException; use Iterator; use IteratorAggregate; +use function array_key_exists; +use function count; /** * @phpstan-implements ArrayAccess diff --git a/src/OtherObject/DoublePrecisionFloatObject.php b/src/OtherObject/DoublePrecisionFloatObject.php index a9ad8b9..db3a1d2 100644 --- a/src/OtherObject/DoublePrecisionFloatObject.php +++ b/src/OtherObject/DoublePrecisionFloatObject.php @@ -8,8 +8,8 @@ use CBOR\Normalizable; use CBOR\OtherObject as Base; use CBOR\Utils; -use const INF; use InvalidArgumentException; +use const INF; use const NAN; final class DoublePrecisionFloatObject extends Base implements Normalizable diff --git a/src/OtherObject/HalfPrecisionFloatObject.php b/src/OtherObject/HalfPrecisionFloatObject.php index 7fd577b..467e0c2 100644 --- a/src/OtherObject/HalfPrecisionFloatObject.php +++ b/src/OtherObject/HalfPrecisionFloatObject.php @@ -8,8 +8,8 @@ use CBOR\Normalizable; use CBOR\OtherObject as Base; use CBOR\Utils; -use const INF; use InvalidArgumentException; +use const INF; use const NAN; final class HalfPrecisionFloatObject extends Base implements Normalizable diff --git a/src/OtherObject/OtherObjectManager.php b/src/OtherObject/OtherObjectManager.php index 4aa0fa8..e691c3d 100644 --- a/src/OtherObject/OtherObjectManager.php +++ b/src/OtherObject/OtherObjectManager.php @@ -4,9 +4,9 @@ namespace CBOR\OtherObject; -use function array_key_exists; use CBOR\OtherObject; use InvalidArgumentException; +use function array_key_exists; class OtherObjectManager implements OtherObjectManagerInterface { diff --git a/src/OtherObject/SimpleObject.php b/src/OtherObject/SimpleObject.php index 03b6d05..702542f 100644 --- a/src/OtherObject/SimpleObject.php +++ b/src/OtherObject/SimpleObject.php @@ -7,8 +7,8 @@ use CBOR\Normalizable; use CBOR\OtherObject as Base; use CBOR\Utils; -use function chr; use InvalidArgumentException; +use function chr; use function ord; final class SimpleObject extends Base implements Normalizable diff --git a/src/OtherObject/SinglePrecisionFloatObject.php b/src/OtherObject/SinglePrecisionFloatObject.php index 1264b36..d47cd30 100644 --- a/src/OtherObject/SinglePrecisionFloatObject.php +++ b/src/OtherObject/SinglePrecisionFloatObject.php @@ -7,8 +7,8 @@ use Brick\Math\BigInteger; use CBOR\OtherObject as Base; use CBOR\Utils; -use const INF; use InvalidArgumentException; +use const INF; use const NAN; final class SinglePrecisionFloatObject extends Base diff --git a/src/Tag/BigFloatTag.php b/src/Tag/BigFloatTag.php index b1fc129..1de2cbe 100644 --- a/src/Tag/BigFloatTag.php +++ b/src/Tag/BigFloatTag.php @@ -10,10 +10,10 @@ use CBOR\Normalizable; use CBOR\Tag; use CBOR\UnsignedIntegerObject; -use function count; -use function extension_loaded; use InvalidArgumentException; use RuntimeException; +use function count; +use function extension_loaded; final class BigFloatTag extends Tag implements Normalizable { diff --git a/src/Tag/DatetimeTag.php b/src/Tag/DatetimeTag.php index ff556ae..d1044ec 100644 --- a/src/Tag/DatetimeTag.php +++ b/src/Tag/DatetimeTag.php @@ -9,10 +9,10 @@ use CBOR\Normalizable; use CBOR\Tag; use CBOR\TextStringObject; -use const DATE_RFC3339; use DateTimeImmutable; use DateTimeInterface; use InvalidArgumentException; +use const DATE_RFC3339; /** * @see \CBOR\Test\Tag\DatetimeTagTest diff --git a/src/Tag/DecimalFractionTag.php b/src/Tag/DecimalFractionTag.php index 8deb37b..9eafd25 100644 --- a/src/Tag/DecimalFractionTag.php +++ b/src/Tag/DecimalFractionTag.php @@ -10,10 +10,10 @@ use CBOR\Normalizable; use CBOR\Tag; use CBOR\UnsignedIntegerObject; -use function count; -use function extension_loaded; use InvalidArgumentException; use RuntimeException; +use function count; +use function extension_loaded; final class DecimalFractionTag extends Tag implements Normalizable { diff --git a/src/Tag/TagManager.php b/src/Tag/TagManager.php index 271e159..0d3eb6d 100644 --- a/src/Tag/TagManager.php +++ b/src/Tag/TagManager.php @@ -4,11 +4,11 @@ namespace CBOR\Tag; -use function array_key_exists; use CBOR\CBORObject; use CBOR\Tag; use CBOR\Utils; use InvalidArgumentException; +use function array_key_exists; final class TagManager implements TagManagerInterface { diff --git a/tests/ByteStringObjectTest.php b/tests/ByteStringObjectTest.php index a7727d0..fa924b5 100644 --- a/tests/ByteStringObjectTest.php +++ b/tests/ByteStringObjectTest.php @@ -7,6 +7,7 @@ use CBOR\ByteStringObject; use CBOR\CBORObject; use CBOR\StringStream; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -47,12 +48,10 @@ public function aByteStringObjectCanBeCreated( static::assertSame($string, $decoded->normalize()); } - public static function getData(): array + public static function getData(): Iterator { - return [ - ['Hello', 5, 5, '4548656c6c6f'], - ['(。◕‿◕。)', 17, 17, '5128efbda1e29795e280bfe29795efbda129'], - ['HelloHelloHelloHelloHello', 24, 25, '581948656c6c6f48656c6c6f48656c6c6f48656c6c6f48656c6c6f'], - ]; + yield ['Hello', 5, 5, '4548656c6c6f']; + yield ['(。◕‿◕。)', 17, 17, '5128efbda1e29795e280bfe29795efbda129']; + yield ['HelloHelloHelloHelloHello', 24, 25, '581948656c6c6f48656c6c6f48656c6c6f48656c6c6f48656c6c6f']; } } diff --git a/tests/FloatTest.php b/tests/FloatTest.php index ee8b035..fba3096 100644 --- a/tests/FloatTest.php +++ b/tests/FloatTest.php @@ -5,6 +5,7 @@ namespace CBOR\Test; use CBOR\StringStream; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -25,16 +26,31 @@ public function aFloatCanBeParsed(string $data): void static::assertSame($data, bin2hex((string) $object)); } - public static function getDataSet(): array + public static function getDataSet(): Iterator { - return [ - ['f90000'], ['f98000'], ['f93c00'], ['fb3ff199999999999a'], ['f93e00'], [ - 'f97bff', - ], ['fa47c35000'], ['fa7f7fffff'], ['fb7e37e43c8800759c'], ['f90001'], ['f90400'], ['f9c400'], [ - 'fbc010666666666666', - ], ['f97c00'], ['f97e00'], ['f9fc00'], ['fa7f800000'], ['fa7fc00000'], ['faff800000'], [ - 'fb7ff0000000000000', - ], ['fb7ff8000000000000'], ['fbfff0000000000000'], ['c5822003'], ['c48221196ab3'], - ]; + yield ['f90000']; + yield ['f98000']; + yield ['f93c00']; + yield ['fb3ff199999999999a']; + yield ['f93e00']; + yield ['f97bff']; + yield ['fa47c35000']; + yield ['fa7f7fffff']; + yield ['fb7e37e43c8800759c']; + yield ['f90001']; + yield ['f90400']; + yield ['f9c400']; + yield ['fbc010666666666666']; + yield ['f97c00']; + yield ['f97e00']; + yield ['f9fc00']; + yield ['fa7f800000']; + yield ['fa7fc00000']; + yield ['faff800000']; + yield ['fb7ff0000000000000']; + yield ['fb7ff8000000000000']; + yield ['fbfff0000000000000']; + yield ['c5822003']; + yield ['c48221196ab3']; } } diff --git a/tests/GlobalTest.php b/tests/GlobalTest.php index 72d8ca4..ec0c1ea 100644 --- a/tests/GlobalTest.php +++ b/tests/GlobalTest.php @@ -5,6 +5,7 @@ namespace CBOR\Test; use CBOR\StringStream; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -24,26 +25,45 @@ public function aSignedIntegerCanBeParsed(string $data): void static::assertSame($data, bin2hex((string) $object)); } - public static function getDataSet(): array + public static function getDataSet(): Iterator { - return [ - [ - 'c074323031332d30332d32315432303a30343a30305a', - ], ['c11a514b67b0'], ['c1fb41d452d9ec200000'], ['d74401020304'], ['d818456449455446'], [ - 'd82076687474703a2f2f7777772e6578616d706c652e636f6d', - ], ['40'], ['4401020304'], ['60'], ['6161'], ['6449455446'], [ - '62225c', - ], ['62c3bc'], ['63e6b0b4'], ['64f0908591'], ['80'], ['83010203'], ['8301820203820405'], [ - '98190102030405060708090a0b0c0d0e0f101112131415161718181819', - ], ['a0'], ['a201020304'], ['a26161016162820203'], ['826161a161626163'], [ - 'a56161614161626142616361436164614461656145', - ], ['5f42010243030405ff'], ['7f657374726561646d696e67ff'], ['9fff'], [ - '9f018202039f0405ffff', - ], ['9f01820203820405ff'], ['83018202039f0405ff'], ['83019f0203ff820405'], [ - '9f0102030405060708090a0b0c0d0e0f101112131415161718181819ff', - ], ['bf61610161629f0203ffff'], ['826161bf61626163ff'], ['bf6346756ef563416d7421ff'], [ - 'a401030339010020590100c5da6f4d9357bde202f5c558cd0a3156d254f2e0ad9ab57931f9826b747de1ac4f29d6070874dce57910e19844499d8e42470339b170d022b501ab88e9c2f4ed302e4719c70debe8842403ed9bdfc22730a61a1b70f616c5f1b700cacf7846137dc4b2d469a8e15aab4fad8657084022d28f44d9075323126b7007c981939fdf724caf4fbe475040431a4ea064430bcb2cfad7d05bdb9f64b5b0e0952ecf8679273d6c6dfa81601f14503316a13d0782c31a3e6bdded3d7bc46bc1fa9bef0dff83b7deaf146b582c4644821a3c62edbaa6be422bf04e43edaf5fd3783086153d7361a203061a6298ab26e1337ca1c9ed06741a5905477988e720304eae189d7f2143010001', - ], + yield ['c074323031332d30332d32315432303a30343a30305a']; + yield ['c11a514b67b0']; + yield ['c1fb41d452d9ec200000']; + yield ['d74401020304']; + yield ['d818456449455446']; + yield ['d82076687474703a2f2f7777772e6578616d706c652e636f6d']; + yield ['40']; + yield ['4401020304']; + yield ['60']; + yield ['6161']; + yield ['6449455446']; + yield ['62225c']; + yield ['62c3bc']; + yield ['63e6b0b4']; + yield ['64f0908591']; + yield ['80']; + yield ['83010203']; + yield ['8301820203820405']; + yield ['98190102030405060708090a0b0c0d0e0f101112131415161718181819']; + yield ['a0']; + yield ['a201020304']; + yield ['a26161016162820203']; + yield ['826161a161626163']; + yield ['a56161614161626142616361436164614461656145']; + yield ['5f42010243030405ff']; + yield ['7f657374726561646d696e67ff']; + yield ['9fff']; + yield ['9f018202039f0405ffff']; + yield ['9f01820203820405ff']; + yield ['83018202039f0405ff']; + yield ['83019f0203ff820405']; + yield ['9f0102030405060708090a0b0c0d0e0f101112131415161718181819ff']; + yield ['bf61610161629f0203ffff']; + yield ['826161bf61626163ff']; + yield ['bf6346756ef563416d7421ff']; + yield [ + 'a401030339010020590100c5da6f4d9357bde202f5c558cd0a3156d254f2e0ad9ab57931f9826b747de1ac4f29d6070874dce57910e19844499d8e42470339b170d022b501ab88e9c2f4ed302e4719c70debe8842403ed9bdfc22730a61a1b70f616c5f1b700cacf7846137dc4b2d469a8e15aab4fad8657084022d28f44d9075323126b7007c981939fdf724caf4fbe475040431a4ea064430bcb2cfad7d05bdb9f64b5b0e0952ecf8679273d6c6dfa81601f14503316a13d0782c31a3e6bdded3d7bc46bc1fa9bef0dff83b7deaf146b582c4644821a3c62edbaa6be422bf04e43edaf5fd3783086153d7361a203061a6298ab26e1337ca1c9ed06741a5905477988e720304eae189d7f2143010001', ]; } } diff --git a/tests/IndefiniteLengthByteStringObjectTest.php b/tests/IndefiniteLengthByteStringObjectTest.php index 0b9c12c..cd68757 100644 --- a/tests/IndefiniteLengthByteStringObjectTest.php +++ b/tests/IndefiniteLengthByteStringObjectTest.php @@ -7,6 +7,7 @@ use CBOR\CBORObject; use CBOR\IndefiniteLengthByteStringObject; use CBOR\StringStream; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -50,15 +51,13 @@ public function aIndefiniteLengthByteStringObjectCanBeCreated( static::assertSame($expectedValue, $decoded->normalize()); } - public static function getData(): array + public static function getData(): Iterator { - return [ - [['He', 'll', 'o'], 5, 'Hello', '5f424865426c6c416fff'], - [['(', '。', '◕', '‿', '◕', '。', ')'], - 17, - '(。◕‿◕。)', - '5f412843efbda143e2979543e280bf43e2979543efbda14129ff', - ], + yield [['He', 'll', 'o'], 5, 'Hello', '5f424865426c6c416fff']; + yield [['(', '。', '◕', '‿', '◕', '。', ')'], + 17, + '(。◕‿◕。)', + '5f412843efbda143e2979543e280bf43e2979543efbda14129ff', ]; } } diff --git a/tests/IndefiniteLengthTextStringObjectTest.php b/tests/IndefiniteLengthTextStringObjectTest.php index 15f74ea..8180ec7 100644 --- a/tests/IndefiniteLengthTextStringObjectTest.php +++ b/tests/IndefiniteLengthTextStringObjectTest.php @@ -8,6 +8,7 @@ use CBOR\IndefiniteLengthTextStringObject; use CBOR\StringStream; use CBOR\TextStringObject; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -51,15 +52,13 @@ public function aIndefiniteLengthTextStringObjectCanBeCreated( static::assertSame($expectedValue, $decoded->normalize()); } - public static function getData(): array + public static function getData(): Iterator { - return [ - [['He', 'll', 'o'], 5, 'Hello', '7f624865626c6c616fff'], - [['(', '。', '◕', '‿', '◕', '。', ')'], - 7, - '(。◕‿◕。)', - '7f612863efbda163e2979563e280bf63e2979563efbda16129ff', - ], + yield [['He', 'll', 'o'], 5, 'Hello', '7f624865626c6c616fff']; + yield [['(', '。', '◕', '‿', '◕', '。', ')'], + 7, + '(。◕‿◕。)', + '7f612863efbda163e2979563e280bf63e2979563efbda16129ff', ]; } } diff --git a/tests/InvalidTypeTest.php b/tests/InvalidTypeTest.php index 494a095..8042002 100644 --- a/tests/InvalidTypeTest.php +++ b/tests/InvalidTypeTest.php @@ -7,6 +7,7 @@ use Brick\Math\Exception\IntegerOverflowException; use CBOR\StringStream; use InvalidArgumentException; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use RuntimeException; @@ -32,271 +33,285 @@ public function invalidData(string $item, string $class, string $expectedError): /** * @see https://datatracker.ietf.org/doc/html/rfc8949#appendix-F.1 */ - public static function getInvalidDataItems(): array + public static function getInvalidDataItems(): Iterator { - return [ - [ - base_convert('00000011100', 2, 16), - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', - ], - [ - base_convert('00000011101', 2, 16), - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', - ], - [ - base_convert('00000011110', 2, 16), - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', - ], - ['18', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['19', InvalidArgumentException::class, 'Out of range. Expected: 2, read: 0.'], - ['1a', InvalidArgumentException::class, 'Out of range. Expected: 4, read: 0.'], - ['1b', InvalidArgumentException::class, 'Out of range. Expected: 8, read: 0.'], - ['1901', InvalidArgumentException::class, 'Out of range. Expected: 2, read: 0.'], - ['1a0102', InvalidArgumentException::class, 'Out of range. Expected: 4, read: 0.'], - ['1b01020304050607', InvalidArgumentException::class, 'Out of range. Expected: 8, read: 0.'], - ['38', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['58', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['78', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['98', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['9a01ff00', InvalidArgumentException::class, 'Out of range. Expected: 4, read: 0.'], - ['b8', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['d8', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['f8', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['f900', InvalidArgumentException::class, 'Out of range. Expected: 2, read: 0.'], - ['fa0000', InvalidArgumentException::class, 'Out of range. Expected: 4, read: 0.'], - ['fb000000', InvalidArgumentException::class, 'Out of range. Expected: 8, read: 0.'], - ['41', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['61', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['5affffffff00', InvalidArgumentException::class, 'Out of range. Expected: 4294967295, read: 0.'], - [ - '5bffffffffffffffff010203', - IntegerOverflowException::class, - '18446744073709551615 is out of range -9223372036854775808 to 9223372036854775807 and cannot be represented as an integer.', - ], - ['7affffffff00', InvalidArgumentException::class, 'Out of range. Expected: 4294967295, read: 0.'], - [ - '7b7fffffffffffffff010203', - InvalidArgumentException::class, - 'Out of range. Expected: 9223372036854775807, read: 0.', - ], - ['81', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['818181818181818181', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['8200', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['a1', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['a20102', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['a100', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['a2000000', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['c0', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['5f4100', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['7f6100', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['9f', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['9f0102', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['bf', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['bf01020102', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['819f', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['9f8000', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['9f9f9f9f9fffffffff', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['9f819f819f9fffffff', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - [ - '1c', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', - ], - [ - '1d', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', - ], - [ - '1e', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', - ], - [ - '3c', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', - ], - [ - '3d', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', - ], - [ - '3e', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', - ], - [ - '5c', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', - ], - [ - '5d', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', - ], - [ - '5e', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', - ], - [ - '7c', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', - ], - [ - '7d', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', - ], - [ - '7e', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', - ], - [ - '9c', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', - ], - [ - '9d', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', - ], - [ - '9e', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', - ], - [ - 'bc', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', - ], - [ - 'bd', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', - ], - [ - 'be', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', - ], - [ - 'dc', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', - ], - [ - 'dd', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', - ], - [ - 'de', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', - ], - [ - 'fc', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', - ], - [ - 'fd', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', - ], - [ - 'fe', - InvalidArgumentException::class, - 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', - ], - ['f800', InvalidArgumentException::class, 'Invalid simple value. Content data must be between 32 and 255.'], - ['f801', InvalidArgumentException::class, 'Invalid simple value. Content data must be between 32 and 255.'], - ['f818', InvalidArgumentException::class, 'Invalid simple value. Content data must be between 32 and 255.'], - ['f81f', InvalidArgumentException::class, 'Invalid simple value. Content data must be between 32 and 255.'], - [ - '5f00ff', - RuntimeException::class, - 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', - ], - [ - '5f21ff', - RuntimeException::class, - 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', - ], - [ - '5f6100ff', - RuntimeException::class, - 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', - ], - [ - '5f80ff', - RuntimeException::class, - 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', - ], - [ - '5fa0ff', - RuntimeException::class, - 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', - ], - ['5fc000ff', InvalidArgumentException::class, 'This tag only accepts a Byte String object.'], - [ - '5fe0ff', - RuntimeException::class, - 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', - ], - [ - '7f4100ff', - RuntimeException::class, - 'Unable to parse the data. Infinite Text String object can only get Text String objects.', - ], - ['5f5f4100', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.'], - ['ffff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.'], - [ - '7f7f6100ffff', - RuntimeException::class, - 'Unable to parse the data. Infinite Text String object can only get Text String objects.', - ], - ['ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.'], - ['81ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.'], - ['8200ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.'], - ['a1ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.'], - ['a1ff00', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.'], - ['a100ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.'], - ['a20000ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.'], - ['9f81ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.'], - [ - '9f829f819f9fffffffff', - InvalidArgumentException::class, - 'Cannot parse the data. No enclosing indefinite.', - ], - ['bf00ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.'], - ['bf000000ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.'], - [ - '1f', - InvalidArgumentException::class, - 'Cannot parse the data. Found infinite length for Major Type "00000" (0).', - ], - [ - '3f', - InvalidArgumentException::class, - 'Cannot parse the data. Found infinite length for Major Type "00001" (1).', - ], - [ - 'df', - InvalidArgumentException::class, - 'Cannot parse the data. Found infinite length for Major Type "00110" (6).', - ], + yield [ + base_convert('00000011100', 2, 16), + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', + ]; + yield [ + base_convert('00000011101', 2, 16), + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', + ]; + yield [ + base_convert('00000011110', 2, 16), + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', + ]; + yield ['18', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['19', InvalidArgumentException::class, 'Out of range. Expected: 2, read: 0.']; + yield ['1a', InvalidArgumentException::class, 'Out of range. Expected: 4, read: 0.']; + yield ['1b', InvalidArgumentException::class, 'Out of range. Expected: 8, read: 0.']; + yield ['1901', InvalidArgumentException::class, 'Out of range. Expected: 2, read: 0.']; + yield ['1a0102', InvalidArgumentException::class, 'Out of range. Expected: 4, read: 0.']; + yield ['1b01020304050607', InvalidArgumentException::class, 'Out of range. Expected: 8, read: 0.']; + yield ['38', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['58', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['78', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['98', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['9a01ff00', InvalidArgumentException::class, 'Out of range. Expected: 4, read: 0.']; + yield ['b8', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['d8', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['f8', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['f900', InvalidArgumentException::class, 'Out of range. Expected: 2, read: 0.']; + yield ['fa0000', InvalidArgumentException::class, 'Out of range. Expected: 4, read: 0.']; + yield ['fb000000', InvalidArgumentException::class, 'Out of range. Expected: 8, read: 0.']; + yield ['41', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['61', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['5affffffff00', InvalidArgumentException::class, 'Out of range. Expected: 4294967295, read: 0.']; + yield [ + '5bffffffffffffffff010203', + IntegerOverflowException::class, + '18446744073709551615 is out of range -9223372036854775808 to 9223372036854775807 and cannot be represented as an integer.', + ]; + yield ['7affffffff00', InvalidArgumentException::class, 'Out of range. Expected: 4294967295, read: 0.']; + yield [ + '7b7fffffffffffffff010203', + InvalidArgumentException::class, + 'Out of range. Expected: 9223372036854775807, read: 0.', + ]; + yield ['81', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['818181818181818181', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['8200', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['a1', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['a20102', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['a100', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['a2000000', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['c0', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['5f4100', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['7f6100', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['9f', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['9f0102', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['bf', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['bf01020102', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['819f', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['9f8000', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['9f9f9f9f9fffffffff', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['9f819f819f9fffffff', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield [ + '1c', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', + ]; + yield [ + '1d', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', + ]; + yield [ + '1e', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', + ]; + yield [ + '3c', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', + ]; + yield [ + '3d', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', + ]; + yield [ + '3e', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', + ]; + yield [ + '5c', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', + ]; + yield [ + '5d', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', + ]; + yield [ + '5e', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', + ]; + yield [ + '7c', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', + ]; + yield [ + '7d', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', + ]; + yield [ + '7e', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', + ]; + yield [ + '9c', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', + ]; + yield [ + '9d', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', + ]; + yield [ + '9e', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', + ]; + yield [ + 'bc', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', + ]; + yield [ + 'bd', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', + ]; + yield [ + 'be', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', + ]; + yield [ + 'dc', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', + ]; + yield [ + 'dd', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', + ]; + yield [ + 'de', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', + ]; + yield [ + 'fc', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011100" (28).', + ]; + yield [ + 'fd', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011101" (29).', + ]; + yield [ + 'fe', + InvalidArgumentException::class, + 'Cannot parse the data. Found invalid Additional Information "00011110" (30).', + ]; + yield [ + 'f800', + InvalidArgumentException::class, + 'Invalid simple value. Content data must be between 32 and 255.', + ]; + yield [ + 'f801', + InvalidArgumentException::class, + 'Invalid simple value. Content data must be between 32 and 255.', + ]; + yield [ + 'f818', + InvalidArgumentException::class, + 'Invalid simple value. Content data must be between 32 and 255.', + ]; + yield [ + 'f81f', + InvalidArgumentException::class, + 'Invalid simple value. Content data must be between 32 and 255.', + ]; + yield [ + '5f00ff', + RuntimeException::class, + 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', + ]; + yield [ + '5f21ff', + RuntimeException::class, + 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', + ]; + yield [ + '5f6100ff', + RuntimeException::class, + 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', + ]; + yield [ + '5f80ff', + RuntimeException::class, + 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', + ]; + yield [ + '5fa0ff', + RuntimeException::class, + 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', + ]; + yield ['5fc000ff', InvalidArgumentException::class, 'This tag only accepts a Byte String object.']; + yield [ + '5fe0ff', + RuntimeException::class, + 'Unable to parse the data. Infinite Byte String object can only get Byte String objects.', + ]; + yield [ + '7f4100ff', + RuntimeException::class, + 'Unable to parse the data. Infinite Text String object can only get Text String objects.', + ]; + yield ['5f5f4100', InvalidArgumentException::class, 'Out of range. Expected: 1, read: 0.']; + yield ['ffff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.']; + yield [ + '7f7f6100ffff', + RuntimeException::class, + 'Unable to parse the data. Infinite Text String object can only get Text String objects.', + ]; + yield ['ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.']; + yield ['81ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.']; + yield ['8200ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.']; + yield ['a1ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.']; + yield ['a1ff00', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.']; + yield ['a100ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.']; + yield ['a20000ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.']; + yield ['9f81ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.']; + yield [ + '9f829f819f9fffffffff', + InvalidArgumentException::class, + 'Cannot parse the data. No enclosing indefinite.', + ]; + yield ['bf00ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.']; + yield ['bf000000ff', InvalidArgumentException::class, 'Cannot parse the data. No enclosing indefinite.']; + yield [ + '1f', + InvalidArgumentException::class, + 'Cannot parse the data. Found infinite length for Major Type "00000" (0).', + ]; + yield [ + '3f', + InvalidArgumentException::class, + 'Cannot parse the data. Found infinite length for Major Type "00001" (1).', + ]; + yield [ + 'df', + InvalidArgumentException::class, + 'Cannot parse the data. Found infinite length for Major Type "00110" (6).', ]; } } diff --git a/tests/OtherObject/AllTest.php b/tests/OtherObject/AllTest.php index 031b2d9..4f1f8de 100644 --- a/tests/OtherObject/AllTest.php +++ b/tests/OtherObject/AllTest.php @@ -18,12 +18,13 @@ use CBOR\OtherObject\UndefinedObject; use CBOR\StringStream; use CBOR\Test\CBORTestCase; -use function chr; -use const INF; use InvalidArgumentException; -use const M_PI; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; +use function chr; +use const INF; +use const M_PI; use const STR_PAD_LEFT; /** @@ -256,160 +257,165 @@ public function createInvalidSimpleObjectOutOfRange(): void SimpleObject::create(256); } - public static function getSimpleObjectWithoutContent(): array + public static function getSimpleObjectWithoutContent(): Iterator { - return [[0], [18], [19]]; + yield [0]; + yield [18]; + yield [19]; } - public static function getSimpleObjectWithContent(): array + public static function getSimpleObjectWithContent(): Iterator { - return [[32], [255]]; + yield [32]; + yield [255]; } /** * @see https://en.wikipedia.org/wiki/Half-precision_floating-point_format */ - public static function getHalfPrecisionFloatObject(): array + public static function getHalfPrecisionFloatObject(): Iterator { - return [ - [self::bitsToByteString('0000000000000001', 2), 0.000000059604645, 0.000000000000001], - [self::bitsToByteString('0000001111111111', 2), 0.000060975552, 0.000000000001], - [self::bitsToByteString('0000010000000000', 2), 0.00006103515625, 0.00000000000001], - [self::bitsToByteString('0111101111111111', 2), 65504, 1], - [self::bitsToByteString('0011101111111111', 2), 0.99951172, 0.00000001], - [self::bitsToByteString('0011110000000000', 2), 1, 1], - [self::bitsToByteString('0011110000000001', 2), 1.00097656, 0.00000001], - [self::bitsToByteString('0011010101010101', 2), 0.333251953125, 0.000000000001], - [self::bitsToByteString('1100000000000000', 2), -1, 1], - [self::bitsToByteString('0000000000000000', 2), 0, 1], - [self::bitsToByteString('1000000000000000', 2), -0, 1], - [self::bitsToByteString('0111110000000000', 2), INF, 1], - [self::bitsToByteString('1111110000000000', 2), -INF, 1], - ]; + yield [self::bitsToByteString('0000000000000001', 2), 0.000000059604645, 0.000000000000001]; + yield [self::bitsToByteString('0000001111111111', 2), 0.000060975552, 0.000000000001]; + yield [self::bitsToByteString('0000010000000000', 2), 0.00006103515625, 0.00000000000001]; + yield [self::bitsToByteString('0111101111111111', 2), 65504, 1]; + yield [self::bitsToByteString('0011101111111111', 2), 0.99951172, 0.00000001]; + yield [self::bitsToByteString('0011110000000000', 2), 1, 1]; + yield [self::bitsToByteString('0011110000000001', 2), 1.00097656, 0.00000001]; + yield [self::bitsToByteString('0011010101010101', 2), 0.333251953125, 0.000000000001]; + yield [self::bitsToByteString('1100000000000000', 2), -1, 1]; + yield [self::bitsToByteString('0000000000000000', 2), 0, 1]; + yield [self::bitsToByteString('1000000000000000', 2), -0, 1]; + yield [self::bitsToByteString('0111110000000000', 2), INF, 1]; + yield [self::bitsToByteString('1111110000000000', 2), -INF, 1]; } /** * @see https://en.wikipedia.org/wiki/Single-precision_floating-point_format */ - public static function getSinglePrecisionFloatObject(): array + public static function getSinglePrecisionFloatObject(): Iterator { - return [ - [self::bitsToByteString('00000000000000000000000000000001', 4), 2 ** -149, 10 ** -149], - [self::bitsToByteString('00000000011111111111111111111111', 4), 1.1754942107 * 10 ** -38, 10 ** -38], - [self::bitsToByteString('00000000100000000000000000000000', 4), 1.1754943508 * 10 ** -38, 10 ** -38], - [self::bitsToByteString('01111111011111111111111111111111', 4), 3.4028234664 * 10 ** 38, 10 ** 38], - [self::bitsToByteString('00111111011111111111111111111111', 4), 0.999999940395355225, 0.000000000000000001], - [self::bitsToByteString('00111111100000000000000000000000', 4), 1, 1], - [self::bitsToByteString('00111111100000000000000000000001', 4), 1.00000011920928955, 0.00000000000000001], - [self::bitsToByteString('11000000000000000000000000000000', 4), -2, 1], - [self::bitsToByteString('00000000000000000000000000000000', 4), 0, 0], - [self::bitsToByteString('10000000000000000000000000000000', 4), -0, 0], - [self::bitsToByteString('01111111100000000000000000000000', 4), INF, 0], - [self::bitsToByteString('11111111100000000000000000000000', 4), -INF, 0], - [self::bitsToByteString('01000000010010010000111111011011', 4), 3.14159274101257324, 0.00000000000000001], - [self::bitsToByteString('00111110101010101010101010101011', 4), 0.333333343267440796, 0.000000000000000001], + yield [self::bitsToByteString('00000000000000000000000000000001', 4), 2 ** -149, 10 ** -149]; + yield [self::bitsToByteString('00000000011111111111111111111111', 4), 1.1754942107 * 10 ** -38, 10 ** -38]; + yield [self::bitsToByteString('00000000100000000000000000000000', 4), 1.1754943508 * 10 ** -38, 10 ** -38]; + yield [self::bitsToByteString('01111111011111111111111111111111', 4), 3.4028234664 * 10 ** 38, 10 ** 38]; + yield [ + self::bitsToByteString('00111111011111111111111111111111', 4), + 0.999999940395355225, + 0.000000000000000001, + ]; + yield [self::bitsToByteString('00111111100000000000000000000000', 4), 1, 1]; + yield [self::bitsToByteString('00111111100000000000000000000001', 4), 1.00000011920928955, 0.00000000000000001]; + yield [self::bitsToByteString('11000000000000000000000000000000', 4), -2, 1]; + yield [self::bitsToByteString('00000000000000000000000000000000', 4), 0, 0]; + yield [self::bitsToByteString('10000000000000000000000000000000', 4), -0, 0]; + yield [self::bitsToByteString('01111111100000000000000000000000', 4), INF, 0]; + yield [self::bitsToByteString('11111111100000000000000000000000', 4), -INF, 0]; + yield [self::bitsToByteString('01000000010010010000111111011011', 4), 3.14159274101257324, 0.00000000000000001]; + yield [ + self::bitsToByteString('00111110101010101010101010101011', 4), + 0.333333343267440796, + 0.000000000000000001, ]; } /** * @see https://en.wikipedia.org/wiki/Double-precision_floating-point_format */ - public static function getDoublePrecisionFloatObject(): array + public static function getDoublePrecisionFloatObject(): Iterator { - return [ - [self::bitsToByteString('0011111111110000000000000000000000000000000000000000000000000000', 8), 1, 1], - [ - self::bitsToByteString('0011111111110000000000000000000000000000000000000000000000000001', 8), - 1.0000000000000002, - 0.0000000000000001, - ], - [ - self::bitsToByteString('0011111111110000000000000000000000000000000000000000000000000010', 8), - 1.0000000000000004, - 0.0000000000000001, - ], - [ - self::bitsToByteString('0100000000000000000000000000000000000000000000000000000000000000', 8), - 2, - 0.0000000000000001, - ], - [ - self::bitsToByteString('1100000000000000000000000000000000000000000000000000000000000000', 8), - -2, - 0.0000000000000001, - ], - [ - self::bitsToByteString('0100000000001000000000000000000000000000000000000000000000000000', 8), - 3, - 0.0000000000000001, - ], - [ - self::bitsToByteString('0100000000010000000000000000000000000000000000000000000000000000', 8), - 4, - 0.0000000000000001, - ], - [ - self::bitsToByteString('0100000000010100000000000000000000000000000000000000000000000000', 8), - 5, - 0.0000000000000001, - ], - [ - self::bitsToByteString('0100000000011000000000000000000000000000000000000000000000000000', 8), - 6, - 0.0000000000000001, - ], - [ - self::bitsToByteString('0100000000110111000000000000000000000000000000000000000000000000', 8), - 23, - 0.0000000000000001, - ], - [ - self::bitsToByteString('0011111110001000000000000000000000000000000000000000000000000000', 8), - 0.01171875, - 0.00000001, - ], - [ - self::bitsToByteString('0000000000000000000000000000000000000000000000000000000000000001', 8), - 4.9406564584124654 * 10 ** -324, - 10 ** -323, - ], - [ - self::bitsToByteString('0000000000001111111111111111111111111111111111111111111111111111', 8), - 2.2250738585072009 * 10 ** -308, - 10 ** -308, - ], - [ - self::bitsToByteString('0000000000010000000000000000000000000000000000000000000000000000', 8), - 2.2250738585072014 * 10 ** -308, - 10 ** -308, - ], - [ - self::bitsToByteString('0111111111101111111111111111111111111111111111111111111111111111', 8), - 1.7976931348623157 * 10 ** 308, - 1, - ], - [ - self::bitsToByteString('0000000000000000000000000000000000000000000000000000000000000000', 8), - 0, - 0.0000000000000001, - ], - [ - self::bitsToByteString('1000000000000000000000000000000000000000000000000000000000000000', 8), - -0, - 0.0000000000000001, - ], - [self::bitsToByteString('0111111111110000000000000000000000000000000000000000000000000000', 8), INF, 1], - [self::bitsToByteString('1111111111110000000000000000000000000000000000000000000000000000', 8), -INF, 1], - [ - self::bitsToByteString('0011111111010101010101010101010101010101010101010101010101010101', 8), - 1 / 3, - 0.0000000000000001, - ], - [ - self::bitsToByteString('0100000000001001001000011111101101010100010001000010110100011000', 8), - M_PI, - 0.0000000000000001, - ], + yield [self::bitsToByteString('0011111111110000000000000000000000000000000000000000000000000000', 8), 1, 1]; + yield [ + self::bitsToByteString('0011111111110000000000000000000000000000000000000000000000000001', 8), + 1.0000000000000002, + 0.0000000000000001, + ]; + yield [ + self::bitsToByteString('0011111111110000000000000000000000000000000000000000000000000010', 8), + 1.0000000000000004, + 0.0000000000000001, + ]; + yield [ + self::bitsToByteString('0100000000000000000000000000000000000000000000000000000000000000', 8), + 2, + 0.0000000000000001, + ]; + yield [ + self::bitsToByteString('1100000000000000000000000000000000000000000000000000000000000000', 8), + -2, + 0.0000000000000001, + ]; + yield [ + self::bitsToByteString('0100000000001000000000000000000000000000000000000000000000000000', 8), + 3, + 0.0000000000000001, + ]; + yield [ + self::bitsToByteString('0100000000010000000000000000000000000000000000000000000000000000', 8), + 4, + 0.0000000000000001, + ]; + yield [ + self::bitsToByteString('0100000000010100000000000000000000000000000000000000000000000000', 8), + 5, + 0.0000000000000001, + ]; + yield [ + self::bitsToByteString('0100000000011000000000000000000000000000000000000000000000000000', 8), + 6, + 0.0000000000000001, + ]; + yield [ + self::bitsToByteString('0100000000110111000000000000000000000000000000000000000000000000', 8), + 23, + 0.0000000000000001, + ]; + yield [ + self::bitsToByteString('0011111110001000000000000000000000000000000000000000000000000000', 8), + 0.01171875, + 0.00000001, + ]; + yield [ + self::bitsToByteString('0000000000000000000000000000000000000000000000000000000000000001', 8), + 4.9406564584124654 * 10 ** -324, + 10 ** -323, + ]; + yield [ + self::bitsToByteString('0000000000001111111111111111111111111111111111111111111111111111', 8), + 2.2250738585072009 * 10 ** -308, + 10 ** -308, + ]; + yield [ + self::bitsToByteString('0000000000010000000000000000000000000000000000000000000000000000', 8), + 2.2250738585072014 * 10 ** -308, + 10 ** -308, + ]; + yield [ + self::bitsToByteString('0111111111101111111111111111111111111111111111111111111111111111', 8), + 1.7976931348623157 * 10 ** 308, + 1, + ]; + yield [ + self::bitsToByteString('0000000000000000000000000000000000000000000000000000000000000000', 8), + 0, + 0.0000000000000001, + ]; + yield [ + self::bitsToByteString('1000000000000000000000000000000000000000000000000000000000000000', 8), + -0, + 0.0000000000000001, + ]; + yield [self::bitsToByteString('0111111111110000000000000000000000000000000000000000000000000000', 8), INF, 1]; + yield [self::bitsToByteString('1111111111110000000000000000000000000000000000000000000000000000', 8), -INF, 1]; + yield [ + self::bitsToByteString('0011111111010101010101010101010101010101010101010101010101010101', 8), + 1 / 3, + 0.0000000000000001, + ]; + yield [ + self::bitsToByteString('0100000000001001001000011111101101010100010001000010110100011000', 8), + M_PI, + 0.0000000000000001, ]; } diff --git a/tests/OtherTest.php b/tests/OtherTest.php index 8b13b94..f496e1e 100644 --- a/tests/OtherTest.php +++ b/tests/OtherTest.php @@ -5,6 +5,7 @@ namespace CBOR\Test; use CBOR\StringStream; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -24,8 +25,14 @@ public function aSignedIntegerCanBeParsed(string $data): void static::assertSame($data, bin2hex((string) $object)); } - public static function getDataSet(): array + public static function getDataSet(): Iterator { - return [['f4'], ['f5'], ['f6'], ['f7'], ['f0'], ['f820'], ['f8ff']]; + yield ['f4']; + yield ['f5']; + yield ['f6']; + yield ['f7']; + yield ['f0']; + yield ['f820']; + yield ['f8ff']; } } diff --git a/tests/SignedIntegerTest.php b/tests/SignedIntegerTest.php index aa2319b..6e2b57e 100644 --- a/tests/SignedIntegerTest.php +++ b/tests/SignedIntegerTest.php @@ -7,6 +7,7 @@ use CBOR\NegativeIntegerObject; use CBOR\StringStream; use InvalidArgumentException; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -29,15 +30,13 @@ public function createOnValidValue( static::assertSame($expectedAdditionalInformation, $unsignedInteger->getAdditionalInformation()); } - public static function getValidValue(): array + public static function getValidValue(): Iterator { - return [ - [-12_345_678, '-12345678', 1, 26], - [-255, '-255', 1, 24], - [-254, '-254', 1, 24], - [-65535, '-65535', 1, 25], - [-18, '-18', 1, 17], - ]; + yield [-12_345_678, '-12345678', 1, 26]; + yield [-255, '-255', 1, 24]; + yield [-254, '-254', 1, 24]; + yield [-65535, '-65535', 1, 25]; + yield [-18, '-18', 1, 17]; } #[Test] @@ -71,13 +70,13 @@ public function anUnsignedIntegerCanBeEncodedAndDecoded(string $data, string $ex static::assertSame($expectedNormalizedData, $object->normalize()); } - public static function getDataSet(): array + public static function getDataSet(): Iterator { - return [ - ['20', '-1'], ['29', '-10'], ['3863', '-100'], ['3903e7', '-1000'], [ - 'c349010000000000000000', - '-18446744073709551617', - ], ['3bffffffffffffffff', '-18446744073709551616'], - ]; + yield ['20', '-1']; + yield ['29', '-10']; + yield ['3863', '-100']; + yield ['3903e7', '-1000']; + yield ['c349010000000000000000', '-18446744073709551617']; + yield ['3bffffffffffffffff', '-18446744073709551616']; } } diff --git a/tests/Tag/DatetimeTagTest.php b/tests/Tag/DatetimeTagTest.php index 77cb7f6..42d18dc 100644 --- a/tests/Tag/DatetimeTagTest.php +++ b/tests/Tag/DatetimeTagTest.php @@ -15,6 +15,7 @@ use CBOR\TextStringObject; use CBOR\UnsignedIntegerObject; use InvalidArgumentException; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; @@ -84,19 +85,16 @@ public function createValidTimestampTagWithDoublePrecisionFloat(): void static::assertSame('3.141592', $tag->normalize()->format('U.u')); } - public static function getDatetimes(): array + public static function getDatetimes(): Iterator { $buildTestEntry = static fn (string $datetime, string $timestamp): array => [ TextStringObject::create($datetime), $timestamp, ]; - - return [ - $buildTestEntry('2003-12-13T18:30:02Z', '1071340202.000000'), - $buildTestEntry('2003-12-13T18:30:02.25Z', '1071340202.250000'), - $buildTestEntry('2003-12-13T18:30:02+01:00', '1071336602.000000'), - $buildTestEntry('2003-12-13T18:30:02.25+01:00', '1071336602.250000'), - $buildTestEntry('2003-12-13T18:30:02.251254+01:00', '1071336602.251254'), - ]; + yield $buildTestEntry('2003-12-13T18:30:02Z', '1071340202.000000'); + yield $buildTestEntry('2003-12-13T18:30:02.25Z', '1071340202.250000'); + yield $buildTestEntry('2003-12-13T18:30:02+01:00', '1071336602.000000'); + yield $buildTestEntry('2003-12-13T18:30:02.25+01:00', '1071336602.250000'); + yield $buildTestEntry('2003-12-13T18:30:02.251254+01:00', '1071336602.251254'); } } diff --git a/tests/TextStringObjectTest.php b/tests/TextStringObjectTest.php index 5c93a0f..a88b528 100644 --- a/tests/TextStringObjectTest.php +++ b/tests/TextStringObjectTest.php @@ -7,6 +7,7 @@ use CBOR\CBORObject; use CBOR\StringStream; use CBOR\TextStringObject; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -47,12 +48,10 @@ public function aTextStringObjectCanBeCreated( static::assertSame($string, $decoded->normalize()); } - public static function getData(): array + public static function getData(): Iterator { - return [ - ['Hello', 5, 5, '6548656c6c6f'], - ['(。◕‿◕。)', 17, 7, '7128efbda1e29795e280bfe29795efbda129'], - ['HelloHelloHelloHelloHello', 24, 25, '781948656c6c6f48656c6c6f48656c6c6f48656c6c6f48656c6c6f'], - ]; + yield ['Hello', 5, 5, '6548656c6c6f']; + yield ['(。◕‿◕。)', 17, 7, '7128efbda1e29795e280bfe29795efbda129']; + yield ['HelloHelloHelloHelloHello', 24, 25, '781948656c6c6f48656c6c6f48656c6c6f48656c6c6f48656c6c6f']; } } diff --git a/tests/UnsignedIntegerTest.php b/tests/UnsignedIntegerTest.php index 533d7d1..75b65e9 100644 --- a/tests/UnsignedIntegerTest.php +++ b/tests/UnsignedIntegerTest.php @@ -7,6 +7,7 @@ use CBOR\StringStream; use CBOR\UnsignedIntegerObject; use InvalidArgumentException; +use Iterator; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; @@ -29,9 +30,12 @@ public function createOnValidValue( static::assertSame($expectedAdditionalInformation, $unsignedInteger->getAdditionalInformation()); } - public static function getValidValue(): array + public static function getValidValue(): Iterator { - return [[12_345_678, '12345678', 0, 26], [255, '255', 0, 25], [254, '254', 0, 24], [18, '18', 0, 18]]; + yield [12_345_678, '12345678', 0, 26]; + yield [255, '255', 0, 25]; + yield [254, '254', 0, 24]; + yield [18, '18', 0, 18]; } #[Test] @@ -64,16 +68,19 @@ public function anUnsignedIntegerCanBeParsed(string $data, string $expectedNorma static::assertSame($expectedNormalizedData, $object->normalize()); } - public static function getDataSet(): array + public static function getDataSet(): Iterator { - return [ - ['00', '0'], ['01', '1'], ['0a', '10'], ['17', '23'], [ - '1818', - '24', - ], ['1819', '25'], ['1864', '100'], ['1903e8', '1000'], ['1a000f4240', '1000000'], [ - '1b000000e8d4a51000', - '1000000000000', - ], ['1bffffffffffffffff', '18446744073709551615'], ['c249010000000000000000', '18446744073709551616'], - ]; + yield ['00', '0']; + yield ['01', '1']; + yield ['0a', '10']; + yield ['17', '23']; + yield ['1818', '24']; + yield ['1819', '25']; + yield ['1864', '100']; + yield ['1903e8', '1000']; + yield ['1a000f4240', '1000000']; + yield ['1b000000e8d4a51000', '1000000000000']; + yield ['1bffffffffffffffff', '18446744073709551615']; + yield ['c249010000000000000000', '18446744073709551616']; } } diff --git a/tests/VectorTest.php b/tests/VectorTest.php index 3846717..e633375 100644 --- a/tests/VectorTest.php +++ b/tests/VectorTest.php @@ -5,9 +5,9 @@ namespace CBOR\Test; use CBOR\StringStream; -use const JSON_THROW_ON_ERROR; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; +use const JSON_THROW_ON_ERROR; /** * @internal From 658ed12a85a6b31fa312b89cd92f3a4ce6df4c6b Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Mon, 29 Jan 2024 21:33:48 +0100 Subject: [PATCH 2/2] updated merge action --- .../workflows/release-on-milestone-closed.yml | 56 ++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml index a5f1511..b9986a8 100644 --- a/.github/workflows/release-on-milestone-closed.yml +++ b/.github/workflows/release-on-milestone-closed.yml @@ -9,15 +9,15 @@ on: jobs: release: - name: "GIT tag, release & create merge-up PR" + name: "Release" runs-on: ubuntu-latest steps: - name: "Checkout" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" - name: "Release" - uses: "laminas/automatic-releases@1.19.0" + uses: "laminas/automatic-releases@1.24.0" with: command-name: "laminas:automatic-releases:release" env: @@ -27,8 +27,18 @@ jobs: "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} + merge-up: + name: "Create Merge-Up Pull Request" + runs-on: ubuntu-latest + if: ${{ always() }} + needs: "release" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + - name: "Create Merge-Up Pull Request" - uses: "laminas/automatic-releases@1.19.0" + uses: "laminas/automatic-releases@1.24.0" with: command-name: "laminas:automatic-releases:create-merge-up-pull-request" env: @@ -38,8 +48,18 @@ jobs: "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} + switch: + name: "Create and/or Switch to new Release Branch" + runs-on: ubuntu-latest + if: ${{ always() }} + needs: "merge-up" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + - name: "Create and/or Switch to new Release Branch" - uses: "laminas/automatic-releases@1.19.0" + uses: "laminas/automatic-releases@1.24.0" with: command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor" env: @@ -49,8 +69,20 @@ jobs: "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} + bump: + name: "Bump Changelog Version On Originating Release Branch" + runs-on: ubuntu-latest + if: ${{ always() }} + needs: "switch" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + with: + fetch-depth: 0 + - name: "Bump Changelog Version On Originating Release Branch" - uses: "laminas/automatic-releases@1.19.0" + uses: "laminas/automatic-releases@1.24.0" with: command-name: "laminas:automatic-releases:bump-changelog" env: @@ -60,8 +92,18 @@ jobs: "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} + milestones: + name: "Create new milestones" + runs-on: ubuntu-latest + if: ${{ always() }} + needs: "bump" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + - name: "Create new milestones" - uses: "laminas/automatic-releases@1.19.0" + uses: "laminas/automatic-releases@1.24.0" with: command-name: "laminas:automatic-releases:create-milestones" env: