Skip to content

Commit

Permalink
PHPUnit 10 breaks error_get_last()
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed Jun 26, 2023
1 parent 70ace0e commit b3d9366
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 2 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test

on:
push:

jobs:
run-tests:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ['8.2']
phpunit: ['9', '10']

name: "PHP ${{ matrix.php }} with PHPUnit ${{ matrix.phpunit }}"

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

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

- name: Dump autoload
run: composer du

- name: Run tests
run: phpunit
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Bug Report Reproduction Scenarios

This repository contains reproduction scenarios for various bugs I've found and reported.
## PHPUnit 10 break error_get_last()

There's nothing of significance in the `main` branch, but for each (open) bug report, there will be a separate branch which can be checked out to reproduce the specific issue reported.
### Description

See issue https://github.com/sebastianbergmann/phpunit/issues/5428


### How to reproduce

* Check out this branch
* Run `composer install`
* Run `vendor/bin/phpunit`

Or have a look at the GitHub Actions output for this branch: https://github.com/jrfnl/bug-report-reproduction-scenarios/actions
18 changes: 18 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "jrfnl/phpunit-5428",
"description": "Testing",
"license": "MIT",
"require-dev": {
"phpunit/phpunit": "^9.3 || ^10.1"
},
"autoload": {
"psr-4": {
"Jrf\\PHPUnit10\\Scenario\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Jrf\\PHPUnit10\\Scenario\\Tests\\": "tests/"
}
}
}
16 changes: 16 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
bootstrap="vendor/autoload.php"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
>
<testsuites>
<testsuite name="POC">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
</phpunit>
31 changes: 31 additions & 0 deletions src/Foo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Jrf\PHPUnit10\Scenario;

use Exception;

class Foo
{
/**
* Real world example.
*/
public function methodA($fileName)
{
$stream_handle = @fopen($fileName, 'wb');
if ($stream_handle === false) {
$error = error_get_last();
throw new Exception($error['message']);
}

return $stream_handle;
}

/**
* Minimal test case.
*/
public function methodB()
{
@trigger_error('Triggering', E_USER_WARNING);
return error_get_last();
}
}
24 changes: 24 additions & 0 deletions tests/FooTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Jrf\PHPUnit10\Scenario\Tests;

use Exception;
use Jrf\PHPUnit10\Scenario\Foo;
use PHPUnit\Framework\TestCase;

class FooTest extends TestCase
{

public function testMethodA() {
$fileName = tempnam(sys_get_temp_dir(), 'RLT') . '/missing/directory';

$this->expectException(Exception::class);
$this->expectExceptionMessage('Failed to open stream');

(new Foo)->methodA($fileName);
}

public function testMethodB() {
$this->assertSame('Triggering', (new Foo)->methodB()['message']);
}
}

0 comments on commit b3d9366

Please sign in to comment.