Laravel & PEST Php | Github Actions | cURL error 7: Failed to connect to localhost port 8000

Viewed 919

I would like to run Github Actions on a Laravel Project with PEST PHP but I'm receiving errors when running the HTTP Facade to hit a local API within my testsuite.

cURL error 7: Failed to connect to localhost port 8000: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

I've tried to change the APP_URL on the Github .env but without any success. On my local machine test working as expected.

Code that gets hit via the test

   $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 Actions

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
0 Answers
Related