From 14a4a35064a86416f7990fa4a6c7ceba32455935 Mon Sep 17 00:00:00 2001
From: Thomas Flori <thflori@gmail.com>
Date: Thu, 7 Mar 2024 12:09:34 +0100
Subject: [PATCH] switch to gitlab with gitlab-ci

---
 .gitattributes |  3 +-
 .gitlab-ci.yml | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++
 .travis.yml    | 23 ----------------
 README.md      |  4 +--
 composer.json  | 15 ++++++----
 phpunit.xml    |  3 +-
 ruleset.xml    | 47 ++++++++++++++++++++++++++++++++
 7 files changed, 137 insertions(+), 32 deletions(-)
 create mode 100644 .gitlab-ci.yml
 delete mode 100644 .travis.yml
 create mode 100644 ruleset.xml

diff --git a/.gitattributes b/.gitattributes
index 09dfee1..df54092 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,5 +1,6 @@
 /tests export-ignore
 .gitattributes export-ignore
 .gitignore export-ignore
-.travis.yml export-ignore
+.gitlab-ci.yml export-ignore
 phpunit.xml export-ignore
+ruleset.xml export-ignore
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..3b1151d
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,74 @@
+stages:
+  - test
+  - publish
+
+phpunit:
+  stage: test
+  needs: []
+  parallel:
+    matrix:
+      - PHP_VERSION: ['7.3', '7.4', '8.0', '8.1', '8.2']
+  image: iras/php-composer:${PHP_VERSION}
+  cache:
+    key: php-dependencies-${PHP_VERSION}
+    paths:
+      - ./storage/composer
+  before_script:
+    - export COMPOSER_CACHE_DIR=$(pwd)/storage/composer
+    # basically we are ignoring the composer.lock in tests
+    - composer update --no-interaction --ansi
+  script:
+    - php -dzend_extension=xdebug.so -dxdebug.mode=coverage 
+        vendor/bin/phpunit -c phpunit.xml --color=always 
+          --coverage-text --coverage-cobertura=coverage/cobertura.xml 
+          --coverage-html=coverage/html | tee /tmp/phpunit.out
+    - sed -r 's~\x01?(\x1B\(B)?\x1B\[([0-9;]*)?[JKmsu]\x02?~~g' /tmp/phpunit.out|grep '^  Lines'
+  artifacts:
+    paths:
+      - coverage/html
+    reports:
+      coverage_report:
+        coverage_format: cobertura
+        path: coverage/cobertura.xml
+  coverage: '/^\s*Lines:\s*\d+.\d+\%/'
+
+quality:
+  stage: test
+  needs: []
+  image: iras/php-composer:8.2
+  cache:
+    key: php-dependencies-8.2
+    paths:
+      - ./storage/composer
+  before_script:
+    - export COMPOSER_CACHE_DIR=$(pwd)/storage/composer
+    # basically we are ignoring the composer.lock in tests
+    - composer update --no-interaction --ansi
+  script:
+    - composer run code-quality
+
+style:
+  stage: test
+  needs: []
+  image: iras/php-composer:8.2
+  cache:
+    key: php-dependencies-8.2
+    paths:
+      - ./storage/composer
+  before_script:
+    - export COMPOSER_CACHE_DIR=$(pwd)/storage/composer
+    # basically we are ignoring the composer.lock in tests
+    - composer update --no-interaction --ansi
+  script:
+    - composer run code-style
+
+packagist:
+  stage: publish
+  needs: [phpunit]
+  image: alpine:3.18
+  before_script:
+    - apk add --no-cache curl
+  script:
+    - curl -XPOST -H'content-type:application/json' 
+        'https://packagist.org/api/update-package?username=tflori&apiToken='${PACKAGIST_API_TOKEN} 
+         -d'{"repository":{"url":"https://gitlab.w00tserver.org/tflori/nb-sessions.git"}}'
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index cae9ee3..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-language: php
-php:
-- 7.1
-- 7.2
-
-sudo: false
-
-cache:
-    directories:
-    - $HOME/.composer/cache
-
-matrix:
-    fast_finish: true
-
-before_script:
-- composer install --no-interaction
-- sh -c 'if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then composer require satooshi/php-coveralls:~0.6@stable; fi;'
-- mkdir -p build/logs
-
-script:
-- composer code-style
-- vendor/bin/phpunit -c phpunit.xml --coverage-clover=build/logs/clover.xml --coverage-text
-- sh -c 'if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then php vendor/bin/coveralls -v; fi;'
diff --git a/README.md b/README.md
index 4621c8f..2358f0b 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 # tal
 
-[![Build Status](https://travis-ci.org/tflori/tal.svg?branch=master)](https://travis-ci.org/tflori/tal)
-[![Coverage Status](https://coveralls.io/repos/github/tflori/tal/badge.svg?branch=master)](https://coveralls.io/github/tflori/tal?branch=master)
+[![Build Status](https://gitlab.w00tserver.org/tflori/tal/badges/master/pipeline.svg)](https://gitlab.w00tserver.org/tflori/tal/-/pipelines)
+[![Coverage Status](https://gitlab.w00tserver.org/tflori/tal/badges/master/coverage.svg)](https://gitlab.w00tserver.org/tflori/tal/-/pipelines)
 [![Latest Stable Version](https://poser.pugx.org/tflori/tal/v/stable.svg)](https://packagist.org/packages/tflori/tal) 
 [![Total Downloads](https://poser.pugx.org/tflori/tal/downloads.svg)](https://packagist.org/packages/tflori/tal) 
 [![License](https://poser.pugx.org/tflori/tal/license.svg)](https://packagist.org/packages/tflori/tal)
diff --git a/composer.json b/composer.json
index 12afeb1..eed8fa3 100644
--- a/composer.json
+++ b/composer.json
@@ -4,16 +4,21 @@
     "type": "library",
     "license": "MIT",
     "scripts": {
-        "code-style": "phpcs --standard=PSR2 src && phpcs --standard=PSR2 --ignore=example tests"
+        "code-style": "phpcs --colors --standard=PSR2 src && phpcs --colors --standard=PSR2 --ignore=example tests",
+        "code-quality": "phpmd src,tests ansi ruleset.xml",
+        "test": "phpunit --stderr",
+        "coverage": "phpunit --stderr --coverage-text"
     },
     "require": {
-        "guzzlehttp/psr7": "^1.4.2",
+        "guzzlehttp/psr7": "^2.6.1",
         "ralouphie/getallheaders": "^2.0.5"
     },
     "require-dev": {
-        "phpunit/phpunit": "^7.2.7",
-        "squizlabs/php_codesniffer": "^3.3.1",
-        "mockery/mockery": "^1.1.0"
+        "phpunit/phpunit": "*",
+        "mockery/mockery": "*",
+        "squizlabs/php_codesniffer": "*",
+        "tflori/phpunit-printer": "*",
+        "phpmd/phpmd": "*"
     },
     "autoload": {
         "psr-4": {
diff --git a/phpunit.xml b/phpunit.xml
index 8cd9d23..286b292 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -8,7 +8,8 @@
          convertNoticesToExceptions="true"
          convertWarningsToExceptions="true"
          processIsolation="false"
-         stopOnFailure="false">
+         stopOnFailure="false"
+         printerClass="PhpUnitPrinter\TextPrinter">
     <testsuite name="tests">
         <directory>./tests/</directory>
     </testsuite>
diff --git a/ruleset.xml b/ruleset.xml
new file mode 100644
index 0000000..7d4077a
--- /dev/null
+++ b/ruleset.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<ruleset name="My first PHPMD rule set"
+         xmlns="http://pmd.sf.net/ruleset/1.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
+                     http://pmd.sf.net/ruleset_xml_schema.xsd"
+         xsi:noNamespaceSchemaLocation="
+                     http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+    <rule ref="rulesets/design.xml" />
+    <rule ref="rulesets/codesize.xml" />
+    <rule ref="rulesets/unusedcode.xml" />
+
+
+    <rule ref="rulesets/cleancode.xml">
+        <exclude name="ElseExpression" />
+        <exclude name="StaticAccess" />
+    </rule>
+    <rule ref="rulesets/cleancode.xml/StaticAccess">
+        <properties>
+            <property name="exceptions">
+                <value>
+                    \Hamcrest\Matchers,
+                    \Mockery
+                </value>
+            </property>
+        </properties>
+    </rule>
+
+    <rule ref="rulesets/controversial.xml">
+        <exclude name="Superglobals" />
+    </rule>
+
+    <rule ref="rulesets/naming.xml">
+        <exclude name="ShortVariable" />
+    </rule>
+    <rule ref="rulesets/naming.xml/ShortVariable">
+        <properties>
+            <property name="exceptions">
+                <value>
+                    id
+                </value>
+            </property>
+        </properties>
+    </rule>
+
+</ruleset>
-- 
GitLab