xp-framework/rfc

@expect withMessage

thekid opened this issue · 0 comments

Scope of Change

The @expect annotation will be enhanced to provide a means for
also checking the expected exception's message.

Rationale

Ensuring a certain exception message requires the "old-style" approach
with try, fail(); and the checking the message inside
catch (ExpectedException $expected), a construct we successfully
removed the need for with @expect years ago.

Functionality

The @expect annotation is currently written as:

  @expect([CLASSNAME])

Keeping the old syntax intact, the new form is defined as:

  @expect(class= [CLASSNAME], withMessage= [MESSAGE])

This test succeeds:

<?php
  #[@test, @expect(class= 'lang.IllegalArgumentException', withMessage= 'Hello')]
  public function wrongMessage() {
    throw new IllegalArgumentException('Hello');
  }
?>

This test fails:

<?php
  #[@test, @expect(class= 'lang.IllegalArgumentException', withMessage= 'Hello')]
  public function wrongMessage() {
    throw new IllegalArgumentException('Another message');
  }
?>

Security considerations

n/a

Speed impact

Negligible

Dependencies

n/a

Related documents