PHPUnit test error csrf Laravel, in gitlab CI / CD docker

1

I am having problems when writing POST requests in the integration tests, in the local machine where I launch the tests they pass without problems, but in the docker container of gitlab fail by the token csrf, even if I put the token in the petition I still do not pass the test, it's a little strange.

I understood that this middleware was disabled in the tests, but I do not know what to think anymore.

Error

Illuminate\Session\TokenMismatchException: 

.../vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:71

Test code

public function testClientStatusUpdate()
{
    $this->withoutExceptionHandling();
    $user = \App\User::find(1);

    $response = $this->actingAs($user)->post('/client/2/status', [
        'status' => 1, 
        '_token' => csrf_token()
    ]);
    $response->assertStatus(302);

    $response = $this->actingAs($user)->get('/client/2');
    $response->assertViewIs('client.show');
    $response->assertSuccessful();
    $response->assertSee('Estado cambiado correctamente correctamente.');
    $response->assertSee('<span class="label label-success">Activo</span>');
}

CI / CD

image: php:latest
services:
  - mysql:5.7.24
variables:
  MYSQL_DATABASE: project_name
  MYSQL_ROOT_PASSWORD: secret
cache:
  paths:
  - vendor/
  - node_modules/

before_script:
  - apt-get update -yqq
  - apt-get install libcurl4-gnutls-dev libicu-dev libmcrypt-dev libpng-dev  libxml2-dev libbz2-dev libpcre3-dev -yqq
  - docker-php-ext-install mbstring pdo_mysql curl json intl gd xml zip bz2 opcache
  - curl -sS https://getcomposer.org/installer | php
  # Run  build
  - php composer.phar install 
  - cp .env.example .env
  - php artisan --version
  - php artisan key:generate
  - php artisan config:cache
  - php artisan migrate --force
  - php artisan db:seed --force

test:
  script:
  - php vendor/bin/phpunit --coverage-text --colors=never 

Other information:
Laravel: 5.5.44
PHPUnit: 6.5.13

Is there a way to disable the VerifyCsrfToken middleware for the tests or to write the tests so that a valid token is obtained to pass the test?

    
asked by Xerif 19.11.2018 в 22:14
source

0 answers