Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rdohms/phpunit-arraysubset-asserts
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.0
Choose a base ref
...
head repository: rdohms/phpunit-arraysubset-asserts
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
14 changes: 11 additions & 3 deletions .github/workflows/check-cs.yml
Original file line number Diff line number Diff line change
@@ -10,6 +10,12 @@ on:
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
fix-style:
name: Fix Code Style
@@ -20,21 +26,23 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.x
coverage: none
tools: composer, cs2pr

- name: Install dependencies
run: |
composer update --prefer-dist --no-suggest --no-progress
composer update --prefer-dist --no-suggest --no-progress --no-interaction
- name: Check Code Style
id: phpcs
run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml

- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml
38 changes: 38 additions & 0 deletions .github/workflows/promote-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Releases

on:
push:
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Pick Release Version from git tag
id: version
run: |
echo "::set-output name=version::${GITHUB_REF#refs/*/}"
- name: Debug Release Version
run: echo "Extracted this version ${{ steps.version.outputs.version }}"
- name: Pick Changelog from git tag
id: changelog
run: |
OUTPUT=$(git tag -l --format='%(contents:body)' ${GITHUB_REF#refs/*/})
OUTPUT="${OUTPUT//'%'/'%25'}"
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
echo "body=$OUTPUT" >> $GITHUB_OUTPUT
- name: Debug Changelog
run: echo "Extracted this Changelog \n ${{ steps.changelog.outputs.body }}"
- uses: ncipollo/release-action@v1
with:
body: ${{ steps.changelog.outputs.body }}
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.version }}
allowUpdates: true
50 changes: 37 additions & 13 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -7,11 +7,15 @@ on:
pull_request:
branches:
- "*"
schedule:
- cron: '0 0 * * *'
# Allow manually triggering the workflow.
workflow_dispatch:

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
php-tests:
runs-on: ubuntu-latest
@@ -21,11 +25,14 @@ jobs:

strategy:
matrix:
php: ['8.0', '7.4', '7.3', '7.2', '7.1', '7.0', '5.6', '5.5', '5.4']
php: ['8.3', '8.2', '8.1', '8.0', '7.4', '7.3', '7.2', '7.1', '7.0', '5.6', '5.5', '5.4']
dependency-version: ['prefer-stable']
experimental: [false]

include:
- php: '7.2'
dependency-version: 'prefer-lowest'
experimental: false
- php: '7.3'
dependency-version: 'prefer-lowest'
experimental: false
@@ -35,8 +42,17 @@ jobs:
- php: '8.0'
dependency-version: 'prefer-lowest'
experimental: false

- php: '8.1'
dependency-version: 'prefer-lowest'
experimental: false
- php: '8.2'
dependency-version: 'prefer-lowest'
experimental: false
- php: '8.3'
dependency-version: 'prefer-lowest'
experimental: false

- php: '8.4'
dependency-version: 'prefer-stable'
experimental: true

@@ -45,33 +61,41 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: error_reporting=E_ALL, display_errors=On
coverage: none
tools: composer

# Remove the coding standards package as it has a higher minimum PHP
# requirement and would prevent running the tests on older PHP versions.
- name: 'Composer: remove CS dependency'
run: composer remove --dev --no-update dms/coding-standard
run: composer remove --dev --no-update dms/coding-standard --no-interaction

- name: 'Composer: update PHPUnit for testing lowest (PHP 7.2)'
if: ${{ matrix.dependency-version == 'prefer-lowest' && matrix.php == '7.2' }}
run: composer require --no-update phpunit/phpunit:"^8.0" --no-interaction

- name: 'Composer: update PHPUnit for testing lowest'
if: ${{ matrix.dependency-version == 'prefer-lowest' }}
run: composer require --no-update phpunit/phpunit:"^9.0"
- name: 'Composer: update PHPUnit for testing lowest (PHP 7.3+)'
if: ${{ matrix.dependency-version == 'prefer-lowest' && matrix.php != '7.2' }}
run: composer require --no-update phpunit/phpunit:"^9.0" --no-interaction

- name: Install dependencies - normal
if: ${{ matrix.php < 8.1 }}
if: ${{ matrix.php < 8.4 }}
run: |
composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress
composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress --no-interaction
- name: Install dependencies - ignore platform reqs
if: ${{ matrix.php >= 8.1 }}
if: ${{ matrix.php >= 8.4 }}
run: |
composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress --ignore-platform-reqs
composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress --ignore-platform-req=php+ --no-interaction
- name: Migrate PHPUnit configuration if possible
run: vendor/bin/phpunit --migrate-configuration || echo '--migrate-configuration not available'

- name: Execute Unit Tests
run: vendor/bin/phpunit
14 changes: 14 additions & 0 deletions .github/workflows/update-milestone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'Update Milestone on Release'

on:
release:
types: [released]

jobs:
update-milestone-on-release:
runs-on: ubuntu-latest
steps:
- name: 'Update Milestone on Release'
uses: mhutchie/update-milestone-on-release@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -15,11 +15,9 @@ composer require --dev dms/phpunit-arraysubset-asserts

> :bulb: The package can be safely required on PHP 5.4 to current in combination with PHPUnit 4.8.36/5.7.21 to current.
>
> When the PHPUnit `assertArraySubset()` method is natively available (PHPUnit 4.x - 8.x), the PHPUnit native functionality will be used.
> For PHPUnit 9 and higher, the extension will kick in and polyfill the functionality which was removed from PHPUnit.
>
> Note: PHPUnit 8.x will show deprecation notices about the use of the `assertArraySubset()` method.
> With this extension in place, those can be safely ignored.
> When the PHPUnit `assertArraySubset()` method is natively available and not deprecated (PHPUnit 4.x - 7.x),
> the PHPUnit native functionality will be used.
> For PHPUnit 8 and higher, the extension will kick in and polyfill the functionality which was removed from PHPUnit.

## Usage
48 changes: 37 additions & 11 deletions assertarraysubset-autoload.php
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@

namespace DMS\PHPUnitExtensions\ArraySubset;

use PHPUnit\Runner\Version as PHPUnit_Version;
use PHPUnit_Runner_Version;

if (\class_exists('DMS\PHPUnitExtensions\ArraySubset\Autoload', false) === false) {

/**
@@ -25,49 +28,51 @@ public static function load($className)
return false;
}

$loadPolyfill = \version_compare(self::getPHPUnitVersion(), '8.0.0', '>=');

switch ($className) {
case 'DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts':
if (\method_exists('\PHPUnit\Framework\Assert', 'assertArraySubset') === false) {
// PHPUnit >= 9.0.0.
if ($loadPolyfill === true) {
// PHPUnit >= 8.0.0.
require_once __DIR__ . '/src/ArraySubsetAsserts.php';

return true;
}

// PHPUnit < 9.0.0.
// PHPUnit < 8.0.0.
require_once __DIR__ . '/src/ArraySubsetAssertsEmpty.php';

return true;

case 'DMS\PHPUnitExtensions\ArraySubset\Assert':
if (\method_exists('\PHPUnit\Framework\Assert', 'assertArraySubset') === false) {
// PHPUnit >= 9.0.0.
if ($loadPolyfill === true) {
// PHPUnit >= 8.0.0.
require_once __DIR__ . '/src/Assert.php';

return true;
}

// PHPUnit < 9.0.0.
// PHPUnit < 8.0.0.
require_once __DIR__ . '/src/AssertFallThrough.php';

return true;

/*
* Handle arbitrary additional classes via PSR-4, but only allow loading on PHPUnit >= 9.0.0,
* as additional classes should only ever _need_ to be loaded when using PHPUnit >= 9.0.0.
* Handle arbitrary additional classes via PSR-4, but only allow loading on PHPUnit >= 8.0.0,
* as additional classes should only ever _need_ to be loaded when using PHPUnit >= 8.0.0.
*/
default:
if (\method_exists('\PHPUnit\Framework\Assert', 'assertArraySubset') === true) {
if ($loadPolyfill === false) {
// PHPUnit < 9.0.0.
throw new \RuntimeException(
\sprintf(
'Using class "%s" is only supported in combination with PHPUnit >= 9.0.0',
'Using class "%s" is only supported in combination with PHPUnit >= 8.0.0',
$className
)
);
}

// PHPUnit >= 9.0.0.
// PHPUnit >= 8.0.0.
$file = \realpath(
__DIR__ . \DIRECTORY_SEPARATOR
. 'src' . \DIRECTORY_SEPARATOR
@@ -83,6 +88,27 @@ public static function load($className)

return false;
}

/**
* Retrieve the PHPUnit version id.
*
* As both the pre-PHPUnit 6 class, as well as the PHPUnit 6+ class contain the `id()` function,
* this should work independently of whether or not another library may have aliased the class.
*
* @return string Version number as a string.
*/
public static function getPHPUnitVersion()
{
if (\class_exists('\PHPUnit\Runner\Version')) {
return PHPUnit_Version::id();
}

if (\class_exists('\PHPUnit_Runner_Version')) {
return PHPUnit_Runner_Version::id();
}

return '0';
}
}

\spl_autoload_register(__NAMESPACE__ . '\Autoload::load');
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"description": "This package provides ArraySubset and related asserts once deprecated in PHPUnit 8",
"type": "library",
"require": {
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
"php": "^5.4 || ^7.0 || ^8.0"
},
"license": "MIT",
@@ -14,8 +14,7 @@
}
],
"require-dev": {
"squizlabs/php_codesniffer": "^3.4",
"dms/coding-standard": "^8"
"dms/coding-standard": "^9"
},
"autoload": {
"files": ["assertarraysubset-autoload.php"]
@@ -24,5 +23,10 @@
"psr-4": {
"DMS\\PHPUnitExtensions\\ArraySubset\\Tests\\": "tests"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
Loading