I think the reason is because you are running composer with the --no-dev flag. So just remove that, and the test command should be available.
Dec 9, 2024
4
Level 8
ERROR Command "test" is not defined.
Hello
With the support of chat GPT I created this .gitlab-ci.yml file
stages:
- setup
- build
- test
cache:
paths:
- vendor/
variables:
POSTGRES_DB: tracker
POSTGRES_USER: sail
POSTGRES_PASSWORD: ""
POSTGRES_HOST_AUTH_METHOD: trust
setup:
stage: setup
image: php:8.3-cli
before_script:
- apt-get update && apt-get install -y git unzip libzip-dev libpq-dev
- docker-php-ext-install zip pdo pdo_pgsql
- curl -sS https://getcomposer.org/installer | php
- mv composer.phar /usr/local/bin/composer
script:
- cp .env.example .env
- sed -i 's/DB_CONNECTION=mysql/DB_CONNECTION=pgsql/' .env
- sed -i 's/DB_HOST=127.0.0.1/DB_HOST=db/' .env
- sed -i 's/DB_DATABASE=forge/DB_DATABASE=tracker/' .env
- sed -i 's/DB_USERNAME=root/DB_USERNAME=sail/' .env
- sed -i 's/DB_PASSWORD=//g' .env
- sed -i 's/DB_PORT=3306/DB_PORT=5432/' .env
- composer install --no-dev --optimize-autoloader
artifacts:
paths:
- vendor/
build:
stage: build
image: php:8.3-cli
dependencies:
- setup
script:
- php artisan config:cache
- php artisan route:cache
- php artisan view:cache
test:
stage: test
image: php:8.3-cli
services:
- name: postgres:15
alias: db
before_script:
- apt-get update && apt-get install -y git unzip libzip-dev libpq-dev
- docker-php-ext-install pdo pdo_pgsql
- curl -sS https://getcomposer.org/installer | php
- mv composer.phar /usr/local/bin/composer
- cp .env.example .env
- sed -i 's/DB_CONNECTION=mysql/DB_CONNECTION=pgsql/' .env
- sed -i 's/DB_HOST=127.0.0.1/DB_HOST=db/' .env
- sed -i 's/DB_DATABASE=forge/DB_DATABASE=tracker/' .env
- sed -i 's/DB_USERNAME=root/DB_USERNAME=sail/' .env
- sed -i 's/DB_PASSWORD=//g' .env
- sed -i 's/DB_PORT=3306/DB_PORT=5432/' .env
- composer install --no-dev --optimize-autoloader
script:
- php artisan migrate --force
- php artisan test
when I run the pipelines the stages setup and build successed but I got an error on test stage :
$ php artisan migrate --force
INFO Preparing database.
Creating migration table ......................................... 25ms DONE
INFO Running migrations.
2014_10_12_000000_create_users_table ............................. 17ms DONE
(...)
2024_02_14_202021_remove_columns_from_stops_table ................. 2ms DONE
$ php artisan test
ERROR Command "test" is not defined. Did you mean one of these?
⇂ make:test
⇂ schedule:test
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
I’m not sure how to resolve this issue! On my local setup, I use Laravel Sail, and the unit tests run successfully with the command sail test. Do you have any suggestions?
Level 73
1 like
Please or to participate in this conversation.