Skip to content

Commit

Permalink
Add StubPostRequestSenderTest
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Jan 30, 2022
1 parent 6bb9373 commit 534c8cb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/SpyPostRequestSenderTest.php
Expand Up @@ -17,7 +17,7 @@
class SpyPostRequestSenderTest extends TestCase {

public function testGetCalls(): void {
$spy = new SpyPostRequestSender( new StubPostRequestSender( ) );
$spy = new SpyPostRequestSender( new StubPostRequestSender() );

$spy->post( 'http://first.url', [ 'foo' => 'bar' ] );
$spy->post( 'http://second.url', [ 'baz' => 'bah', 'pew' => 1337 ] );
Expand Down
52 changes: 52 additions & 0 deletions tests/StubPostRequestSenderTest.php
@@ -0,0 +1,52 @@
<?php

declare( strict_types = 1 );

namespace Jeroen\PostRequestSender\Tests;

use Jeroen\PostRequestSender\StubPostRequestSender;
use Jeroen\PostRequestSender\TestResponse;
use PHPUnit\Framework\TestCase;

/**
* @covers \Jeroen\PostRequestSender\StubPostRequestSender
* @covers \Jeroen\PostRequestSender\PostRequest
* @covers \Jeroen\PostRequestSender\TestResponse
*/
class StubPostRequestSenderTest extends TestCase {

public function testDefaultResponse(): void {
$stubSender = new StubPostRequestSender();

$response = $stubSender->post( 'https://example.com', [ 'foo' => 'bar' ] );

$this->assertSame(
'',
$response->getBody()->getContents()
);

$this->assertSame(
200,
$response->getStatusCode()
);
}

public function testAlternativeResponse(): void {
$stubSender = new StubPostRequestSender(
new TestResponse( 'TestBody', 418 )
);

$response = $stubSender->post( 'https://example.com', [ 'foo' => 'bar' ] );

$this->assertSame(
'TestBody',
$response->getBody()->getContents()
);

$this->assertSame(
418,
$response->getStatusCode()
);
}

}

0 comments on commit 534c8cb

Please sign in to comment.