Skip to content

Instantly share code, notes, and snippets.

@nclavaud
Created April 20, 2017 17:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nclavaud/6ebfa130bad086623083f83bfe5ed7d6 to your computer and use it in GitHub Desktop.
Save nclavaud/6ebfa130bad086623083f83bfe5ed7d6 to your computer and use it in GitHub Desktop.
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