Does Travis CI Check more than one .travis.yml file? - phpunit

I'm just starting with Continuous Integration using Travis CI.
I have this file at the TLD of my repo:
sudo: false
language: php
php:
- '7.1'
This is how Travis CI sees my config:
{
"os": "linux",
"php": "7.1",
"dist": "trusty",
"sudo": false,
"group": "stable",
"language": "php",
}
Why is the build failing with a phpunit error? Could it be because of another .travis.yml file within the repo?
Network availability confirmed.
...edited for brevity...
git.checkout
0.34s$ git clone ...edited for brevity...
$ php --version
PHP 7.1.11 (cli) (built: Oct 26 2017 16:25:55) ( ZTS )
Copyright (c) 1997-2017 The PHP Group
...edited for brevity...
$ composer --version
Composer version 1.6.5 2018-05-04 11:44:59
0.15s$ phpunit
PHPUnit 6.4.3 by Sebastian Bergmann and contributors.
Usage: phpunit [options] UnitTest [UnitTest.php]
phpunit [options] <directory>
...edited for brevity...
The command "phpunit" exited with 2.
Done. Your build exited with 1.
I'm not sure where to look next.

phpunit exits with an error because you haven't told phpunit where to look for your tests. Typically you would do this by placing phpunit.xml in the base directory of your repo. Among other things, phpunit.xml tells phpunit which directory contains your tests.
Your phpunit.xmlshould contain something like this:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<testsuites>
<testsuite name="Your application name">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
Replace ./tests/ with the relative path to the folder containing your test files.
To test out your configuration, run phpunit while in the base directory of your repo. You should see the same result that Travis CI does.

As per the docs, "Travis CI uses .travis.yml file in the root of your repository to learn about your project and how you want your builds to be executed."
It wants something to run and defaults to running phpunit, which will fail without at least one test to run.
So for a placeholder build one could create a bash script in the same directory as the .travis.yml file, make it executable and point to it like this:
sudo: false
language: php
php:
- '7.1'
before_install:
- chmod +x build.sh
script: ./build.sh
This is a "build" script:
#!/usr/bin/env bash
echo This is a placeholder.

Related

GitLab Runner stopping after `dotnet restore` or `dotnet test`

I am new to CI and tried to add the following yaml to our project.
image: microsoft/dotnet:latest
stages:
- test
test:
stage: test
before_script:
- 'echo Stage - Test started'
- 'dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools'
script:
- 'cd "./My Project"'
- 'dotnet test --settings:./Settings/CodeCoverage.runsettings --collect:"XPlat Code Coverage"'
- './tools/reportgenerator "-reports:./Tests/*/TestResults/*/coverage.cobertura.xml" "-targetdir:Reports_Coverage" -reportTypes:TextSummary'
- 'cat ./Reports_Coverage/Summary.txt'
after_script:
- 'echo Stage - Test finished'
On the job I get the following output:
Running with gitlab-runner 13.7.0 (943fc252) on ***
Resolving secrets
Preparing the "kubernetes" executor
Using Kubernetes namespace: gitlab-pipeline
Using Kubernetes executor with image microsoft/dotnet:latest ...
Preparing environment
Running on*** via ***...
Getting source from Git repository
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/***/.git/
Created fresh repository.
Checking out 07e98444 as ***...
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ echo Stage - Test started
Stage - Test started
$ dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools
You can invoke the tool using the following command: reportgenerator
Tool 'dotnet-reportgenerator-globaltool' (version '4.8.4') was successfully installed.
$ cd "./My Project"
$ dotnet test --settings:./Settings/CodeCoverage.runsettings --collect:"XPlat Code Coverage"
Running after_script
Running after script...
$ echo Stage - Test finished
Stage - Test finished
Cleaning up file based variables
ERROR: Job failed: command terminated with exit code 1
I tinkered around a little bit and realized, that this minified yaml also fails:
image: microsoft/dotnet:latest
stages:
- test
test:
stage: test
before_script:
- 'cd "./My Project"'
- 'dotnet restore'
script:
- 'dotnet test --no-restore'
This generates an equal output, except it stops at dotnet restore.
I honestly don't know what to do, since this is the most minified version of a test I found.
Did I mess up something within the project, or is the problem within the GitLab Runner itself?
Project Version: .net Core App 3.1
Not a real solution, but I found the issue behind this. You can set the verbosity level of the dotnet test command (documentation). While doing so, I found out that you obviously cannot run a WPF project within a Linux based GitLab Runner.

#PHPUnit Testing simple Code in this Link:https://phpunit.de/getting-started/phpunit-8.html

Hello I am new in PHPUnit and try to execute the Test Example:EmailTest by Composer, the Link is: https://phpunit.de/getting-started/phpunit-8.html
I got the text in the command_Line
$ phpunit --bootstrap vendor/autoload.php tests/EmailTest
PHPUnit 3.7.21 by Sebastian Bergmann.
Cannot open file "vendor/autoload.php".
It appears that you have different installations of PHPUnit mixed up.
For instance, you may have used Composer to install PHPUnit and have configured the autoloader generated by Composer as PHPUnit's bootstrap script but then you invoke PHPUnit using an executable other than vendor/bin/phpunit.

Use local phpunit if installed otherwise fall back to global

I have PHPUnit version 5.3.2 installed via composer globally, and version 5.7.19 installed locally in my project. I can run global PHPUnit just by typing phpunit and local by vendor/bin/phpunit.
Is there a way to configure PHPUnit to by default run local installation if it exists, or otherwise fall back to global installation so I don't have to use vendor/bin/phpunit each time?
The only solution I came up so far is creating a bash script phpunit in project directory:
#!/bin/bash
vendor/bin/phpunit $#
But then I have to type ./phpunit anyway.
Looks like I wasn't that far. So I added following to my .bashrc
original_phpunit=$(which phpunit)
phpunit() {
if [ -f vendor/bin/phpunit ]; then vendor/bin/phpunit $#
else eval "'$original_phpunit' $#"
fi
}
And now it works as I wanted. Hope someone will find it useful!

Laravel 5: PHPUnit and no code coverage driver available

I would like to use PHPUnit to create code coverage reports. I have tried a lot of installation setups found on the web. But nothing seems to work out.
I use the latest version of Laravel 5 (>5.2) and PHPUnit v. 5.0.10. Further, I use MAMP on Mac OS X 10.9.5 running PHP 7.
When I run PHPUnit that is integrated in my Laravel distribution, I receive the following error.
$ vendor/bin/phpunit -v
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.
Runtime: PHP 7.0.0
Configuration: /Applications/MAMP/htdocs/myProject/phpunit.xml
Error: No code coverage driver is available`
My composer file looks like:
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "5.0.*",
"phpunit/php-code-coverage": "^3",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
},
I have also tried the following command:
/Applications/MAMP/bin/php/php7.0.0/bin/phpdbg -qrr ../../../htdocs/myProject/vendor/bin/phpunit -v
This seems to set up the code coverage driver well, but it ends up in an exception:
$ /Applications/MAMP/bin/php/php7.0.0/bin/phpdbg -qrr ../../../htdocs/myProject/vendor/bin/phpunit -v
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.
Runtime: PHPDBG 7.0.0
Configuration: /Applications/MAMP/htdocs/myProject/phpunit.xml
[PHP Fatal error: Uncaught ErrorException: include(/Applications/MAMP/htdocs/myProject/app/Exceptions/Handler.php): failed to open stream: Too many open files in /Applications/MAMP/htdocs/myProject/vendor/composer/ClassLoader.php:412
Stack trace:
...
The phpunit.xml looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="./tests/codeCoverage" charset="UTF-8"/>
</logging>
<filter>
<whitelist>
<directory suffix=".php">app/</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>
Is it possible to use PHPUnit that comes with the Laravel framework together with code coverage? How should I set it up and use it?
Thanks a lot for your help.
It seems like you are missing the Xdebug extension. If you're using homebrew you can install it like:
brew install php70-xdebug
After that, don't forget to edit your php.ini file to enable the extension.
php -i | grep xdebug
After checking that xdebug is enabled you should be able to do code coverage
Update for anyone else stuck;
pecl install xdebug
For windows users:
1) Download xdebug
2) Rename the file to _php_xdebug.dll_ and copy the file to the ext folder in your php installation e.g C:\Program Files (x86)\php\ext
3) Open your php.ini file. For me it’s available at C:\Program Files (x86)\php\php.ini.
4) Paste the below code at the bottom of the file.
zend_extension = php_xdebug.dll
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.remote_autostart = 1
xdebug.remote_port = 9000
xdebug.show_local_vars = 1
Update for PHP 7.1
xdebug is essential for code lookup and coverage , so xdebug is must to be installed or enabled in test environment. xdebug in production environment is not suggestible, it will affect performance if you turned on
brew install php71-xdebug
As other developers answered, you need to install PHP Xdebug but I want to add new recommend for the developers who are using homestead by default have Xdebug (but it is off) and you can make it ON or OFF
If you want to make it on use below command in homestead
#for on :
xon
#for off:
xoff
Then check php -v and you will see Xdebug in the detail box
it's worked for me. follow this step :
1.) install php7.x-dev, (x) is PHP version on your Linux server
sudo apt-get install php7.x-dev
2.) install Xdebug through PECL on Linux
sudo pecl install xdebug
3.) add the following php.ini file. (you can insert it on last line)
zend_extension="/wherever/you/put/it/xdebug.so"
If you run phpunit inside a vagrant box then you don't need to install xdebug in local and homestead comes with xdebug install automatically. only needs to link homestead xdebug.ini file
Here is the step that worked for me:
cd ~/homestead/REPLACE THIS WITH YOUR HOMESTEAD FOLDER IN LOCAL //
vagrant ssh
sudo ln -s /etc/php/7.2/fpm/conf.d/20-xdebug.ini /etc/php/7.2/cli/conf.d/
In the above command if your running 7.3 or 7.1 then replace it based on your php version
To Reproduce, kindly follow the solution(s) below;
Steps to reproduce the behavior if you don't have Xdebug activated already:
Inside your project root directory open your CMD terminal and type php -i
A list of important information concerning your php will be listed in the CMD terminal
Copy and paste the output here https://xdebug.org/wizard
After you paste the output, click on the button Analyse my phpinfo() output to proceed
Follow the instructions to the latter after your redirect to the Summary page
After you are done with the installation, type php -v to confirm that Xdebug is activated successfully.
If you already have Xdebug activated, follow these steps get test coverage running;
Type ./vendor/bin/phpunit --coverage-html tests/coverage into the CMD terminal to generate the test coverage
After it is done with running the tests successfully, the coverage report of the tests will be in the project_dir/tests/coverage directory
Inside the project_dir/tests/coverage directory, click on the index.html file to open and view the general report of the project's phpunit test coverage
NB:
I worked in Laravel ^6.0
Tested in Windows 10 environment but can be replicated in other environments
I am having
PHP 7.1.33, Centos 7, PHPUnit 5.7.27
and this works for me
$ yum install gcc
$ pecl install xdebug-2.9.0
Build process completed successfully
Installing '/usr/lib64/php/modules/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.9.0
configuration option "php_ini" is not set to php.ini location
You should add "zend_extension=/usr/lib64/php/modules/xdebug.so" to php.ini
Proceeding after that
Find position of php.ini file
$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
Add Xdebug config
$ vi /etc/php.ini
Add this at the end
zend_extension=/usr/lib64/php/modules/xdebug.so
Check if Xdebug is installed
$ php -ini|grep 'xdebug support'
xdebug support => enabled

PHPunit, Symfony2 & AWS SDK - Can't load APC or xcache

I've hit a roadblock with my phpunit functional tests. The AWS SDK requires APC, for some reason I can't get phpunit to load the extension. I'm not sure where I'm going wrong. The CLI is using the same ini file as MAMP
Gregs-MacBook-Pro:HvH-PHP greg$ php --ini
Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php5.3.6/conf
Loaded Configuration File: /Applications/MAMP/bin/php/php5.3.6/conf/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Gregs-MacBook-Pro:HvH-PHP greg$
I've also attempted to add the ini file into app/phpunit.xml.dist
<php>
<ini name="mamp" value="/Applications/MAMP/bin/php/php5.3.6/conf/php.ini"/>
<server name="KERNEL_DIR" value="app/" />
</php>
Error message in CLI
PHP Fatal error: Call to undefined function apc_fetch() in /vendor/aws-sdk-for-php/lib/cachecore/cacheapc.class.php on line 58
EDIT: Some more test as per comments
In CLI I can run a test script with apc_fetch(); and it works successfully.
Running php -m also shows APC as an installed module
Any suggestions as to what else I should try?
I could propose you 2 solutions:
Create a symlink of /Applications/MAMP/bin/php/php5.3.6/conf/php.ini to /private/etc/php.ini
Modify phpunit execution file and append -c /Applications/MAMP/bin/php/php5.3.6/conf/ to the php run command. Also - check if correct php binary is used. If it is not - change to the correct path first and check if issue has been fixed

Resources