Was able to get the gitlab ci/cd pipeline working with my laravel project. The pipeline passes with the example tests, and others, but fails on each test that issues a post. When I run the tests locally all pass without any issue, so there seems to be something wrong with the pipeline config…
For example this test passes:
public function test_user_can_view_a_login_form()
{
$response = $this->get('/login');
$response->assertSuccessful();
$response->assertViewIs('auth.login');
}
and this test fails, as will every other test that uses a POST:
public function test_user_can_login_with_correct_credentials()
{
$user = User::factory()->create([
'password' => bcrypt($password = 'i-love-laravel'),
]);
$response = $this->post('/login', [
'email' => $user->email,
'password' => $password,
]);
$response->assertRedirect('/home');
$response->assertStatus(302);
$this->assertAuthenticatedAs($user);
}
This is the error produce in the pipeline (but not when I run the tests outside of the pipeline).
• Tests\Feature\Auth\LoginTest > user can login with correct credentials
[1502] Response status code [419] is not a redirect status code.
[1503]Failed asserting that false is true.
Using Gitlab.com not self managed.
my ci.yml:
image: php:latest
services:
- mysql:latest
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- vendor/
- node_modules/
variables:
MYSQL_DATABASE: db
MYSQL_ROOT_PASSWORD: secret
before_script:
- apt-get update -yqq
- apt-get install -y libfreetype6-dev libjpeg-dev libpng-dev libwebp-dev zlib1g-dev libzip-dev libonig-dev libpng-dev
- docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
- docker-php-ext-install -j$(nproc) gd
- apt-get install -y --no-install-recommends libgmp-dev
- docker-php-ext-install gmp pdo_mysql pdo opcache zip
- pecl install xdebug
- docker-php-ext-enable xdebug
- curl -sS https://getcomposer.org/installer | php
- php composer.phar update
- php composer.phar install
- cp .env.example.testing .env
- php artisan key:generate
- php artisan config:cache
- php artisan migrate
- php artisan db:seed
test:
script:
- php vendor/bin/phpunit --coverage-text --colors=never
I have tried to add in nodejs dependencies but that didn’t change anything, doesn’t make sense why every post returns a 419 in the pipeline but not locally.
I do have a dockerized app and so a docker-compose, but I’m not testing that with the pipeline, just just testing laravel specifically.