在 bitbucket-pipeline 上測試 Guzzle:逐步指南
P粉403804844
P粉403804844 2024-02-17 16:49:46
0
1
439

我使用 Guzzle 編寫了一些整合測試。 我還在 bitbucket 上建立了一個運行測試的管道。

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

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

我的 bitbucket-pipeline.yaml 看起來與此類似:

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

問題是管道因以下錯誤而失敗:

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

看起來管道無法取得主機名,在我的本地它將是 docker web 伺服器的名稱,我應該在管道上設定什麼? 非常感謝提前

P粉403804844
P粉403804844

全部回覆(1)
P粉567281015

請注意,步驟腳本是在單一 docker 容器中執行的。如果您需要連接到其他一些服務來執行整合測試,您應該:

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!