Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new assertion messageContains to CatchException. #321

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Enhancements:
* [ORM] Added support for count query with `DISTINCT` in PostgreSQL dialect.
* [Utilities] `Strings::EMPTY_STRING` is deprecated in favour of `Strings::EMPTY`.
* [Core] `Bootstrap::withErrorHandler(ErroraHandler $errorHandler)` set custom error handler which is registered on `Bootstrap::runApplication()`.
* [Tests] Added new assertion `messageContains` to `CatchException`.

Release 2.0.0
--------
Expand Down
7 changes: 7 additions & 0 deletions src/Ouzo/Goodies/Tests/CatchExceptionAssert.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public function hasCode(int $code): CatchExceptionAssert
return $this;
}

public function messageContains(string $messagePart): CatchExceptionAssert
{
$this->validateExceptionThrown();
AssertAdapter::assertContains($messagePart, $this->exception->getMessage());
return $this;
}

private function validateExceptionThrown(): void
{
if (!$this->exception) {
Expand Down
15 changes: 14 additions & 1 deletion test/src/Ouzo/Goodies/Tests/CatchExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function shouldNotCatchException()
}

#[Test]
public function shouldCheckIsMessageContains()
public function shouldCheckMessageIsEqualTo()
{
//given
$object = new MyClass();
Expand All @@ -61,6 +61,19 @@ public function shouldCheckIsMessageContains()
CatchException::assertThat()->hasMessage('Fatal error');
}

#[Test]
public function shouldCheckMessageContains()
{
//given
$object = new MyClass();

//when
CatchException::when($object)->someMethodThatThrowsException();

//then
CatchException::assertThat()->messageContains('tal err');
}

#[Test]
public function getShouldReturnException()
{
Expand Down
Loading