From 622b59c0a52505dfa95102ffe2ac3cb57681b0d9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 30 Jul 2023 21:23:09 +0000 Subject: [PATCH 1/3] Update all non-major dependencies | datasource | package | from | to | | ----------- | ---------------------- | ------- | ------ | | github-tags | codecov/codecov-action | v3.1.1 | v3.1.4 | | packagist | infection/infection | 0.26.21 | 0.27.0 | | packagist | lcobucci/clock | 3.0.0 | 3.1.0 | | packagist | phpunit/phpunit | 10.2.3 | 10.2.6 | | github-tags | shivammathur/setup-php | 2.24.0 | 2.25.5 | --- .github/workflows/backwards-compatibility.yml | 2 +- .github/workflows/benchmarks.yml | 2 +- .github/workflows/coding-standards.yml | 2 +- .github/workflows/composer-json-lint.yml | 2 +- .github/workflows/mutation-tests.yml | 4 +- .github/workflows/phpunit.yml | 4 +- .github/workflows/static-analysis.yml | 2 +- composer.json | 4 +- composer.lock | 117 +++++++++--------- 9 files changed, 71 insertions(+), 68 deletions(-) diff --git a/.github/workflows/backwards-compatibility.yml b/.github/workflows/backwards-compatibility.yml index ffdea623..8cecba3b 100644 --- a/.github/workflows/backwards-compatibility.yml +++ b/.github/workflows/backwards-compatibility.yml @@ -16,7 +16,7 @@ jobs: fetch-depth: 0 - name: "Install PHP" - uses: "shivammathur/setup-php@2.24.0" + uses: "shivammathur/setup-php@2.25.5" with: php-version: "8.1" ini-values: memory_limit=-1 diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index a2fdd0c4..12e296fb 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -24,7 +24,7 @@ jobs: uses: "actions/checkout@v3" - name: "Install PHP" - uses: "shivammathur/setup-php@2.24.0" + uses: "shivammathur/setup-php@2.25.5" with: coverage: "none" php-version: "${{ matrix.php-version }}" diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index e3b2f4cf..9362a3dd 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -24,7 +24,7 @@ jobs: uses: "actions/checkout@v3" - name: "Install PHP" - uses: "shivammathur/setup-php@2.24.0" + uses: "shivammathur/setup-php@2.25.5" with: coverage: "none" php-version: "${{ matrix.php-version }}" diff --git a/.github/workflows/composer-json-lint.yml b/.github/workflows/composer-json-lint.yml index ff91c047..ff82a4c0 100644 --- a/.github/workflows/composer-json-lint.yml +++ b/.github/workflows/composer-json-lint.yml @@ -24,7 +24,7 @@ jobs: uses: "actions/checkout@v3" - name: "Install PHP" - uses: "shivammathur/setup-php@2.24.0" + uses: "shivammathur/setup-php@2.25.5" with: coverage: "none" php-version: "${{ matrix.php-version }}" diff --git a/.github/workflows/mutation-tests.yml b/.github/workflows/mutation-tests.yml index c754bdd2..5ddfdd92 100644 --- a/.github/workflows/mutation-tests.yml +++ b/.github/workflows/mutation-tests.yml @@ -24,7 +24,7 @@ jobs: uses: "actions/checkout@v3" - name: "Install PHP" - uses: "shivammathur/setup-php@2.24.0" + uses: "shivammathur/setup-php@2.25.5" with: coverage: "xdebug" php-version: "${{ matrix.php-version }}" @@ -58,4 +58,4 @@ jobs: run: "make infection PHPUNIT_FLAGS=--coverage-clover=coverage.xml INFECTION_FLAGS=--logger-github" - name: "Upload Code Coverage" - uses: "codecov/codecov-action@v3.1.1" + uses: "codecov/codecov-action@v3.1.4" diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index bc8a3ec9..b52af8b0 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -27,7 +27,7 @@ jobs: uses: "actions/checkout@v3" - name: "Install PHP" - uses: "shivammathur/setup-php@2.24.0" + uses: "shivammathur/setup-php@2.25.5" with: coverage: "none" php-version: "${{ matrix.php-version }}" @@ -83,7 +83,7 @@ jobs: uses: "actions/checkout@v3" - name: "Install PHP" - uses: "shivammathur/setup-php@2.24.0" + uses: "shivammathur/setup-php@2.25.5" with: coverage: "none" php-version: "${{ matrix.php-version }}" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 42030572..d30678eb 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -24,7 +24,7 @@ jobs: uses: "actions/checkout@v3" - name: "Install PHP" - uses: "shivammathur/setup-php@2.24.0" + uses: "shivammathur/setup-php@2.25.5" with: coverage: "none" php-version: "${{ matrix.php-version }}" diff --git a/composer.json b/composer.json index 7a1bbf1e..653dd601 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "psr/clock": "^1.0" }, "require-dev": { - "infection/infection": "^0.26.19", + "infection/infection": "^0.27.0", "lcobucci/clock": "^3.0", "lcobucci/coding-standard": "^11.0", "phpbench/phpbench": "^1.2.9", @@ -34,7 +34,7 @@ "phpstan/phpstan-deprecation-rules": "^1.1.3", "phpstan/phpstan-phpunit": "^1.3.10", "phpstan/phpstan-strict-rules": "^1.5.0", - "phpunit/phpunit": "^10.0.17" + "phpunit/phpunit": "^10.2.6" }, "suggest": { "lcobucci/clock": ">= 3.0" diff --git a/composer.lock b/composer.lock index 07386805..b507c942 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "88a94131fdd964dd8fadee192dc4dfee", + "content-hash": "ca4967db7ef943a9105aab433001254e", "packages": [ { "name": "psr/clock", @@ -573,16 +573,16 @@ }, { "name": "fidry/cpu-core-counter", - "version": "0.4.1", + "version": "0.5.1", "source": { "type": "git", "url": "https://github.com/theofidry/cpu-core-counter.git", - "reference": "79261cc280aded96d098e1b0e0ba0c4881b432c2" + "reference": "b58e5a3933e541dc286cc91fc4f3898bbc6f1623" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/79261cc280aded96d098e1b0e0ba0c4881b432c2", - "reference": "79261cc280aded96d098e1b0e0ba0c4881b432c2", + "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/b58e5a3933e541dc286cc91fc4f3898bbc6f1623", + "reference": "b58e5a3933e541dc286cc91fc4f3898bbc6f1623", "shasum": "" }, "require": { @@ -622,7 +622,7 @@ ], "support": { "issues": "https://github.com/theofidry/cpu-core-counter/issues", - "source": "https://github.com/theofidry/cpu-core-counter/tree/0.4.1" + "source": "https://github.com/theofidry/cpu-core-counter/tree/0.5.1" }, "funding": [ { @@ -630,7 +630,7 @@ "type": "github" } ], - "time": "2022-12-16T22:01:02+00:00" + "time": "2022-12-24T12:35:10+00:00" }, { "name": "infection/abstract-testframework-adapter", @@ -811,16 +811,16 @@ }, { "name": "infection/infection", - "version": "0.26.21", + "version": "0.27.0", "source": { "type": "git", "url": "https://github.com/infection/infection.git", - "reference": "9bbe4994d204587e0e27475e6681b66608a690a9" + "reference": "a9ff8171577d98b887d7f16428edd81ff69ce887" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/infection/infection/zipball/9bbe4994d204587e0e27475e6681b66608a690a9", - "reference": "9bbe4994d204587e0e27475e6681b66608a690a9", + "url": "https://api.github.com/repos/infection/infection/zipball/a9ff8171577d98b887d7f16428edd81ff69ce887", + "reference": "a9ff8171577d98b887d7f16428edd81ff69ce887", "shasum": "" }, "require": { @@ -831,7 +831,7 @@ "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", - "fidry/cpu-core-counter": "^0.4.0", + "fidry/cpu-core-counter": "^0.4.0 || ^0.5.0", "infection/abstract-testframework-adapter": "^0.5.0", "infection/extension-installer": "^0.1.0", "infection/include-interceptor": "^0.2.5", @@ -862,11 +862,13 @@ "phpspec/prophecy": "^1.15", "phpspec/prophecy-phpunit": "^2.0", "phpstan/extension-installer": "^1.1.0", - "phpstan/phpstan": "^1.3.0", + "phpstan/phpstan": "^1.10.15", "phpstan/phpstan-phpunit": "^1.0.0", "phpstan/phpstan-strict-rules": "^1.1.0", "phpstan/phpstan-webmozart-assert": "^1.0.2", "phpunit/phpunit": "^9.5.5", + "rector/rector": "^0.16.0", + "sidz/phpstan-rules": "^0.2.1", "symfony/phpunit-bridge": "^5.4 || ^6.0", "symfony/yaml": "^5.4 || ^6.0", "thecodingmachine/phpstan-safe-rule": "^1.2.0" @@ -925,7 +927,7 @@ ], "support": { "issues": "https://github.com/infection/infection/issues", - "source": "https://github.com/infection/infection/tree/0.26.21" + "source": "https://github.com/infection/infection/tree/0.27.0" }, "funding": [ { @@ -937,7 +939,7 @@ "type": "open_collective" } ], - "time": "2023-04-25T19:40:27+00:00" + "time": "2023-05-16T05:28:04+00:00" }, { "name": "justinrainbow/json-schema", @@ -1922,16 +1924,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "10.1.2", + "version": "10.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "db1497ec8dd382e82c962f7abbe0320e4882ee4e" + "reference": "be1fe461fdc917de2a29a452ccf2657d325b443d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/db1497ec8dd382e82c962f7abbe0320e4882ee4e", - "reference": "db1497ec8dd382e82c962f7abbe0320e4882ee4e", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/be1fe461fdc917de2a29a452ccf2657d325b443d", + "reference": "be1fe461fdc917de2a29a452ccf2657d325b443d", "shasum": "" }, "require": { @@ -1988,7 +1990,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.2" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.3" }, "funding": [ { @@ -1996,7 +1998,7 @@ "type": "github" } ], - "time": "2023-05-22T09:04:27+00:00" + "time": "2023-07-26T13:45:28+00:00" }, { "name": "phpunit/php-file-iterator", @@ -2242,16 +2244,16 @@ }, { "name": "phpunit/phpunit", - "version": "10.2.3", + "version": "10.2.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "35c8cac1734ede2ae354a6644f7088356ff5b08e" + "reference": "1c17815c129f133f3019cc18e8d0c8622e6d9bcd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35c8cac1734ede2ae354a6644f7088356ff5b08e", - "reference": "35c8cac1734ede2ae354a6644f7088356ff5b08e", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1c17815c129f133f3019cc18e8d0c8622e6d9bcd", + "reference": "1c17815c129f133f3019cc18e8d0c8622e6d9bcd", "shasum": "" }, "require": { @@ -2323,7 +2325,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.2.3" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.6" }, "funding": [ { @@ -2339,7 +2341,7 @@ "type": "tidelift" } ], - "time": "2023-06-30T06:17:38+00:00" + "time": "2023-07-17T12:08:28+00:00" }, { "name": "psr/cache", @@ -3126,16 +3128,16 @@ }, { "name": "sebastian/global-state", - "version": "6.0.0", + "version": "6.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "aab257c712de87b90194febd52e4d184551c2d44" + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/aab257c712de87b90194febd52e4d184551c2d44", - "reference": "aab257c712de87b90194febd52e4d184551c2d44", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/7ea9ead78f6d380d2a667864c132c2f7b83055e4", + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4", "shasum": "" }, "require": { @@ -3175,7 +3177,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.0" + "security": "https://github.com/sebastianbergmann/global-state/security/policy", + "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.1" }, "funding": [ { @@ -3183,7 +3186,7 @@ "type": "github" } ], - "time": "2023-02-03T07:07:38+00:00" + "time": "2023-07-19T07:19:23+00:00" }, { "name": "sebastian/lines-of-code", @@ -3714,16 +3717,16 @@ }, { "name": "symfony/console", - "version": "v6.3.0", + "version": "v6.3.2", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "8788808b07cf0bdd6e4b7fdd23d8ddb1470c83b7" + "reference": "aa5d64ad3f63f2e48964fc81ee45cb318a723898" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/8788808b07cf0bdd6e4b7fdd23d8ddb1470c83b7", - "reference": "8788808b07cf0bdd6e4b7fdd23d8ddb1470c83b7", + "url": "https://api.github.com/repos/symfony/console/zipball/aa5d64ad3f63f2e48964fc81ee45cb318a723898", + "reference": "aa5d64ad3f63f2e48964fc81ee45cb318a723898", "shasum": "" }, "require": { @@ -3784,7 +3787,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v6.3.0" + "source": "https://github.com/symfony/console/tree/v6.3.2" }, "funding": [ { @@ -3800,7 +3803,7 @@ "type": "tidelift" } ], - "time": "2023-05-29T12:49:39+00:00" + "time": "2023-07-19T20:17:28+00:00" }, { "name": "symfony/deprecation-contracts", @@ -3934,16 +3937,16 @@ }, { "name": "symfony/finder", - "version": "v6.3.0", + "version": "v6.3.2", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "d9b01ba073c44cef617c7907ce2419f8d00d75e2" + "reference": "78ce4c29757d657d2b41a91c328923b9a0d6b43d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/d9b01ba073c44cef617c7907ce2419f8d00d75e2", - "reference": "d9b01ba073c44cef617c7907ce2419f8d00d75e2", + "url": "https://api.github.com/repos/symfony/finder/zipball/78ce4c29757d657d2b41a91c328923b9a0d6b43d", + "reference": "78ce4c29757d657d2b41a91c328923b9a0d6b43d", "shasum": "" }, "require": { @@ -3978,7 +3981,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v6.3.0" + "source": "https://github.com/symfony/finder/tree/v6.3.2" }, "funding": [ { @@ -3994,7 +3997,7 @@ "type": "tidelift" } ], - "time": "2023-04-02T01:25:41+00:00" + "time": "2023-07-13T14:29:38+00:00" }, { "name": "symfony/options-resolver", @@ -4395,16 +4398,16 @@ }, { "name": "symfony/process", - "version": "v6.3.0", + "version": "v6.3.2", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "8741e3ed7fe2e91ec099e02446fb86667a0f1628" + "reference": "c5ce962db0d9b6e80247ca5eb9af6472bd4d7b5d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/8741e3ed7fe2e91ec099e02446fb86667a0f1628", - "reference": "8741e3ed7fe2e91ec099e02446fb86667a0f1628", + "url": "https://api.github.com/repos/symfony/process/zipball/c5ce962db0d9b6e80247ca5eb9af6472bd4d7b5d", + "reference": "c5ce962db0d9b6e80247ca5eb9af6472bd4d7b5d", "shasum": "" }, "require": { @@ -4436,7 +4439,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v6.3.0" + "source": "https://github.com/symfony/process/tree/v6.3.2" }, "funding": [ { @@ -4452,7 +4455,7 @@ "type": "tidelift" } ], - "time": "2023-05-19T08:06:44+00:00" + "time": "2023-07-12T16:00:22+00:00" }, { "name": "symfony/service-contracts", @@ -4538,16 +4541,16 @@ }, { "name": "symfony/string", - "version": "v6.3.0", + "version": "v6.3.2", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "f2e190ee75ff0f5eced645ec0be5c66fac81f51f" + "reference": "53d1a83225002635bca3482fcbf963001313fb68" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/f2e190ee75ff0f5eced645ec0be5c66fac81f51f", - "reference": "f2e190ee75ff0f5eced645ec0be5c66fac81f51f", + "url": "https://api.github.com/repos/symfony/string/zipball/53d1a83225002635bca3482fcbf963001313fb68", + "reference": "53d1a83225002635bca3482fcbf963001313fb68", "shasum": "" }, "require": { @@ -4604,7 +4607,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.3.0" + "source": "https://github.com/symfony/string/tree/v6.3.2" }, "funding": [ { @@ -4620,7 +4623,7 @@ "type": "tidelift" } ], - "time": "2023-03-21T21:06:29+00:00" + "time": "2023-07-05T08:41:27+00:00" }, { "name": "thecodingmachine/safe", From 5cec2fb28ecae9cdf18907bf07a2e92ec1dfa197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Sun, 30 Jul 2023 23:29:48 +0200 Subject: [PATCH 2/3] Update PHPUnit configuration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luís Cobucci --- phpunit.xml.dist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2a28b61a..52dddd79 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -23,9 +23,9 @@ - + src - + From 6dbbca47e865fc00c1f7045db29a55473b357aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Mon, 31 Jul 2023 00:07:31 +0200 Subject: [PATCH 3/3] Extend test scenarios MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luís Cobucci --- tests/SodiumBase64PolyfillTest.php | 94 ++++++++++++++---------------- 1 file changed, 44 insertions(+), 50 deletions(-) diff --git a/tests/SodiumBase64PolyfillTest.php b/tests/SodiumBase64PolyfillTest.php index 74a893de..e8db0c09 100644 --- a/tests/SodiumBase64PolyfillTest.php +++ b/tests/SodiumBase64PolyfillTest.php @@ -7,8 +7,8 @@ use Lcobucci\JWT\SodiumBase64Polyfill; use PHPUnit\Framework\TestCase; +use function rtrim; use function sodium_base642bin; -use function sodium_bin2base64; use const SODIUM_BASE64_VARIANT_ORIGINAL; use const SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING; @@ -18,13 +18,8 @@ /** @coversDefaultClass \Lcobucci\JWT\SodiumBase64Polyfill */ final class SodiumBase64PolyfillTest extends TestCase { - private string $testString; - - protected function setUp(): void - { - // For proper testing we need a string that can challenge every variant - $this->testString = sodium_base642bin('I+o2tVq8ynY=', SODIUM_BASE64_VARIANT_ORIGINAL, ''); - } + private const B64 = 'I+o2tVq8ynY='; + private const B64URL = 'lZ-2HIl9dTz_Oy0nAb-2gvKdG0jhHJ36XB2rWAKj8Uo='; /** * @test @@ -57,88 +52,87 @@ public function constantsMatchExtensionOnes(): void /** * @test - * @dataProvider provideVariants + * @dataProvider base64Variants * * @covers ::bin2base64 * @covers ::bin2base64Fallback */ - public function bin2base64(int $variant): void + public function bin2base64(string $encoded, string $binary, int $variant): void { - $expected = sodium_bin2base64($this->testString, $variant); - - self::assertSame( - $expected, - SodiumBase64Polyfill::bin2base64($this->testString, $variant), - ); - - self::assertSame( - $expected, - SodiumBase64Polyfill::bin2base64Fallback($this->testString, $variant), - ); + self::assertSame($encoded, SodiumBase64Polyfill::bin2base64($binary, $variant)); + self::assertSame($encoded, SodiumBase64Polyfill::bin2base64Fallback($binary, $variant)); } /** * @test - * @dataProvider provideVariants + * @dataProvider base64Variants * * @covers ::base642bin * @covers ::base642binFallback */ - public function base642binFallback(int $variant): void + public function base642binFallback(string $encoded, string $binary, int $variant): void { - self::assertSame( - $this->testString, - SodiumBase64Polyfill::base642bin( - sodium_bin2base64($this->testString, $variant), - $variant, - ), - ); - - self::assertSame( - $this->testString, - SodiumBase64Polyfill::base642binFallback( - sodium_bin2base64($this->testString, $variant), - $variant, - ), - ); + self::assertSame($binary, SodiumBase64Polyfill::base642bin($encoded, $variant)); + self::assertSame($binary, SodiumBase64Polyfill::base642binFallback($encoded, $variant)); } - /** @return int[][] */ - public static function provideVariants(): array + /** @return iterable */ + public static function base64Variants(): iterable { - return [ - [SODIUM_BASE64_VARIANT_ORIGINAL], - [SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING], - [SODIUM_BASE64_VARIANT_URLSAFE], - [SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING], - ]; + $binary = sodium_base642bin(self::B64, SODIUM_BASE64_VARIANT_ORIGINAL, ''); + + yield [self::B64, $binary, SODIUM_BASE64_VARIANT_ORIGINAL]; + yield [rtrim(self::B64, '='), $binary, SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING]; + + $urlBinary = sodium_base642bin(self::B64URL, SODIUM_BASE64_VARIANT_URLSAFE, ''); + + yield [self::B64URL, $urlBinary, SODIUM_BASE64_VARIANT_URLSAFE]; + yield [rtrim(self::B64URL, '='), $urlBinary, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING]; } /** * @test + * @dataProvider invalidBase64 * * @covers ::base642bin * * @uses \Lcobucci\JWT\Encoding\CannotDecodeContent::invalidBase64String() */ - public function sodiumBase642BinRaisesExceptionOnInvalidBase64(): void + public function sodiumBase642BinRaisesExceptionOnInvalidBase64(string $content, int $variant): void { $this->expectException(CannotDecodeContent::class); - SodiumBase64Polyfill::base642bin('ááá', SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING); + SodiumBase64Polyfill::base642bin($content, $variant); } /** * @test + * @dataProvider invalidBase64 * * @covers ::base642binFallback * * @uses \Lcobucci\JWT\Encoding\CannotDecodeContent::invalidBase64String() */ - public function fallbackBase642BinRaisesExceptionOnInvalidBase64(): void + public function fallbackBase642BinRaisesExceptionOnInvalidBase64(string $content, int $variant): void { $this->expectException(CannotDecodeContent::class); - SodiumBase64Polyfill::base642binFallback('ááá', SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING); + SodiumBase64Polyfill::base642binFallback($content, $variant); + } + + /** @return iterable */ + public static function invalidBase64(): iterable + { + yield 'UTF-8 content' => ['ááá', SODIUM_BASE64_VARIANT_ORIGINAL]; + + yield 'b64Url variant against original (padded)' => [ + self::B64URL, + SODIUM_BASE64_VARIANT_ORIGINAL, + ]; + + yield 'b64Url variant against original (not padded)' => [ + rtrim(self::B64URL, '='), + SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING, + ]; } }