Skip to content

Commit

Permalink
Merge pull request #32407 from christophrumpel/feature/addRequestCoun…
Browse files Browse the repository at this point in the history
…tAssertion

[7.x] Add assertSentCount HTTP client assertion
  • Loading branch information
taylorotwell authored Apr 16, 2020
2 parents 92e6cce + 3343c33 commit b92e27d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Illuminate/Http/Client/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ public function assertNothingSent()
);
}

/**
* Assert how many requests have been recorded.
*
* @param $count
* @return void
*/
public function assertSentCount($count)
{
PHPUnit::assertCount($count, $this->recorded);
}

/**
* Assert that every created response sequence is empty.
*
Expand Down
18 changes: 18 additions & 0 deletions tests/Http/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ public function testNoRequestIsNotBeingSent()
$this->factory->assertNothingSent();
}

public function testRequestCount()
{
$this->factory->fake();
$this->factory->assertSentCount(0);

$this->factory->post('http://foo.com/form', [
'name' => 'Taylor',
]);

$this->factory->assertSentCount(1);

$this->factory->post('http://foo.com/form', [
'name' => 'Jim',
]);

$this->factory->assertSentCount(2);
}

public function testCanSendMultipartData()
{
$this->factory->fake();
Expand Down

0 comments on commit b92e27d

Please sign in to comment.