Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing an integer to the message argument of setExpectedException causes the message matching to always pass #2267

Closed
Bilge opened this issue Aug 14, 2016 · 2 comments
Labels
type/bug Something is broken

Comments

@Bilge
Copy link
Contributor

Bilge commented Aug 14, 2016

PHPUnit 4.8.26

public function testInteger() {
    $this->setExpectedException(Exception::class, 1);

    throw new Exception('2'); // Pass
}

public function testString() {
    $this->setExpectedException(Exception::class, '1');

    throw new Exception('2'); // Failed asserting that exception message '2' contains '1'.
}

I believe the message argument should automatically be typecast to string.

@sebastianbergmann sebastianbergmann added the type/bug Something is broken label Aug 14, 2016
@stevenbitner
Copy link

In PHPUnit 5.4 passing other than a string value for the message will give you the following failure:
PHPUnit_Framework_Exception: Argument #1 (No Value) of PHPUnit_Framework_TestCase::expectExceptionMessage() must be a string

@leedwilkins
Copy link
Contributor

setExpectedException has been decripcated, in checking expectExceptionCode, expecteExceptionMessage, and expectExceptedMessageRegex I realized that the tests are not run if the string is empty. It was originally using the empty() method, which meant that '0' would also be skipped. I changed it so that only the empty string is skipped, but technically even that should be checked. The problem is that, if it tries to test and empty string many errors/failures occur. This will take some more looking into.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

4 participants