PhpUnit and Travis - php

I need help my builds on Travis is always wrong.
The error is:
$phpunit
The configuration file does not exist.
The travis yml:
"language: php
php:
- 5.4
- 5.6
- 7.0
- 7.1.9
- 7.1.10
services:
- mysql
before_script:
- cd Industria
script: phpunit
notifications:
email: false"
My phpunit.xml is a folder in the Industria.
In bash tests always works.
Thanks.

Related

Travis composer install issue

I want to use travis with my simple php projects. My project structure is next:
My .travis.yml
language: php
sudo: required
before_install:
- cd http
before_script:
- cd http
install:
- composer self-update
- composer-install --no-interaction
script:
- phpunit --configuration phpunit.xml
and I want to run trevis into http folder, my composer.json and phpunit are there. However, as a result of my build, I received:
How can I solve this issue and run travis correctly? Thanks

Docker compose PHP version error but docker-compose.yml without image TAG image

I am doing a microservice course and I have downloaded this project from the website course but the project isn't working.
I have a PHP Lumen project and this is its docker-compose.yml, I had updated its composer dependencies before run because my computer has only PHP 8.1:
version: '3.7'
services:
web-academico:
build: ./php-web
volumes:
- ./php-web/:/app
- type: bind
source: ./php-web.sh
target: /app/entrypoint.sh
working_dir: /app
command: sh ./entrypoint.sh
ports:
- 8080:8080
And when I run this docker-composer, I have this message error:
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 8.0.21. in /app/vendor/composer/platform_check.php on line 24
I tried to put the TAG "image: php:8.1.0-fpm" but isn't work.
The entrypoint.sh is blank.
How can I solve it? And why docker is run without TAG image in docker-compose.yml?
I've forgot about Dockerfile and the configuration was in that file.

Gitlab CI -Laravel 5.5 - PHPUnit "Tests\TestCase not found"

I set up a Gitlab CI Pipeline for a Laravel 5.5 project (files at the bottom of the post) and the build is succeeding, but the tests fail because PHPUnit exits with the error message
Fatal error: Class 'Tests\TestCase' not found in /builds/[User]/[Repo]/tests/Feature/DocumentTest.php on line 8
(Obviously, [User] and [Repo] aren't the real values, just don't wanna make it public here)
I've tried different things already, like installing PHPUnit globally, calling PHPUnit in different ways, it all ends up with the same error message.
PHPUnit is running successfully on my local (no matter HOW I call it, it always works). So anyone knows what the problem here might be?
For reference here are the pipeline files:
.gitlab-ci.yml:
image: woohuiren/php-laravel-env:latest
services:
- mysql:latest
- redis:4.0.2-alpine
before_script:
- apk update
- docker-php-ext-install pcntl
variables:
MYSQL_DATABASE: testdb
MYSQL_ROOT_PASSWORD: root
stages:
- build
- test
build_job:
stage: build
script:
- sh .gitlab-build.sh
artifacts:
paths:
- vendor/
- bootstrap/
- composer.phar
- .env
tags:
- docker
test_job:
stage: test
dependencies:
- build_job
script:
- sh .gitlab-ci.sh
tags:
- docker
.gitlab-build.sh:
#!/bin/bash
set -eo pipefail
php -v
ping -c 3 mysql
php composer.phar install --no-progress --no-scripts
php artisan package:discover
cp -v .env.testing .env
php artisan key:generate
php artisan optimize
php artisan config:clear
php artisan storage:link
php artisan migrate --seed
php artisan jwt:secret
php artisan passport:install --force
.gitlab-ci.sh:
#!/bin/sh
set -eo pipefail
php -v
ping -c 3 mysql
./vendor/phpunit/phpunit/phpunit -v --testdox
What is Tests\TestCase? I'm guessing line 8 in DocumentTest.php is
public class DocumentTest extends TestCase
...where TestCase is PHPUnit\Framework\TestCase. It seems like there's an autoloading problem or the file doesn't import TestCase. Try changing this line to:
public class DocumentTest extends PHPUnit_Framework_TestCase
I can try to give a better answer if you include the phpunit.xml and composer.json.
I got the same error on local though. Make sure your composer.json has
"psr-4": {
"App\\": "app/",
"Tests\\": "tests/"
},
run composer dump-autoload at least once or make it a part of your testing procedure.

How to install a custom PHP extension on Travis (OAuth)

I'd like to install the PHP extension OAuth in my build environment on Travis.
I've tried these two configuration in .travis.yml file:
COnfiguration 1 (using before_script):
language: php
matrix:
include:
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: hhvm
cache:
directories:
- $HOME/.composer/cache
install:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
script:
- phpunit --verbose --coverage-clover build/logs/clover.xml
- phpenv config-rm xdebug.ini || return 0
before_script:
- pecl install oauth
Configuration 2 (using install):
language: php
matrix:
include:
- php: 5.3
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: hhvm
cache:
directories:
- $HOME/.composer/cache
install:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction
- pecl install oauth
script:
- phpunit --verbose --coverage-clover build/logs/clover.xml
- phpenv config-rm xdebug.ini || return 0
The documentation isn't clear about where to put the commands to install custom PHP extensions (or maybe I've not understood it, it's possible!).
Anyway, can someone help me configure Travis to install OAuth PHP extension? Thankyou!
Per Problems with PHP YAML within Travis CI it looks like the pecl install goes in the before_script section.
Per my own testing here https://travis-ci.org/davidjeddy/no-code/jobs/345523220 it appears that does the trick.

PHPUnit "Could not read phpunit.xml" on Travis CI

I am encountering a strange issue while trying to run PHP unit tests on Travis CI.
.travis.yml
sudo: false
language: php
php:
- 5.4
env:
- VUFIND_HOME=$PWD VUFIND_LOCAL_DIR=$PWD/local
before_script:
- pear install pear/PHP_CodeSniffer
- pear channel-discover pear.phing.info
- pear install phing/phing
- composer global require fabpot/php-cs-fixer
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- phpenv rehash
script:
- phpunit --stderr --configuration module/VuFind/tests/phpunit.xml
- phpunit --stderr --configuration module/Swissbib/tests/phpunit.xml
- phpcs --standard=PEAR --ignore=*/config/*,*/tests/* --extensions=php $PWD/module
- phing php-cs-fixer-dryrun
module/VuFind/tests/phpunit.xml is a third party framework
module/Swissbib/tests/phpunit.xml is our own code
module/Swissbib/tests/phpunit.xml
<phpunit bootstrap="Bootstrap.php">
<testsuites>
<testsuite name="sbvfrd">
<directory>.</directory>
</testsuite>
</testsuites>
</phpunit>
The tests from the third party framework run without errors. Our own tests do not work and we get the error message:
$ phpunit --stderr --configuration module/Swissbib/tests/phpunit.xml
Could not read "module/Swissbib/tests/phpunit.xml".
Locally (Mac OS X) all the tests run through. Strangely enough the Bootstrap.php defined in module/Swissbib/tests/phpunit.xml runs completely through on Travis CI, I verified this using echo statements. Nevertheless phpunit tells us that it could not read phpunit.xml.
Travis: https://travis-ci.org/swissbib/vufind
Repo: https://github.com/swissbib/vufind (development branch)
Any ideas what could be going wrong?
I found the solution by downloading the phpunit source and debugging with it.
We were changing the directory within the Bootstrap.php file to a different location then the phpunit command was run from. We run the phpunit command from our project root folder and then changed the working directory to the tests folder, because we were using relative paths. I changed everything to absolute paths (using __DIR__) so we do not have to change the working directory anymore.
Bottom line: Do not change the directory in the bootstrap file as it causes phpunit to fail with this error message: Could not read phpunit.xml.

Categories