<#229 Runing Consumer tests against a real externa...
# pact-php
g
#229 Runing Consumer tests against a real external API Issue created by d-jankovic We are looking to introduce contract tests into our system. Besides testing the interaction of various parts of our system, we want to test the communication of our Laravel API with external services APIs. The issue we ran into is that we cannot run provider side validation of our contracts (since we do not control the provider system), so we decided to run the consumer side test against an external service API sandbox, to validate that the interaction went well (if we mocked the provider, we can't guarantee that the mock is up to date with the service). I tried the approach bellow but it fails on trying to POST to /interactions (on willRespondWith) since endpoint is not found. If I start the mock server and send the request, it won't detect the request sent to the external API. Is there a way to achieve what I am looking to do ? My thinking is either defining interactions without posting them to a mocked server or making our mocked server proxy to the real API. I pasted my test code bellow, I don't think it needs further explanation since it mostly just follows the readme.
Copy code
public function externalServiceGetTest()
    {

        $matcher = new Matcher();

        $request = new ConsumerRequest();
        $request->setMethod('GET')
            ->setPath("/some/path");

        $response = new ProviderResponse();
        $response->setBody($matcher->eachLike(DomainDataStructure::class))
            ->setStatus(200);

        $config = new MockServerConfig();
        $config->setConsumer('Our API')
            ->setProvider('External service sandbox env')
            ->setHost('<https://external.service.sandbox.api>')
            ->setPort(80);

        $builder = new InteractionBuilder($config);
        $builder->uponReceiving('A get request to /some/path')
            ->with($request)
            ->willRespondWith($response);

        $result = $this->ourDomainService->sendRequest('data', 'data', 'data');

        $builder->verify();

        $this->assertWhatever();
    }
pact-foundation/pact-php