Commit 795ec798 authored by Thomas Boni's avatar Thomas Boni
Browse files

Merge branch '103-job-implementing-phpunit-testing-job' into 'latest'

Resolve "[Job] Implementing PHPUnit testing job"

Closes #103

See merge request go2scale/hub!47
parents 120a7b16 6d020f84
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -31,4 +31,4 @@

| Name | Description | Default |
| ---- | ----------- | ------- |
| `VARIABLE` <img width=250/> | A general variable for this job | `{{ variable }}` |
| `VARIABLE` <img width=100/> | A general variable for this job <img width=175/>| `{{ variable }}` <img width=100/>|
+49 −0
Original line number Diff line number Diff line
# 🐘 PHPUnit Testing

## Description

Using this job you'll be able to launch PHPUnit tests.

## How to use it

1. Put a `phpunit.xml` (check [syntax](https://phpunit.readthedocs.io/en/latest/configuration.html#the-phpunit-element)) in the root of your php project. Edit `PHPUNIT_CONFIG_FILE` (see [Variables](#variables)) to change the default behavior.

2. Add the corresponding URL to your `.gitlab-ci.yml` file (see [Getting
   started](/getting-started)). Example:

    ```yaml
    include:
      - remote: 'https://jobs.go2scale.io/phpunit_test.yml'
    ```

3. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/getting-started/#jobs-customization)
4. Well done, your job is ready to work ! 😀

## Job details

* Job name: `phpunit_test`
* Docker image:
[`lorisleiva/laravel-docker:7.3`](https://hub.docker.com/r/lorisleiva/laravel-docker)
* Default stage: `static_tests`
* When: `always`


### Variables

| Name | Description | Default |
| ---- | ----------- | ------- |
| `PHPUNIT_OUTPUT` <img width=100/> | Output file <img width=175/>| `report_phpunit.xml` <img width=100/>|
| `PHPUNIT_CONFIG_FILE` | Config file source in repository | `phpunit.xml` |
| `PHPUNIT_COLORS` | Use colors in output | `never` |
| `PHPUNIT_OPTIONS` | Custom user options for phpunit | ` ` |
| `PROJECT_ROOT` | PHP Project location | `/` |

!!! note
    All paths defined in variables are starting from the root of your repository.

### Artifacts

We use [Junit](https://junit.org/junit5/)'s XML report to display error report
directly in pipeline `Test` tab and in merge request widget.
The report defined in variable `PHPUNIT_OUTPUT` is also available directly in the artifacts. 
+6 −0
Original line number Diff line number Diff line
name: phpunit_test
description: A ready to use php environment that launches phpunit testings
default_stage: static_tests
icon: 🐘
maintainer: Protocole
license: MIT
 No newline at end of file
+23 −0
Original line number Diff line number Diff line
stages:
  - static_tests

phpunit_test:
    image: lorisleiva/laravel-docker:7.3
    stage: static_tests
    variables:
      PHPUNIT_OUTPUT: "report_phpunit.xml"
      PHPUNIT_CONFIG_FILE: "phpunit.xml"
      PHPUNIT_COLORS: "never"
      PHPUNIT_OPTIONS: ""
      PROJECT_ROOT: "/"
    script:
      # Going to the root of php project
      - cd ${CI_PROJECT_DIR}${PROJECT_ROOT}
      # Running Unit testing
      - phpunit --configuration ${PHPUNIT_CONFIG_FILE} --coverage-text --colors=${PHPUNIT_COLORS} --log-junit ${CI_PROJECT_DIR}/${PHPUNIT_OUTPUT} ${PHPUNIT_OPTIONS}
    artifacts:
      when: always
      paths:
        - ${CI_PROJECT_DIR}/${PHPUNIT_OUTPUT}
      reports:
        junit: ${CI_PROJECT_DIR}/${PHPUNIT_OUTPUT}
+1 −0
Original line number Diff line number Diff line
* Initial version
 No newline at end of file