From d4489f35cb32b1f4917734a8f386819f1eedb18c Mon Sep 17 00:00:00 2001 From: Michael Diodone Date: Thu, 7 Jul 2022 10:46:08 +0200 Subject: [PATCH] Add PHP 8.0 compatibility, fix iterating JSArray Due to the usage of each() in JSArray::valid() the internal array pointer would be advanced every time valid was called. This resulted in every odd element to be skipped (e.g. 1st, 3rd, 5th...) when iterating. --- .github/workflows/tests.yml | 2 +- .gitignore | 3 +++ composer.json | 2 +- phpunit.xml | 26 ++++++++++++++++++++++++++ phpunit.xml.dist | 18 ------------------ src/vierbergenlars/LibJs/JSArray.php | 2 +- tests/JSArrayTest.php | 25 +++++++++++++++++++++++++ tests/RegressionTest.php | 3 ++- tests/SemVerTest.php | 3 ++- tests/VersionTest.php | 7 ++++--- 10 files changed, 65 insertions(+), 26 deletions(-) create mode 100644 .gitignore create mode 100644 phpunit.xml delete mode 100644 phpunit.xml.dist create mode 100644 tests/JSArrayTest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 816830b..6fc01e9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,7 @@ jobs: tests: strategy: matrix: - php-versions: ['7.3', '7.4'] + php-versions: ['7.3', '7.4', '8.0', '8.1'] runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3eb76cc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.phpunit.cache +/composer.lock +/vendor diff --git a/composer.json b/composer.json index 55f2c2b..ef0f3a1 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "php": ">=5.3.0" }, "require-dev": { - "phpunit/phpunit": "~4" + "phpunit/phpunit": "^9.5.21" }, "autoload": { "psr-0": { diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..fd5e558 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,26 @@ + + + + + tests + + + + + + src + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index c4c78cc..0000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,18 +0,0 @@ - - - ./tests - - - - - ./src - - - - - - - - - - \ No newline at end of file diff --git a/src/vierbergenlars/LibJs/JSArray.php b/src/vierbergenlars/LibJs/JSArray.php index dfd0668..43d48c7 100644 --- a/src/vierbergenlars/LibJs/JSArray.php +++ b/src/vierbergenlars/LibJs/JSArray.php @@ -194,7 +194,7 @@ public function rewind() public function valid() { - return each($this->array)!== false; + return key($this->array) !== null; } public function valueOf() diff --git a/tests/JSArrayTest.php b/tests/JSArrayTest.php new file mode 100644 index 0000000..598a00a --- /dev/null +++ b/tests/JSArrayTest.php @@ -0,0 +1,25 @@ +assertEquals(array(new JString('1.0.0'), new JString('2.0.0')), $versions); + } +} diff --git a/tests/RegressionTest.php b/tests/RegressionTest.php index 1daa441..b561d3c 100644 --- a/tests/RegressionTest.php +++ b/tests/RegressionTest.php @@ -2,9 +2,10 @@ namespace vierbergenlars\SemVer\Tests; +use PHPUnit\Framework\TestCase; use vierbergenlars\SemVer; -class RegressionTest extends \PHPUnit_Framework_TestCase +class RegressionTest extends TestCase { public function testBug23() { diff --git a/tests/SemVerTest.php b/tests/SemVerTest.php index f507112..dc27e7f 100644 --- a/tests/SemVerTest.php +++ b/tests/SemVerTest.php @@ -2,9 +2,10 @@ namespace vierbergenlars\SemVer\Tests\Internal; +use PHPUnit\Framework\TestCase; use vierbergenlars\SemVer\Internal as SemVer; -class SemVerTest extends \PHPUnit_Framework_TestCase +class SemVerTest extends TestCase { public function testComparison() { diff --git a/tests/VersionTest.php b/tests/VersionTest.php index ad44ea9..2b8ab80 100644 --- a/tests/VersionTest.php +++ b/tests/VersionTest.php @@ -2,9 +2,10 @@ namespace vierbergenlars\SemVer\Tests; +use PHPUnit\Framework\TestCase; use vierbergenlars\SemVer; -class VersionTest extends \PHPUnit_Framework_TestCase +class VersionTest extends TestCase { public function testKeepSimpleversion() { @@ -238,19 +239,19 @@ public function testNotSatisfiedBy() /** * @dataProvider invalidSemanticVersionProvider - * @expectedException \vierbergenlars\SemVer\SemVerException */ public function testInvalidExpressionString($version) { + $this->expectException(SemVer\SemVerException::class); new SemVer\expression($version); } /** * @dataProvider invalidSemanticVersionProvider - * @expectedException \vierbergenlars\SemVer\SemVerException */ public function testInvalidVersionString($version) { + $this->expectException(SemVer\SemVerException::class); new SemVer\version($version); }