miguellima's avatar

Livewire test macro not loading on GitHub Actions

Hi everyone,

I'm unable to get my tests to run on GitHub Actions.

I've tried everything I was able to think of. Could anybody help?

<?php

// ensure we can see the request invite page
it('can render', function () {
    $this->get('/')
        ->assertSeeLivewire('auth.request-invite');
});

my ci config:

name: "CI deploy"

on:
  push:
    branches:    
      # - '*'         # matches every branch that doesn't contain a '/'
      # - '*/*'       # matches every branch containing a single '/'
      - '**'        # matches every branch
      # - '!master'   # excludes master

jobs:
  tests:
    name: Laravel (PHP ${{ matrix.php-versions }})
    runs-on: ubuntu-latest

    env:
      APP_ENV: ci
    services:
      postgres:
        image: postgres:13
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
        ports:
          - 5432:5432
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
    strategy:
      fail-fast: false
      matrix:
        php-versions: ['8.2']

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup PHP, with composer and extensions
        uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
        with:
          php-version: ${{ matrix.php-versions }}
          tools: composer:v2
          extensions: mbstring, dom, fileinfo, pgsql, libxml, xml, xmlwriter, dom, tokenizer, filter, json, phar, pcre, openssl, pdo, intl, curl, exif, gd
          coverage: xdebug #optional
        env:
          GD_CONFIGURE_OPTS: --with-freetype --with-webp --with-jpeg
          GD_LIBS: freetype-dev libjpeg-turbo-dev libwebp-dev libjpeg-dev libpng-dev

      - name: Get composer cache directory
        id: composer-cache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"

      - name: Cache composer dependencies
        uses: actions/cache@v1
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          # Use composer.json for key, if composer.lock is not committed.
          # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: ${{ runner.os }}-composer-

      - name: Install Composer dependencies
        run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader

      - name: Dump autoload
        run: composer dump-autoload --optimize --no-interaction

      - name: Clear Config
        run: php artisan config:clear

      - name: Clear Optimize
        run: php artisan optimize:clear

      - name: Cache Config
        run: php artisan config:cache

      - name: Run Migration
        run: php artisan migrate -v

      - name: Check linting
        run: vendor/bin/pint --test

      - name: Test with pest
        run: vendor/bin/pest --display-errors

error:

  ⨯ it can render                                                        0.18s  
18
  ────────────────────────────────────────────────────────────────────────────  
19
   FAILED  Tests\Feature\Pages\IndexTest > it can re…  BadMethodCallException   
20
  Method Illuminate\Http\Response::assertSeeLivewire does not exist.
0 likes
3 replies
benbjurstrom's avatar

Did you ever resolve this? Having this issue on a brand new Laravel 11 install.

benbjurstrom's avatar

Looks like assertSeeLivewire is only registered when APP_ENV=testing. The fix was adding the correct env to my test step.

      - name: Run Tests
        run: php vendor/bin/pest \
          --configuration phpunit.xml \
          --testdox \
          --coverage-text \
          --display-errors \
          --coverage-filter=app \
          --colors=never
        env:
          DB_PORT: 5432
          REDIS_PORT: 6379
          APP_ENV: testing
1 like

Please or to participate in this conversation.