Expected Exception should support string codes #244

Closed
cbandy opened this Issue May 8, 2011 · 4 comments

2 participants

@cbandy

Exceptions can return any type from getCode(), specifically PDOException::getCode() returns a string.

PHPUnit_Framework_TestCase should not restrict exception codes to integers.

@edorian
Collaborator

This works with PHP 3.6.2 so i consider the issue solved. Let me know if it doesn't work out for you

<?php

class FiddleTest extends PHPUnit_Framework_TestCase {

    /** 
     * @expectedException MyException
     * @expectedExceptionCode BOB
     */
    public function testContains() {
        throw new MyException;
    }   

}

class MyException extends Exception {

    public function __construct() {
        $this->code = 'BOB';
    }   

}
@edorian edorian closed this Nov 10, 2011
@edorian edorian reopened this Nov 10, 2011
@edorian
Collaborator

The assertion is only made if it is an integer. Ok. I should have also tried to produce a failure. Point taken. I'll solve this later

@cbandy

It may also be worthwhile testing codes prefixed with numerals, such as '25P01', since the Exception class handles them differently than non-numeric strings.

kohana/core@fb23e91

@edorian edorian added a commit that referenced this issue Nov 10, 2011
@edorian edorian Regression test for #244 266a6fe
@edorian edorian closed this in bcf5245 Nov 10, 2011
@greglamb greglamb pushed a commit to greglamb/phpunit that referenced this issue Apr 19, 2013
@edorian edorian Testcase addition related to #244 - ExceptionCode may be a string 68a67fb
@greglamb greglamb pushed a commit to greglamb/phpunit that referenced this issue Apr 19, 2013
@edorian edorian Regression test for #244 01dd2f1
@greglamb greglamb pushed a commit to greglamb/phpunit that referenced this issue Apr 19, 2013
@edorian edorian Fixes #244 by allowing string exception codes eaf2b3a
@greglamb greglamb pushed a commit to greglamb/phpunit that referenced this issue Apr 19, 2013
@edorian edorian Added some more regression tests for #244 e1399ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment