Skip to content

Commit

Permalink
[FEATURE] add code coverage
Browse files Browse the repository at this point in the history
add converage configuration to phpunit and export the
results to the artifacts
add some more linter to check php, typoscript and
yaml files

Resolves: extcode#19
  • Loading branch information
Daniel Lorenz committed Nov 25, 2018
1 parent 67bd4e9 commit f085125
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ Documentation/_make

.DS_Store
.idea

phpunit.coverage.xml
phpunit.report.xml
70 changes: 55 additions & 15 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,41 @@ before_script:
- apk add git --update

stages:
- cgl
- lint
- test
- analysis
- upload

test:cgl:
lint:cgl:
image: composer:1.6
stage: cgl
stage: lint
before_script:
- composer require typo3/cms-core --no-update
- composer install
- composer remove typo3/cms-core --no-update
- composer install --no-progress --no-ansi --no-interaction
script:
- .Build/bin/php-cs-fixer fix --config=Build/.php_cs -v --dry-run --using-cache=no --path-mode=intersection ./
- .Build/bin/php-cs-fixer fix --config=Build/.php_cs.dist -v --dry-run --using-cache=no --path-mode=intersection ./

lint:typoscriptcgl:
stage: lint
image: composer:1.6
script:
- composer remove typo3/cms-core --no-update
- composer install --no-progress --no-ansi --no-interaction
- .Build/bin/typoscript-lint -c tslint.yaml

lint:yaml:
stage: lint
image: python:alpine3.7
before_script:
- pip install yamllint==1.10.0
script:
- yamllint -c Build/yamllint.yaml Configuration/ Resources/ .travis.yml

lint:php72:
stage: lint
image: php:7.2-alpine
script:
- find . -name \*.php -exec php -l "{}" \;

.test: &test_php
stage: test
Expand All @@ -40,7 +62,12 @@ test:cgl:
only:
- branches
before_script:
- apk --no-cache add bash curl git mercurial openssh openssl parallel subversion tini
- apk add --no-cache bash curl git mercurial openssh openssl parallel subversion tini
- >
if [[ "$COVERAGE" == "1" ]]; then
apk add --no-cache $PHPIZE_DEPS
pecl install xdebug && docker-php-ext-enable xdebug
fi
- docker-php-ext-install mysqli
- wget https://composer.github.io/installer.sig -O - -q | tr -d '\n' > installer.sig
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Expand All @@ -49,16 +76,29 @@ test:cgl:
- php -r "unlink('composer-setup.php'); unlink('installer.sig');"
- composer require typo3/cms-core="${TYPO3_VERSION}"
script:
- .Build/bin/phpunit -c .Build/vendor/nimut/testing-framework/res/Configuration/UnitTests.xml Tests/Unit
- find . -name \*.php ! -path "./.Build/*" | parallel --gnu php -d display_errors=stderr -l {} > /dev/null
- >
if [[ "$COVERAGE" == "0" ]]; then
.Build/bin/phpunit -c Build/UnitTests.xml Tests/Unit
fi
- >
if [[ "$COVERAGE" == "1" ]]; then
.Build/bin/phpunit --coverage-clover=phpunit.coverage.xml --log-junit=phpunit.report.xml -c Build/UnitTests.xml Tests/Unit
fi
# - find 'Tests/Functional' -wholename '*Test.php' | parallel --gnu 'echo; echo "Running functional test suite {}"; .Build/bin/phpunit --colors -c .Build/vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml {}'
artifacts:
paths:
- phpunit.coverage.xml
- phpunit.report.xml
expire_in: 1 day
when: always

# Build in PHP 7.2 and TYPO3 9.3
test:php72:typo3_9:
<<: *test_php
variables:
DOCKER_TAG: 7.2-alpine
TYPO3_VERSION: ^9.3
TYPO3_VERSION: ^9.5
COVERAGE: 1

sonarqube:
stage: analysis
Expand All @@ -72,8 +112,8 @@ sonarqube:
SONAR_SOURCES: "./Classes"
SONAR_GITLAB_PROJECT_ID: "$CI_PROJECT_ID"
script:
- echo "sonar.projectKey=cart_products-9.x" > sonar-project.properties
- gitlab-sonar-scanner
- echo "sonar.projectKey=cart_products-9.x" > sonar-project.properties
- gitlab-sonar-scanner -Dsonar.php.coverage.reportPath=phpunit.coverage.xml -Dsonar.php.tests.reportPath=phpunit.report.xml
allow_failure: true

sonarqube-reports:
Expand All @@ -88,8 +128,8 @@ sonarqube-reports:
SONAR_SOURCES: "./Classes"
SONAR_TESTS: "./Tests"
script:
- echo "sonar.projectKey=cart_products-9.x" > sonar-project.properties
- gitlab-sonar-scanner
- echo "sonar.projectKey=cart_products-9.x" > sonar-project.properties
- gitlab-sonar-scanner -Dsonar.php.coverage.reportPath=phpunit.coverage.xml -Dsonar.php.tests.reportPath=phpunit.report.xml

ter-upload:
image: php:7.1-alpine
Expand All @@ -102,7 +142,7 @@ ter-upload:
- curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- export COMPOSER_CACHE_DIR=.composer
script:
- composer install
- composer install --no-progress --no-ansi --no-interaction
- composer require namelesscoder/typo3-repository-client
- export TYPO3_PATH_WEB="$PWD/.Build/Web"
- >
Expand Down
File renamed without changes.
21 changes: 21 additions & 0 deletions Build/UnitTests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<phpunit
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="../.Build/vendor/nimut/testing-framework/res/Configuration/UnitTestsBootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="false"
>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../Classes/</directory>
</whitelist>
</filter>
</phpunit>
23 changes: 23 additions & 0 deletions Build/yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
extends: default

rules:
line-length: disable
document-start: disable
braces:
min-spaces-inside-empty: 1
max-spaces-inside-empty: 1
brackets:
min-spaces-inside-empty: 1
max-spaces-inside-empty: 1
comments:
level: error
min-spaces-from-content: 1
comments-indentation:
level: error
empty-lines:
max: 1
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
indentation:
spaces: 2
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
},
"require-dev": {
"nimut/testing-framework": "^4.0",
"friendsofphp/php-cs-fixer": "^2.0"
"friendsofphp/php-cs-fixer": "^2.0",
"helmich/typo3-typoscript-lint": "^1.4"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit f085125

Please sign in to comment.