amphp / phpunit-util

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

TestCase::expectException() does not detect exceptions in AsyncTestCase #6

Closed jakobmats closed 5 years ago

jakobmats commented 5 years ago

I'm working on a simple abstraction built on top of http-server for making async APIs and I ran into the following issue - when I try to write a test to assert that an exception is thrown, TestCase::expectException() seems to be unaware of it actually happening. Take a look at this snippet:

<?php
class AwesomeTest extends AsyncTestCase
{
    public function testOhNoes()
    {
        $this->expectException(Error::class);

        yield call(function () {
            throw new Error;
        });
    }

    public function testYay()
    {
        $this->expectException(Error::class);

        throw new Error;
    }
}

And the output from PHPUnit:

1) AwesomeTest::testOhNoes
Error: 
/home/jakobmats/workspace/empress/test/AwesomeTest.php:13
/home/jakobmats/workspace/empress/vendor/amphp/amp/lib/functions.php:60
/home/jakobmats/workspace/empress/test/AwesomeTest.php:14
/home/jakobmats/workspace/empress/vendor/amphp/amp/lib/Coroutine.php:60
/home/jakobmats/workspace/empress/vendor/amphp/amp/lib/functions.php:66
/home/jakobmats/workspace/empress/vendor/amphp/phpunit-util/src/AsyncTestCase.php:23
/home/jakobmats/.config/composer/vendor/phpunit/phpunit/src/TextUI/Command.php:201
/home/jakobmats/.config/composer/vendor/phpunit/phpunit/src/TextUI/Command.php:160

The other test case passes without problems. Any ideas why it happens? As far as I understand it the error should bubble up until it hits the top level so that PHPUnit is supposed to see it, no?

trowski commented 5 years ago

Hi @jakobmats!

I tried reproducing the issue you described, but I'm unable to reproduce it. I added the exact test that you're seeing fail to our tests, but it passes locally and on travis. Could you provide some more context where you're seeing this happen, such as the version of PHP and phpunit you're using?

kelunik commented 5 years ago

Closing due to inactivity and because the issue can't be reproduced.