Created
April 20, 2017 17:14
-
-
Save nclavaud/6ebfa130bad086623083f83bfe5ed7d6 to your computer and use it in GitHub Desktop.
MangoPay API PHPUnit mock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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