Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

masonfox's avatar

Laravel Jetstream & Auth Tests Fail On Github Actions

Hello, I'm having some trouble getting a CI pipeline setup to run my test suite through Github Actions with Laravel Jetstream and basic authentication tests. All of my other tests, like Livewire components, work without an issue.

I've using the base YAML that I've found on Github Actions for a Laravel app, but Feature tests from Laravel Jetstream and basic authentication ones (like below) fail. It seems like it has to do with $this->get() method by that is what all of these tests have in common.

My initial thought was that the web server - php artisan serve - needed to be running while the tests were running, but I tried this and it still didn't work. :(

Here's an example of a test failure:

   FAILED  Tests\Feature\AuthenticationTest > login screen can be rendered      
  Expected response status code [200] but received 500.
Failed asserting that 500 is identical to 200.

  at tests/Feature/AuthenticationTest.php:18
     14▕     public function test_login_screen_can_be_rendered(): void
     15▕     ***
     16▕         $response = $this->get('/login');
     17▕ 
  ➜  18▕         $response->assertStatus(200);
     19▕     ***
     20▕ 
     21▕     public function test_users_can_authenticate_using_the_login_screen(): void
     22▕     ***

Here's a copy of my current Github Actions workflow YAML file:

name: Laravel

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  laravel-tests:

    runs-on: ubuntu-latest

    steps:
    - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
      with:
        php-version: '8.0'
    - uses: actions/checkout@v3
    - name: Copy .env
      run: php -r "file_exists('.env') || copy('.env.example', '.env');"
    - name: Install Dependencies
      run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
    - name: Generate key
      run: php artisan key:generate
    - name: Directory Permissions
      run: chmod -R 777 storage bootstrap/cache
    - name: Create Database
      run: |
        mkdir -p database
        touch database/database.sqlite
    - name: Execute tests (Unit and Feature tests) via PHPUnit
      env:
        DB_CONNECTION: sqlite
        DB_DATABASE: database/database.sqlite
      run: vendor/bin/phpunit

All I want to do is run my full test suite in Github Actions, so ultimately assistance with my YAML file is appreciated. Thanks for the help!

0 likes
8 replies
nexxai's avatar

First question: Which version of Laravel are you using? The most recent ones need a more current version of PHP than 8.0 so I'd be double checking those requirements.

Second question: What does your .env.example file look like?

nexxai's avatar

For posterity's sake, here is my typical template for Github Actions:

TestAndDeploy.yml

name: Deployment

on:
  push:

  workflow_dispatch:

jobs:
  fabpot-security-checker:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout the repository
        uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2

      - name: Install security-checker
        uses: symfonycorp/security-checker-action@v5

  pest:
    runs-on: ubuntu-latest
    needs: [fabpot-security-checker, phpcpd]

    services:
      mariadb:
        image: mariadb:10.11
        env:
          MYSQL_ROOT_PASSWORD: root
        ports:
          - 3306:3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

      redis:
        image: redis:7.0-alpine
        ports:
          - 6379:6379
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - name: Checkout the repository
        uses: actions/checkout@v4

      - name: Setup PHP with composer v2
        uses: shivammathur/setup-php@v2
        with:
          php-version: "8.2"
          tools: composer:v2
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick, redis
          coverage: xdebug

      - name: Install composer packages
        run: |
          php -v
          composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts

      - name: npm install
        run: |
          npm --version
          npm install
          npm run production

      - name: Create temp database
        run: |
          mysql --host 127.0.0.1 -uroot -proot -e "CREATE DATABASE IF NOT EXISTS laravel_db"

      - name: Execute tests
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        run: |
          cp .env.github .env
          php -v
          php artisan migrate --force
          php artisan key:generate
          ./vendor/bin/pest --parallel --coverage-clover=coverage.xml
          bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload'

  phpstan:
    runs-on: ubuntu-latest
    needs: [fabpot-security-checker, phpcpd]

    steps:
      - name: Checkout the repository
        uses: actions/checkout@v4

      - name: Setup PHP with composer v2
        uses: shivammathur/setup-php@v2
        with:
          php-version: "8.2"
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick, redis
          tools: composer:v2

      - name: Install composer packages
        run: |
          php -v
          composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts

      - name: Static analysis with phpstan
        run: ./vendor/bin/phpstan analyse

  phpcpd:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout the repository
        uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2

      - name: Install phpcpd
        run: test -f phpcpd.phar || curl -L https://phar.phpunit.de/phpcpd.phar -o phpcpd.phar

      - name: Run phpcpd
        run: php phpcpd.phar app/ --min-lines=50

  ploi_deploy:
    runs-on: ubuntu-latest
    needs: [pest, phpstan]
    if: github.ref == 'refs/heads/main'

    steps:
      - name: Trigger Ploi webhook
        run: curl -X POST ${{ secrets.PLOI_DEPLOY_WEBHOOK }}
masonfox's avatar

@nexxai, regarding the PHP version, I'd set this to 8.3 at one point, and didn't make any difference.

Here's a copy of my .env.example:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
APP_FAKER_LOCALE=en_US

APP_MAINTENANCE_DRIVER=file
APP_MAINTENANCE_STORE=database

BCRYPT_ROUNDS=12

LOG_CHANNEL=stack
LOG_STACK=single
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=sail
DB_PASSWORD=password

BROADCAST_CONNECTION=log
CACHE_STORE=redis
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
SESSION_ENCRYPT=false
SESSION_PATH=/
SESSION_DOMAIN=null

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

CASHIER_CURRENCY=USD
CASHIER_CURRENCY_LOCALE=en
STRIPE_KEY=pk_test_test
STRIPE_SECRET=pk_test_test
STRIPE_WEBHOOK_SECRET=sk_test_example

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_HOST=
PUSHER_PORT=443
PUSHER_SCHEME=https
PUSHER_APP_CLUSTER=mt1

VITE_APP_NAME="${APP_NAME}"
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

Thanks for the reply! I take a look and tinker with that YAML file your provided! Thanks!

nexxai's avatar

@masonfox BCRYPT_ROUNDS=12 suggests to me that you're using Laravel 11? L11 only supports PHP 8.2 and 8.3, so at the very least you must upgrade to that. That may not solve all of your problems, but it will solve at least one of them.

Also, are you using the RefreshDatabase trait in your tests (or are you expecting it to be there)? If it's not in there, that could be the cause of the 500 from just visiting the login page.

nexxai's avatar

Also, one other thing that I was just thinking of, I think 500 errors during testing still show up in the logs so you could add a step in your workflow to run tail -n 500 storage/logs/laravel.log which should dump out the last 500 lines of the log file which might give you an idea of what's failing.

puklipo's avatar

Laravel11&Jetstream5.0

Maybe DB_DATABASE: database/database.sqlite is incorrect.

Use in-memory SQLite. This is the fastest in testing.

comment out phpunit.xml

<env name="DB_CONNECTION" value="sqlite"/> 
<env name="DB_DATABASE" value=":memory:"/>

No need for sqlite section of workflow.

kobear's avatar

Just in case anyone comes across this, I was having problems with Github actions failing for a brand new install of Jetstream. Worked fine on my local testing, but in Actions, it failed. Below is the YAML I got it to work.

Basically what it came down to was that you have to have Node running for the Jetstream related HTTP code asserts to work properly.

Also added a handy item that creates a artifact of the Laravel log file if the Action fails .

name:  PHPUnit
 
on: [push]
 
jobs:
  PHPUnit-tests:
    name: Run tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Cache composer dependencies
        uses: actions/cache@v2
        with:
          path: vendor
          key: composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            composer-

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
          extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
          coverage: none
 
      - name: Run composer install
        run: composer install -n --prefer-dist
 
      - name: Prepare Laravel Application
        run: |
          cp .env.ci .env
          php artisan key:generate

      - name: Create SQLite database
        run: |
          mkdir -p database
          touch database/database.sqlite

      - name: Run migrations
        env:
          DB_CONNECTION: sqlite
          DB_DATABASE: database/database.sqlite
        run: php artisan migrate

      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: '21.x'

      - name: npm install
        run: |
          npm --version
          npm install
          npm run build

      - name: Run tests
        run: php artisan test

      - uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: laravel-failure-artifact
          path: storage/logs/laravel.log
3 likes

Please or to participate in this conversation.