8000 [Bug]: Nothing is displayed if AfterAll throws an error · Issue #1364 · pestphp/pest · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Bug]: Nothing is displayed if AfterAll throws an error #1364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Nolikein opened this issue Mar 4, 2025 · 0 comments
Open

[Bug]: Nothing is displayed if AfterAll throws an error #1364

Nolikein opened this issue Mar 4, 2025 · 0 comments
Labels

Comments

@Nolikein
Copy link
Nolikein commented Mar 4, 2025

Good morning,

OS (Docker)

Linux under Docker (base image : ubuntu:22.04)
Xdebug enabled.

Versions

PHP : 8.3.17
Pest : 3.7.4
Collision : 8.6.1

What Happened

Short story

When a TypeError is thrown inside the afterAll hook, nothing is displayed but the process return as well as expected the error code 2. We cannot determine the error caused since no message is displayed.

Long story

My repository is private, but i can tell you the story. It may concern Pest or Collision, but i had a problem in the AfterAll() hook. I work in my tests with php resources, so i created a static service to open and get then manually close all the created resources by calling a flush() method inside the afterAll hook. Apparently, some of the resources was already closed when calling fclose() so i got a TypeError without knowing it because all the tests passed. In Pest, this means having an "ErroredEvents", this also blocked my "code coverage", and Pest return in the shell an exit code 2 that is blocking in my CI/CD.

In order to determine the error, I had to go in the vendor / Pest code to dump the error that is called "ErroredEvents" but that is not displayed.

As examples, here is how i dumped the errors :

See vendor/pestphp/pest/src/Kernel.php

// Method handle()
// Code begin from line 114
$result = Facade::result();

$result->hasTestErroredEvents();
$result->numberOfTestErroredEvents();
$result->testErroredEvents();

The same thing can be find in the vendor/nunomaduro/collision/src/Adapters/Phpunit/Style.php file where the writeRecap() method was the perfect place for me to display these errors without denaturing the rest of the code.

How to Reproduce

Inside the AfterAll() hook, open a resource with tmpfile(), then close it two times with fclose() in order to get my php error.

All the tests will pass, but the shell will return an exit code 2.

Sample Repository

No response

Pest Version

3.7.4

PHP Version

8.3.17

Operation System

Linux

Notes

How to solve the problem ?

I need your expertise. I cannot do what is wrote in the CONTRIBUTING.md file because i need to have your expertise. What is the best thing to do about these errors ? How to improve Pest, by displaying or is there another way to catch these errors ?

Here is what i have done, which is rudimentary but it works without denaturing the rest of the code :
See vendor/nunomaduro/collision/src/Adapters/Phpunit/Style.php line 246

        if ($result->hasTestErroredEvents()) {
            $this->output->writeln([
                '',
                sprintf(
                    '  <fg=red>The %s test thrown %d error(s)</>',
                    $state->testCaseName,
                    $result->numberOfTestErroredEvents(),
                ),
            ]);

            foreach ($result->testErroredEvents() as $errored) {
                $this->writeError($errored->throwable());
            }
        }
@Nolikein Nolikein added the bug label Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant
0