Skip to content

AssertClosedResource: improve error messages#65

Merged
jrfnl merged 1 commit into
developfrom
feature/assertclosedresource-improve-error-message
Nov 11, 2021
Merged

AssertClosedResource: improve error messages#65
jrfnl merged 1 commit into
developfrom
feature/assertclosedresource-improve-error-message

Conversation

@jrfnl

@jrfnl jrfnl commented Nov 11, 2021

Copy link
Copy Markdown
Collaborator

The sebastian/exporter package has been a dependency of PHPUnit from before PHPUnit 4.8.x (minimum supported version by this library), so it is safe to use the same variable export methodology as PHPUnit itself uses.

The class is prefixed via PHP_Scoper when it is includes as part of a PHPUnit Phar file and the toggle added will make sure the class can be loaded both when run via a Composer install, as well as when run via a Phar file.

Also note that the Exporter reports closed resources as NULL. This has been reported upstream via sebastianbergmann/exporter#36 and for the polyfill a fix has been put in place to work around this.

Props to @schlessera for the feedback leading to this improvement.

Important:
While the sebastian/exporter package has, in effect, now become a direct dependency of the Polyfills, I'm not going to declare it as such in the composer.json file as for all supported PHPUnit versions, the package will already be available via PHPUnit itself, whether installed via Composer or as a PHAR.
This prevent potential version conflicts when tests are run via the PHAR, while the Polyfills have been installed via Composer and saves hassle of having to take care of autoloading the Exporter file, while it will be loaded for PHPUnit itself anyway.

If at some point in the future, PHPUnit would no longer require the Exporter package as a dependency, this should be re-evaluated.

The `sebastian/exporter` package has been a dependency of PHPUnit from before PHPUnit 4.8.x (minimum supported version by this library), so it is safe to use the same variable export methodology as PHPUnit itself uses.

The class is prefixed via PHP_Scoper when it is includes as part of a PHPUnit Phar file and the toggle added will make sure the class can be loaded both when run via a Composer install, as well as when run via a Phar file.

Also note that the Exporter reports closed resources as `NULL`. This has been reported upstream via sebastianbergmann/exporter#36 and for the polyfill a fix has been put in place to work around this.

**Important**:
While the `sebastian/exporter` package has , in effect, now become a direct dependency of the Polyfills, I'm not going to declare it as such in the `composer.json` file as for all supported PHPUnit versions, the package will already be available via PHPUnit itself, whether installed via Composer or as a PHAR.
This prevent potential version conflicts when tests are run via the PHAR, while the Polyfills have been installed via Composer and saves hassle of having to take care of autoloading the Exporter file, while it will be loaded for PHPUnit itself anyway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant