Commit 4e19ab9d authored by Protocole's avatar Protocole
Browse files

Post review updates

parent acd5a83a
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -2,16 +2,12 @@

## Description

Using this job you'll be able to launch PHPUnit tests. You need nothing more than a valid phpunit.xml.

The results of your tests are available in two locations:

* In an artifact named report-phpunit.xml 
* In `Tests` tab, in your pipeline state page.
Using this job you'll be able to launch PHPUnit tests.

## How to use it

1. Put a valid `phpunit.xml` in the root of your php project, edit [variables](#variables) if not.
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:

@@ -37,5 +33,17 @@ The results of your tests are available in two locations:

| Name | Description | Default |
| ---- | ----------- | ------- |
| `PHPUNIT_VERBOSITY` <img width=250/> | Verbosity of PHPUnit | `-v` |
| `PROJECT_ROOT` <img width=250/> | PHP Project and phpunit.xml location | `/` |
| `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. 
+1 −1
Original line number Diff line number Diff line
name: phpunit_test
description: A ready to use php environnement that launches phpunit testings
description: A ready to use php environment that launches phpunit testings
default_stage: static_tests
icon: 🐘
maintainer: Protocole
+7 −6
Original line number Diff line number Diff line
@@ -5,18 +5,19 @@ phpunit_test:
    image: lorisleiva/laravel-docker:7.3
    stage: static_tests
    variables:
      PHPUNIT_VERBOSITY: "-v"
      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 ${PHPUNIT_VERBOSITY} --coverage-text --colors=never --stderr --log-junit report-phpunit.xml
      - phpunit --configuration ${PHPUNIT_CONFIG_FILE} --coverage-text --colors=${PHPUNIT_COLORS} --log-junit ${CI_PROJECT_DIR}/${PHPUNIT_OUTPUT}
    artifacts:
      when: always
      expire_in: never
      paths:
        - ${CI_PROJECT_DIR}${PROJECT_ROOT}/report-phpunit.xml
        - ${CI_PROJECT_DIR}${PROJECT_ROOT}/storage/logs
        - ${CI_PROJECT_DIR}/${PHPUNIT_OUTPUT}
      reports:
        junit: ${CI_PROJECT_DIR}${PROJECT_ROOT}/report-phpunit.xml
        junit: ${CI_PROJECT_DIR}/${PHPUNIT_OUTPUT}