I am using the Braintree PHP Client which relies heavily on static methods. All my endpoints in this project are covered with integration tests Something like:
Storage::shouldReceive('put')->once()->andReturn(true);
$this->post('/api/payment');
As you can see I'm also using Mockery in order to create mocks. However since the Braintree library is heavily relying on static methods, I'm not able to create methods, thus not able to test these endpoints.
Here's an example of a code written using the Braintree PHP Client:
$result = Braintree\Transaction::sale([
'amount' => '1000.00',
'paymentMethodNonce' => 'nonceFromTheClient',
'options' => [ 'submitForSettlement' => true ]
]);
What options do I have here?
this answer will only work if you got mockery 1.*
installed.. earlier versions won't do static method mocking. The below code works:
$brainTreeMock = Mockery::mock('alias:Braintree_Transaction');
$transaction = (object)[ 'id' => str_random(5) ];
$brainTreeMock->shouldReceive('sale')->andReturn((object)[
'success' => true,
'transaction' => $transaction
]
);