我想使用 PEST PHP 在 Laravel 项目上运行 Github Actions,但是在运行 HTTP Facade 以在我的测试套件中访问本地 API 时收到错误消息。
cURL error 7: Failed to connect to localhost port 8000: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
我试图更改 Github .env 上的 APP_URL 但没有任何成功。在我的本地机器测试上按预期工作。
- http://localhost
- http://localhost:80
- http://localhost:8000
- http://127.0.0.1:800
- http://127.0.0.1:80
通过测试命中的代码
$response = Http::withHeaders([
'Accept' => 'application/json',
'Content-Type' => 'application/json',
])->post(route('create.country'), [
'name_de' => $name_de,
'name_fr' => $name_fr,
'name_it' => $name_it,
'name_rm' => $name_rm,
'iso_alpha_2' => $iso_alpha_2,
'iso_alpha_3' => $iso_alpha_3,
]);
Github 操作
name: "PEST"
on: [push, pull_request]
jobs:
laravel-tests:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:latest
env:
MYSQL_USER: github_actions
MYSQL_PASSWORD: github_secret
MYSQL_DATABASE: github_actions
MYSQL_ROOT_PASSWORD: github_secret
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1
- name: Prepare the environment
run: cp .env.github .env
- name: Set Composer config
run: composer config disable-tls true
- name: Install Composer dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Generate key
run: php artisan key:generate
- name: Execute PEST
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
run: ./vendor/bin/pest --coverage
Github .env
APP_NAME="Application"
APP_ENV=testing
APP_KEY=
APP_DEBUG=false
APP_URL=http://localhost:8000