Sign inSign up

liou95145hf/gitlab-ci-laravel-test

By liou95145hf

•Updated about 4 years ago

gitlab ci laravel test

Image
1

130

liou95145hf/gitlab-ci-laravel-test repository overview

⁠release version

  • v1.3.1 : create redis service-2022/09/06
  • v1.2.1 -2022/09/04

⁠note

  • is lightweight image for create your laravel project test on gitlab ci
  • this test only run sqlite, attention maybe some program is not working in sqlite
  • php 8.1
  • php8.1-fpm
  • Ubuntu 22.04.1 LTS
  • redis-cli 6.0.16

⁠step1

  • setting phpunit.xml , cancel comments

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

⁠step2

  • create .env.testing
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:GRoFzuubHfP/FG1xa5p4Sh1PItNh1su1vi523PrUAvs=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug

DB_CONNECTION=sqlite
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=":memory:"
DB_USERNAME=root
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailhog
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_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}"

⁠step3

  • your Test maybe like
<?php

namespace Tests\Feature;

use Database\Seeders\UserSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class ApiTest extends TestCase
{
    use RefreshDatabase;

    /**
     * A basic feature test example.
     *
     * @return void
     */
    public function test_example()
    {
        $this->seed([
            UserSeeder::class
        ]);

        $response = $this->get('/api/users');

        $response->assertJsonCount(10);
    }
}

⁠step4

  • your .gitlab-ci.yml maybe like

image: liou95145hf/gitlab-ci-laravel-test:1.2.1

cache:
  paths:
    - vendor/

before_script:
  - composer install
  - cp .env.testing .env
  - php artisan key:generate
  - php artisan config:cache

test:
  coverage: '/^\s*Lines:\s*\d+.\d+\%/'
  script:
    - php vendor/bin/phpunit --coverage-text --colors=never

  • or use runner
stages:
  - Test

image: liou95145hf/gitlab-ci-laravel-test:1.3.1

test:
  stage: Test
  only:
      - develop
  tags:
    - "your runner name"
  # cache:
  #   paths:
  #     - vendor/
  before_script:
    - composer install
    - cp .env.testing .env
    - php artisan key:generate
    - php artisan config:cache  
    - service redis-server start
  coverage: '/^\s*Lines:\s*\d+.\d+\%/' 
  script:
    - php vendor/bin/phpunit --coverage-text --colors=never

Tag summary

Content type

Image

Digest

sha256:9e7baa00a…

Size

346.4 MB

Last updated

about 4 years ago

docker pull liou95145hf/gitlab-ci-laravel-test:1.3.1