Skip to content

Commit

Permalink
Merge pull request #68 from Yoast/develop
Browse files Browse the repository at this point in the history
Release version 1.0.3
  • Loading branch information
jrfnl authored Nov 23, 2021
2 parents 1a582ab + a6d09df commit 5ea3536
Show file tree
Hide file tree
Showing 17 changed files with 306 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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:
checkcs:
name: 'Basic CS and QA checks'
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Lint

on:
# Run on all pushes and on all pull requests.
push:
pull_request:
# 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 Code Linting ####
lint:
runs-on: ubuntu-latest

strategy:
matrix:
php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']

name: "Lint: PHP ${{ matrix.php }}"

continue-on-error: ${{ matrix.php == '8.2' }}

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

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: none

- name: 'Composer: remove PHPUnit (not needed for lint)'
run: composer remove phpunit/phpunit --no-update

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies
uses: "ramsey/composer-install@v1"

- name: "Lint PHP files against parse errors - PHP < 7.0"
if: ${{ matrix.php < 7.0 }}
run: composer lint-lt70

- name: "Lint PHP files against parse errors - PHP 7.x"
if: ${{ startsWith( matrix.php, '7' ) }}
run: composer lint7

- name: "Lint PHP files against parse errors - PHP >= 8.0"
if: ${{ matrix.php >= 8.0 }}
run: composer lint-gte80
20 changes: 7 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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:
#### TEST STAGE ####
test:
Expand Down Expand Up @@ -71,7 +77,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: error_reporting=E_ALL, display_errors=On
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: none

- name: 'Composer: set PHPUnit version for tests'
Expand All @@ -91,18 +97,6 @@ jobs:
with:
composer-options: --ignore-platform-reqs

- name: "Lint PHP files against parse errors - PHP < 7.0"
if: ${{ matrix.phpunit == 'auto' && matrix.php < 7.0 }}
run: composer lint-lt70

- name: "Lint PHP files against parse errors - PHP 7.x"
if: ${{ matrix.phpunit == 'auto' && startsWith( matrix.php, '7' ) }}
run: composer lint7

- name: "Lint PHP files against parse errors - PHP >= 8.0"
if: ${{ matrix.phpunit == 'auto' && matrix.php >= 8.0 }}
run: composer lint-gte80

- name: Run the unit tests
if: ${{ matrix.phpunit != '^10.0' }}
run: composer test
Expand Down
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ This projects adheres to [Keep a CHANGELOG](http://keepachangelog.com/) and uses

_Nothing yet._

## [1.0.3] - 2021-11-23

### Changed
* General housekeeping.

### Fixed
* The failure message thrown for the `assertIsClosedResource()` and `assertIsNotClosedResource()` assertions will now be more informative, most notably, when the value under test _is_ a closed resource. PR [#65], props [Alain Schlesser] for reporting.

[#65]: https://github.com/Yoast/PHPUnit-Polyfills/pull/65


## [1.0.2] - 2021-10-03

As of version 2.15.0 of the `shivammathur/setup-php` action for GitHub Actions, the PHPUnit Polyfills can be installed directly from this action using the `tools` key.
Expand All @@ -17,7 +28,7 @@ As of version 2.15.0 of the `shivammathur/setup-php` action for GitHub Actions,
* README: FAQ section about installing and using the library via the `shivammathur/setup-php` action. PR [#52]

### Changed
* README: minor textual clarifications and improvements. PRs [#52], [$54], props [Pierre Gordon].
* README: minor textual clarifications and improvements. PRs [#52], [#54], props [Pierre Gordon].
* General housekeeping.

### Fixed
Expand Down Expand Up @@ -100,15 +111,16 @@ Initial release.


[Unreleased]: https://github.com/Yoast/PHPUnit-Polyfills/compare/main...HEAD
[1.0.3]: https://github.com/Yoast/PHPUnit-Polyfills/compare/1.0.2...1.0.3
[1.0.2]: https://github.com/Yoast/PHPUnit-Polyfills/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/Yoast/PHPUnit-Polyfills/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/Yoast/PHPUnit-Polyfills/compare/0.2.0...1.0.0
[0.2.0]: https://github.com/Yoast/PHPUnit-Polyfills/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/Yoast/PHPUnit-Polyfills/compare/e8f8b7a73737aa9a5974bd9c73d2bd8d09f69873...0.1.0

[Alain Schlesser]: https://github.com/schlessera
[Gary Jones]: https://github.com/GaryJones
[Marc Siegrist]: https://github.com/mergeMarc
[Mark Baker]: https://github.com/MarkBaker
[Pascal Birchler]: https://github.com/swissspidy
[Pierre Gordon]: https://github.com/pierlon

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PHPUnit Polyfills

[![Version](https://poser.pugx.org/yoast/phpunit-polyfills/version)](//packagist.org/packages/yoast/phpunit-polyfills)
[![CS Build Status](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/cs.yml/badge.svg)](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/cs.yml)
[![Lint Build Status](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/lint.yml/badge.svg)](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/lint.yml)
[![Test Build Status](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/test.yml/badge.svg)](https://github.com/Yoast/PHPUnit-Polyfills/actions/workflows/test.yml)
[![Minimum PHP Version](https://img.shields.io/packagist/php-v/yoast/phpunit-polyfills.svg?maxAge=3600)](https://packagist.org/packages/yoast/phpunit-polyfills)
[![License: BSD3](https://poser.pugx.org/yoast/phpunit-polyfills/license)](https://github.com/Yoast/PHPUnit-Polyfills/blob/master/LICENSE)
Expand Down
2 changes: 1 addition & 1 deletion phpunitpolyfills-autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Autoload {
*
* @var string
*/
const VERSION = '1.0.2';
const VERSION = '1.0.3';

/**
* Loads a class.
Expand Down
12 changes: 10 additions & 2 deletions src/Polyfills/AssertClosedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Yoast\PHPUnitPolyfills\Polyfills;

use PHPUnit\SebastianBergmann\Exporter\Exporter as Exporter_In_Phar;
use SebastianBergmann\Exporter\Exporter;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;

/**
Expand All @@ -24,7 +26,8 @@ trait AssertClosedResource {
*/
public static function assertIsClosedResource( $actual, $message = '' ) {
if ( $message === '' ) {
$message = \sprintf( 'Failed asserting that %s is of type "resource (closed)"', \var_export( $actual, true ) );
$exporter = \class_exists( 'SebastianBergmann\Exporter\Exporter' ) ? new Exporter() : new Exporter_In_Phar();
$message = \sprintf( 'Failed asserting that %s is of type "resource (closed)"', $exporter->export( $actual ) );
}

static::assertTrue( ResourceHelper::isClosedResource( $actual ), $message );
Expand All @@ -40,7 +43,12 @@ public static function assertIsClosedResource( $actual, $message = '' ) {
*/
public static function assertIsNotClosedResource( $actual, $message = '' ) {
if ( $message === '' ) {
$message = \sprintf( 'Failed asserting that %s is not of type "resource (closed)"', \var_export( $actual, true ) );
$exporter = \class_exists( 'SebastianBergmann\Exporter\Exporter' ) ? new Exporter() : new Exporter_In_Phar();
$type = $exporter->export( $actual );
if ( $type === 'NULL' ) {
$type = 'resource (closed)';
}
$message = \sprintf( 'Failed asserting that %s is not of type "resource (closed)"', $type );
}

static::assertFalse( ResourceHelper::isClosedResource( $actual ), $message );
Expand Down
8 changes: 6 additions & 2 deletions tests/Polyfills/AssertClosedResourceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ public function isClosedResourceExpectExceptionOnOpenResource( $actual ) {
* @return void
*/
public function isNotClosedResourceExpectExceptionOnClosedResource( $actual ) {
$msg = 'Failed asserting that NULL is not of type "resource (closed)"';
/*
* PHPUnit itself will report closed resources as `NULL` prior to Exporter 3.0.4/4.1.4.
* See: https://github.com/sebastianbergmann/exporter/pull/37
*/
$pattern = '`^Failed asserting that (resource \(closed\)|NULL) is not of type "resource \(closed\)"`';
$exception = 'PHPUnit\Framework\AssertionFailedError';
if ( \class_exists( 'PHPUnit_Framework_AssertionFailedError' ) ) {
// PHPUnit < 6.
$exception = 'PHPUnit_Framework_AssertionFailedError';
}

$this->expectException( $exception );
$this->expectExceptionMessage( $msg );
$this->expectExceptionMessageMatches( $pattern );

self::assertIsNotClosedResource( $actual );
}
Expand Down
22 changes: 22 additions & 0 deletions tests/TestListeners/Fixtures/FailurePHPUnitGte7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Yoast\PHPUnitPolyfills\Tests\TestListeners\Fixtures;

use PHPUnit\Framework\TestCase;

/**
* Fixture to generate a "failed test" to pass to the test listener.
*
* @requires PHPUnit 7.0
*/
class FailurePHPUnitGte7 extends TestCase {

/**
* Test resulting in a failed test.
*
* @return void
*/
protected function testForListener() {
$this->fail();
}
}
22 changes: 22 additions & 0 deletions tests/TestListeners/Fixtures/IncompletePHPUnitGte7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Yoast\PHPUnitPolyfills\Tests\TestListeners\Fixtures;

use PHPUnit\Framework\TestCase;

/**
* Fixture to generate an "incomplete test" to pass to the test listener.
*
* @requires PHPUnit 7.0
*/
class IncompletePHPUnitGte7 extends TestCase {

/**
* Test resulting in a test marked as incomplete.
*
* @return void
*/
protected function testForListener() {
$this->markTestIncomplete( 'Test incomplete' );
}
}
22 changes: 22 additions & 0 deletions tests/TestListeners/Fixtures/RiskyPHPUnitGte7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Yoast\PHPUnitPolyfills\Tests\TestListeners\Fixtures;

use PHPUnit\Framework\TestCase;

/**
* Fixture to generate a "risky test" to pass to the test listener.
*
* @requires PHPUnit 7.0
*/
class RiskyPHPUnitGte7 extends TestCase {

/**
* Test resulting in a test marked as risky.
*
* @return void
*/
protected function testForListener() {
$this->markAsRisky();
}
}
22 changes: 22 additions & 0 deletions tests/TestListeners/Fixtures/SkippedPHPUnitGte7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Yoast\PHPUnitPolyfills\Tests\TestListeners\Fixtures;

use PHPUnit\Framework\TestCase;

/**
* Fixture to generate a "skipped test" to pass to the test listener.
*
* @requires PHPUnit 7.0
*/
class SkippedPHPUnitGte7 extends TestCase {

/**
* Test resulting in a test marked as skipped.
*
* @return void
*/
protected function testForListener() {
$this->markTestSkipped( 'Skipped test' );
}
}
22 changes: 22 additions & 0 deletions tests/TestListeners/Fixtures/SuccessPHPUnitGte7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Yoast\PHPUnitPolyfills\Tests\TestListeners\Fixtures;

use PHPUnit\Framework\TestCase;

/**
* Fixture to generate a "successfull test" to pass to the test listener.
*
* @requires PHPUnit 7.0
*/
class SuccessPHPUnitGte7 extends TestCase {

/**
* Test resulting in a successfull test.
*
* @return void
*/
protected function testForListener() {
$this->assertTrue( true );
}
}
27 changes: 27 additions & 0 deletions tests/TestListeners/Fixtures/TestErrorPHPUnitGte7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Yoast\PHPUnitPolyfills\Tests\TestListeners\Fixtures;

use Exception;
use PHPUnit\Framework\TestCase;

/**
* Fixture to generate a test error to pass to the test listener.
*
* @requires PHPUnit 7.0
*
* @coversNothing
*/
class TestErrorPHPUnitGte7 extends TestCase {

/**
* Test resulting in an error.
*
* @return void
*
* @throws Exception For test purposes.
*/
protected function testForListener() {
throw new Exception();
}
}
25 changes: 25 additions & 0 deletions tests/TestListeners/Fixtures/WarningPHPUnitGte7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Yoast\PHPUnitPolyfills\Tests\TestListeners\Fixtures;

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Warning as PHPUnit_Warning;

/**
* Fixture to generate a test warning to pass to the test listener.
*
* @requires PHPUnit 7.0
*/
class WarningPHPUnitGte7 extends TestCase {

/**
* Test resulting in a warning.
*
* @return void
*
* @throws PHPUnit_Warning For test purposes.
*/
protected function testForListener() {
throw new PHPUnit_Warning();
}
}
Loading

0 comments on commit 5ea3536

Please sign in to comment.