amphp / phpunit-util

Helper package to ease testing with PHPUnit.
MIT License
21 stars 8 forks source link

Stop event loop if exception is thrown from test #9

Closed trowski closed 3 years ago

trowski commented 4 years ago

If the test method throws an exception or the promise returned from the test method fails, the loop is automatically stopped after 1 second and the test is failed, noting that the loop continued to run.

@kelunik Thoughts?

Fixes #8.

prolic commented 4 years ago

@kelunik @trowski I need this here merged and released. I work against this issue-8 branch for now. Thanks!

prolic commented 4 years ago

I tried this branch and I have a problem with it: Tests fail when an expected exception is thrown with something like this: An exception was thrown from the test method or promise returned from test method failed, but the event loop continued to run; Prooph\EventStore\Exception\StreamDeleted: Stream 'should_fail_appending_with_stream_exists_exp_ver_to_soft_deleted_stream' is deleted

trowski commented 4 years ago

@prolic That's because the loop is continuing to run after the test method throws (or promise fails). In other words, you still have active watchers in the loop after throwing.

trowski commented 4 years ago

We could also release it as 2.0.

@kelunik Yeah, let's do that. I pushed a new commit that fails any test if the loop continues to run after resolving. If we're going to go with another major, that would be even better I think. A test will explicitly have to allow the loop to continue running after resolving using AsyncTestCase::setTimeout().

In the meantime I'm going to tag a 1.3 that supports PHPUnit 9.

enumag commented 4 years ago

@kelunik @trowski Just ran into this problem as well. Took me quite a while to realize there was an exception which was hidden and the timeout exception was shown instead. Can this be merged?