Skip to content

Commit

Permalink
Propagate any non-expected exceptions in testing fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Szurovecz committed Jun 9, 2015
1 parent feb869d commit bc22336
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/predaddy/util/test/Fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ private function checkReturnValue()
private function checkThrownException()
{
if ($this->raisedException !== null) {
/* @var $exception Exception */
PHPUnit_Framework_TestCase::assertInstanceOf($this->expectedExceptionClass, $this->raisedException);
if ($this->expectedExceptionMessage !== null) {
PHPUnit_Framework_TestCase::assertEquals(
$this->expectedExceptionMessage,
$this->raisedException->getMessage()
);
if ($this->expectedExceptionClass === null) {
throw $this->raisedException;
}
PHPUnit_Framework_TestCase::assertInstanceOf($this->expectedExceptionClass, $this->raisedException);
PHPUnit_Framework_TestCase::assertEquals(
$this->expectedExceptionMessage,
$this->raisedException->getMessage()
);
}
}

Expand Down
18 changes: 18 additions & 0 deletions tests/src/predaddy/domain/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,22 @@ public function shouldThrowExceptionIfIncrementedThreeTimes()
->when(new Increment())
->expectException('\RuntimeException', 'Cannot be incremented more, than twice');
}

/**
* @test
* @expectedException \RuntimeException
*/
public function shouldThrowNotExpectedException()
{
$fixture = Fixtures::newGivenWhenThenFixture(User::className());
$fixture
->registerAnnotatedCommandHandler(new UserCommandHandler(new InMemoryRepository()))
->givenCommands(
new CreateUser(),
new Increment(),
new Increment()
)
->when(new Increment())
->expectNoEvents();
}
}

0 comments on commit bc22336

Please sign in to comment.