Testing Guzzle on bitbucket-pipeline: a step-by-step guide
P粉403804844
P粉403804844 2024-02-17 16:49:46
0
1
482

I wrote some integration tests using Guzzle. I also created a pipeline on bitbucket to run the tests.

$this->client = new Client([
  'base_uri' => "http://{docker_service_name}/api/",
]);
$response = $this->client->request('GET', 'regions');

$this->assertEquals(SELF::STATUS_OK, $response->getStatusCode());

My bitbucket-pipeline.yaml looks similar to this:

image: php:7.1.1
pipelines:
  default:
    - step:
        script:
          - apt-get update && apt-get install -y unzip
          - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
          - composer install
          - vendor/bin/phpunit

The problem is that the pipeline fails with the following error:

GuzzleHttp\Exception\ConnectException: cURL error 7: Failed to connect to docker_service_name port 80: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://{docker_service_name}/api/regions

Looks like the pipeline can't get the hostname, on my local it would be the name of the docker web server, what should I set on the pipeline? Thank you very much in advance

P粉403804844
P粉403804844

reply all(1)
P粉567281015

Please note that the step script is executed in a single docker container. If you need to connect to some other service to run integration tests, you should:

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template