Skip to content

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

@jakobmats

Description

@jakobmats

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions