Skip to content

Commit

Permalink
feat: add assertFaulty assertion (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelstolt authored Jul 24, 2024
1 parent 0625e55 commit f727837
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CreateUserCommandTest extends KernelTestCase
// test command throws exception
$this->consoleCommand(CreateUserCommand::class)
->expectException(\RuntimeException::class, 'Username required!')
->assertStatusCode(1)
->assertStatusCode(1) // equivalent to ->assertFaulty()
->assertOutputContains('Could not create user!') // can still make assertions on output before exception was thrown
;

Expand Down
7 changes: 7 additions & 0 deletions src/CommandResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public function assertSuccessful(): self
return $this->assertStatusCode(0);
}

public function assertFaulty(): self
{
Assert::that($this->statusCode() > 0);

return $this;
}

public function assertStatusCode(int $expected): self
{
Assert::that($this->statusCode())->is($expected);
Expand Down
1 change: 1 addition & 0 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public function can_expect_exception(): void
->expectException(\RuntimeException::class, 'Exception thrown!')
->execute()
->assertStatusCode(1)
->assertFaulty()
->assertOutputContains('Executing command...')
->assertOutputContains('Error output.')
;
Expand Down

0 comments on commit f727837

Please sign in to comment.