ignited / laravel-omnipay

Omnipay for Laravel & Lumen
MIT License
509 stars 100 forks source link

Included options to inject httpClient for omnipay to use Guzzle Plugin #18

Closed Leuloch closed 7 years ago

Leuloch commented 8 years ago

To unable mock response for tests, we need to inject Guzzle\Plugin\Mock\MockPlugin when creating the gateway like so:

class ApplicationTest extends TestCase
{

    public function testOmnipayManager()
    {
        // Create gateway using mocked HttpClient
        $this->gateway = \Omnipay::gateway('pagarme', $this->getHttpClient(), $this->getHttpRequest());

        // Add Expected Response from the API
        $this->setMockHttpResponse('AuthorizeCardSuccess.txt');

        $request = $this->gateway->authorize(
            [
                'amount'           => '10.00',
                'soft_descriptor'  => 'test',
            ]
        );

        $response = $request->send();

        $this->assertTrue($response->isSuccessful());
    }

More info: http://guzzle3.readthedocs.org/testing/unit-testing.html#queueing-mock-responses

@alexw23

alexw23 commented 7 years ago

20 fixes this