Skip to content

Commit

Permalink
✨ Add ability to assert Visit Path
Browse files Browse the repository at this point in the history
* ✨ Add ability to assert Visit Path

* ✨ Add ability to assert Visit Path

* Lint
  • Loading branch information
robertmarney authored Sep 13, 2024
1 parent 6a6348c commit 63ba0f8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/Actions/MockActionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,17 @@ public function assertPush(string $message = ''): self
/**
* Asserts the handle response is of type "visit".
*
* @param string $message
* @param string|null $path
* @param array $options
* @return $this
*/
public function assertVisit(string $message = ''): self
public function assertVisit(string $path = '', array $options = []): self
{
return $this->assertResponseType('visit', $message);
if (blank($path)) {
return $this->assertResponseType('visit');
}

return $this->assertResponseContainsArray(['path' => $path, 'options' => array_values($options)], 'visit');
}

/**
Expand Down Expand Up @@ -142,6 +147,20 @@ private function assertResponseContains(string $contents, string $type, string $
return $this;
}

private function assertResponseContainsArray(array $contents, string $type, string $message = ''): self
{
PHPUnit::assertThat(
$this->response[$type] ?? '',
PHPUnit::logicalAnd(
PHPUnit::logicalNot(PHPUnit::isEmpty()),
PHPUnit::equalTo($contents)
),
$message
);

return $this;
}

/**
* Asserts the handle response is a "message" and contains the given text.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/Actions/MockActionResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,26 @@ public function testItSucceedsOnVisitResponse()
$mockActionResponse->assertVisit();
}

public function testItSucceedsOnVisitResponseWithPath()
{
$mockActionResponse = new MockActionResponse(Action::visit('/test/path'));
$mockActionResponse->assertVisit('/test/path');
}

public function testItFailsOnResponseOtherThanVisit()
{
$this->shouldFail();
$mockActionResponse = new MockActionResponse(Action::message('test'));
$mockActionResponse->assertVisit();
}

public function testItFailsOnVisitResponseWithPathIncorrect()
{
$this->shouldFail();
$mockActionResponse = new MockActionResponse(Action::visit('/test/path'));
$mockActionResponse->assertVisit('/test/wrongpath');
}

public function testItSucceedsOnDownloadResponse()
{
$mockActionResponse = new MockActionResponse(Action::download('test', 'test'));
Expand Down

0 comments on commit 63ba0f8

Please sign in to comment.