Skip to content

Instantly share code, notes, and snippets.

@yourwebmaker
Created November 6, 2019 15:31
Show Gist options
  • Save yourwebmaker/7f600954d41fa76d3b09921522bb558e to your computer and use it in GitHub Desktop.
Save yourwebmaker/7f600954d41fa76d3b09921522bb558e to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace PHPBrasil\ExemploTest;
use PHPUnit\Framework\TestCase;
class ExemploMockStub extends TestCase
{
public function testExemploComStub() : void
{
$dadosCliente = [];
$httpClientStub = $this->createStub(HttpClient::class);
$clientesApi = new ClientesApi($httpClientStub);
self::assertEquals(201, $clientesApi->save($dadosCliente)->getResponseCode());
}
public function testExemploComMock() : void
{
$dadosCliente = [];
$httpClientMock = $this->createMock(HttpClient::class);
$httpClientMock
->method('post')
->expects($this->once())
->willReturn($objResponse)
;
$clientesApi = new ClientesApi($httpClientMock);
$clientesApi->save($dadosCliente);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment