pest: Not seeing exception when running in PhpStorm
I have a test:
<?php
it('works', function () {
//expect(true)->toBeTrue();
throw new \Exception('watup');
});
When I run this in PhpStorm, I see the following output:
[docker-compose://[/Users/.../docker-compose.yml]:web/]:php /var/www/html/vendor/pestphp/pest/bin/pest --teamcity /var/www/html/tests/Feature/ExampleTest.php
This test did not perform any assertions
Tests: 1 failed (0 assertions)
Duration: 0.47s
Process finished with exit code 2
When I do an assertion (uncomment the line: expect(true)->toBeTrue();
), then I do see the exception.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (11 by maintainers)
@olivernybroe Thank you for your valuable hints.
I think I found a way to fix the issues and reflect this within the tests.
cc @nunomaduro
I digged deeper into this issue and it seems to be a tricky one. My findings so far:
The problem is definitively related to a change in PHPUnit in the latest version (10.1.2). Before this change a test throwing an exception only triggered a
PHPUnit\Event\Test\Errored
event. But now it also triggers aPHPUnit\Event\Test\ConsideredRisky
event in case if the test did not any assertions before the exception was thrown.This is also visible in the default output of PHPUnit: Test
Output PHPUnit 10.1.1
Output PHPUnit 10.1.2
Having this extra
ConsideredRisky
event we have two issues in the Teamcity output:https://github.com/pestphp/pest/blob/2.x/src/Logging/TeamCity/Converter.php#L191
To be honest I am not sure how to proceed here. My thoughts so far:
Maybe triggering the two events for the same test is not intended in PHPUnit and it is a bug on their end, but I don’t think so.
If we want to fix this on the Pest side we have to calculate the number of successful tests differently by checking every event if there is another event for the same test. This seems doable to me.
For the second problem we would have to store all the events instead of writing them to the output directly and then filter them to only pass the most important event to the output. But this looks like a massive change compared to the current behaviour and I would like to hear your thought before continuing.
Last but not least it would also be possible that the second problem is on PHPStorm side and they should show two or more messages for the same test. I am not familiar with the TeamCity specifications.
@nunomaduro @olivernybroe
The issue comes from this file: https://github.com/pestphp/pest/blob/2.x/src/Logging/TeamCity/TeamCityLogger.php.