I have a CakePHP project where I also integrated Travis-CI to start automated testing.
Now my tests look something like this:
<?php
App::uses('CustomControllerTest', 'Lib');
class AllocationsControllerTest extends CustomControllerTest
{...
My travis.yml:
language: php
php:
- '5.3'
before_script:
- composer install
- php bootstrap.php
script:
phpunit --configuration phpunit.xml --coverage-text
bootsrap.php is currently empty.
When triggering Travis it says it doesn't find Class'App'.
What do I have to add to the .travis.yml or bootstrap.php so it loads all the dependencies needed in the test classes?
Related
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.
I have installed PHP Unit and done everything the instructions tell me.
I'm told that I can just run:
$ phpunit
...and it will work. I may need to specify the config file and I can do that.
I have changed the directory to the PHP Unit folder, but nothing.
I am using Mac's Terminal if this means anything.
I have tried (with the error shown):
$ phpunit - $: command not found
phpunit - phpunit: command not found
php phpunit - ...doesn't return an error, but doesn't do return anything
% phpunit - fg: %: no such job
Also, the folder structure is like this:
- phpunit
- php-code-coverage
- php-file-iterator
- php-text-template
- php-timer
- php-token-stream
- phpunit
- phpunit-mock-objects
phpunit.php
- PHPUnit (folder)
- various things inside
... what am I actually running? The outer folder, inner folder or the phpunit.php file?
I must be doing something wrong?
My question: How'd you install PHPUnit? By "hand" (download it and just unzip it), via PEAR, ...?
Try executing (inside the phpunit folder):
./phpunit
Make sure the path where the phpunit executable lies is added to your $PATH variable.
A similiar question on SO on how to install phpunit can be found here, general installation instructions here.
I have a project that uses Composer to manage it's dependencies; one of them being PHPUnit.
To run my project's test suite, I run the following command on the terminal:
bin/phpunit -c tests/
Using the binary from the Composer PHPUnit version and setting the configuration file to be loaded from the tests/ directory.
It runs perfectly.
With Zend Studio 10 (BETA), though, I can't configure my project to run the tests the same way but inside the IDE.
Is there anyway to do that?
I have a project generated with Composer which has a dependency on PHPUnit. Now I have
dir1 -> PHPUnit stuff
dir2 -> project stuff
If I go into the project directory and run PHPUnit, it complains about loading ClassLoader.php twice:
PHPUnit requires it in vendors/autoload.php
The application code (bootstrap) requires it
How can I resolve this double-inclusion?
Make sure you're running the copy of PHPUnit being installed using Composer, which should be vendor/bin/phpunit. See composer.json, tests/composer.json, and the "Tests" section of README.md in this github repo for examples: https://github.com/phergie/phergie-irc-parser
From a certain composer version [citation needed], class loader got "namespaced" with a long name, thus enabling more composer based projects to work together, this is a non issue from that point on.
After a fresh symfony2 install i can run phpunit -c app/ and phpunit tests the included demo application: OK (1 test, 1 assertion).
But i receive no output (even with verbosity) when i run phpunit -c vendor/symfony/ as described here: http://symfony.com/doc/2.0/contributing/code/tests.html.
Does anyone know how to make this work?
PHPUnit: 3.6.2
PHP: 5.3.8
Symfony: 2.0.5
Testing twig, doctrine and other plugins works as expected (although doctrine tests fail for some reason).
If you have no output it's maybe because you configured php not to display errors.
You must install the vendors using the vendors.php script before lauching the Symfony test suite:
$ php vendor/symfony/vendors.php
Are you running the tests using the provided phpunit.xml.dist configuration file?
From your projects root directory:
$ phpunit --configuration app/phpunit.xml.dist vendor/symfony/tests
That should add an autoloader for vendors.