PHP code example of doppiogancio / mocked-symfony-client
1. Go to this page and download the library: Download doppiogancio/mocked-symfony-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
doppiogancio / mocked-symfony-client example snippets
namespace DoppioGancio\MockedSymfonyClient\Tests;
use DoppioGancio\MockedSymfonyClient\MockedClient;
use PHPUnit\Framework\TestCase;
class RealExampleTest extends TestCase
{
private MockedClient $jsonPlaceHolderClient;
private MockedClient $dummyJsonClient;
protected function setUp(): void
{
parent::setUp();
$this->injectJsonPlaceHolderClient();
$this->injectDummyJsonClient();
}
public function testGetUserByJsonPlaceHolderApi(): void
{
$response = $this->jsonPlaceHolderClient->request('GET', '/user/1');
self::assertEquals(200, $response->getStatusCode());
$user = $response->toArray();
self::assertEquals('Leanne Graham', $user['name']);
}
private function injectJsonPlaceHolderClient(): void
{
$client = new MockedClient([
'base_uri' => [
'https://jsonplaceholder.typicode.com',
],
]);
$this->jsonPlaceHolderClient = $client;
}
private function injectDummyJsonClient(): void
{
$client = new MockedClient([
'base_uri' => [
'https://dummyjson.com',
],
]);
$this->dummyJsonClient = $client;
}
}