Skip to content

Instantly share code, notes, and snippets.

Created April 20, 2017 17:14
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
MangoPay API PHPUnit mock
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()
->willReturn($this->createWallet(1000, 'EUR'));
// 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