Skip to content
This repository was archived by the owner on Nov 19, 2023. It is now read-only.

Conversation

thekid
Copy link
Member

@thekid thekid commented Sep 20, 2020

This pull request implements a new method throws() in the assertion DSL. With it, code along the lines of the following can be rewritten to a more concise form:

Before

use lang\IllegalArgumentException;

class FixtureTest {

  #[@test]
  public function raises_exception() {
    $fixture= ... // Code which could also raise IllegalArgumentExceptions
    try {
      $fixture->test(null);
      $this->fail('No exception raised', null, IllegalArgumentException::class);
    } catch (IllegalArgumentException $expected) {
       // OK
    }
  }
}

After

use lang\IllegalArgumentException;

class FixtureTest {

  #[@test]
  public function raises_exception() {
    $fixture= ... // Code which could also raise IllegalArgumentExceptions
    Assert::throws(IllegalArgumentException::class, function() use($fixture) {
      $fixture->test(null);
    });
  }
}

@thekid thekid merged commit ec532db into master Sep 20, 2020
@thekid thekid deleted the feature/assert-throws branch September 20, 2020 15:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant