Menu

#34 expectExceptionPattern

open
nobody
None
5
2009-09-22
2009-09-22
No

I may be wrong, but there's no way to expect an exception whose message matches a regular expression pattern. Reading the exception.php source code I found this comment: "This could be improved to accept a pattern expectation to test the error message, but that will have to come later."

Please, find attached 2 patches and a sample UnitTestCase

I didn't use a pattern expectation but an exception object whose message contains a regex pattern. It's not elegant, but it allows the exception type to be tested too.

Discussion

  • Arialdo Martini

    Arialdo Martini - 2009-09-22

    Patch for exceptions. Added ExceptionPatternExpectation

     
  • Arialdo Martini

    Arialdo Martini - 2009-09-22

    Added expectExceptionPattern()

     
  • Arialdo Martini

    Arialdo Martini - 2009-09-22

    A simple UnitCaseTest testing with ExpectExeptionPattern. It requires the sample ThrowException class too

     
  • Arialdo Martini

    Arialdo Martini - 2009-09-22

    A sample class with a method throwing an exception

     

Log in to post a comment.