Codeception / AssertThrows

Assert exception handling without stopping a test. For PHPUnit 6+
MIT License
19 stars 10 forks source link

assertThrows raise an exception about mismatching messages #4

Closed askobara closed 5 years ago

askobara commented 6 years ago

There is an example to reproduce:

$this->assertThrows(Exception::class, function () {
    throw new Exception('an exception');
});

exception message '' was expected, but 'an exception' was received

wmathes commented 6 years ago

confirmed. Your fix is valid :) Was about to send a similar PR.

ppetpadriew commented 6 years ago

Confirmed. Facing the same problem here. I will use old version of specify package which does not use this package while this PR is waiting for merge.

kagje commented 6 years ago

Accepting this PR would really be appreciated!

wmathes commented 6 years ago

@DavertMik please have a look at this.

Solomonic commented 6 years ago

Confirmed! Running into the very same issue. Will be fixed with the proposed PR.

cyberhck commented 6 years ago

Confirmed, please have a look soon, it's already been quite long when PR is already available.

z3niths commented 6 years ago

@DavertMik @diego-vieira

                  🐞 
             🐝 🐝 🐝 
       🐝 🐝 🐝 🐝 🐝 
  🐝 🐝 🐝 🐝 🐝 🐝 🐝 
Lewke commented 6 years ago

Waiting for this PR too...

theoc31 commented 6 years ago

Confirmed as well! Please can we get this PR merged asap. This is becoming a roadblock in our team flow 😞

barthy-koeln commented 6 years ago

In the meantime, I wrapped all the assertion stuff in a try-catch block like the following:

$this->it(
    "throws an exception",
    function () {
        $this->assertThrows(
            \InvalidArgumentException::class,
            function () {
                try {
                    $this->unitUnderTest->functionUnderTest($param);
                } catch (\InvalidArgumentException $e) {
                     throw new \InvalidArgumentException();
                }
            }
        );
    }
);

This just strips the message from the exception. It's ugly and shouldn't be needed, but it does the trick until the PR is merged.

ddinchev commented 5 years ago

@DavertMik is there a reason this issue is neglected? If the library is no longer maintained, wouldn't it make sense to say so in the README?