Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Add PHP 8.0 compatibility, fix iterating JSArray
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mdio committed Jul 7, 2022
1 parent 120ca33 commit d4489f3
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.phpunit.cache
/composer.lock
/vendor
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4"
"phpunit/phpunit": "^9.5.21"
},
"autoload": {
"psr-0": {
Expand Down
26 changes: 26 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
18 changes: 0 additions & 18 deletions phpunit.xml.dist

This file was deleted.

2 changes: 1 addition & 1 deletion src/vierbergenlars/LibJs/JSArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function rewind()

public function valid()
{
return each($this->array)!== false;
return key($this->array) !== null;
}

public function valueOf()
Expand Down
25 changes: 25 additions & 0 deletions tests/JSArrayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace vierbergenlars\SemVer\Tests;

use PHPUnit\Framework\TestCase;
use vierbergenlars\LibJs\JSArray;
use vierbergenlars\LibJs\JString;

/**
* @copyright ResearchGate GmbH
*/
class JSArrayTest extends TestCase
{

public function testIterableJSArray()
{
$jsArray = new JSArray(array('1.0.0', '2.0.0'));
$versions = array();
foreach ($jsArray as $version) {
$versions[] = $version;
}

$this->assertEquals(array(new JString('1.0.0'), new JString('2.0.0')), $versions);
}
}
3 changes: 2 additions & 1 deletion tests/RegressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/SemVerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
7 changes: 4 additions & 3 deletions tests/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit d4489f3

Please sign in to comment.