Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MangoPay API PHPUnit mock
<?php
namespace Lrqdo\Tests;
use MangoPay\ApiWallets;
use MangoPay\MangoPayApi;
use MangoPay\Money;
use MangoPay\Wallet;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class MyTest extends WebTestCase
{
private $mangoPayApi;
private $webClient;
protected function setUp()
{
$this->mangoPayApi = $this->createMock(MangoPayApi::class);
$this->mangoPayApi->Wallets = $this->createMock(ApiWallets::class);
$this->webClient = static::createClient();
$container = $this->webClient->getContainer();
// replace the SDK by the mock
$container->set('mangopay.api', $this->mangoPayApi);
}
/**
* @test
*/
public function it_returns_balance_of_authenticated_user()
{
$this->mangoPayApi->Wallets
->expects($this->once())
->willReturn($this->createWallet(1000, 'EUR'));
$this->webClient->request(
// custom HTTP request on the route we want to test
);
$response = json_decode($this->webClient->getResponse()->getContent(), true);
$this->assertEquals(1000, $response['balance']['amount']);
}
private function createWallet($amount, $currency)
{
$wallet = new Wallet();
$wallet->Balance = new Money();
$wallet->Balance->Amount = $amount;
$wallet->Balance->Currency = $currency;
return $wallet;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment