1
votes

I am having some trouble running PHPUnit from Travis.

My travis configuration is simple

language: php
php:
  - 7.0
  - 7.1
script: phpunit

And my phpunit.xml is as follows,

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php">
    <testsuites>
        <testsuite name="Basic Test Suite">
            <directory suffix=".php">./tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>

And my composer.json

{
    "name": "nikhilkuria/nikeandphp",
    "description": "A PHP library used to work with Nike+ API",
    "type": "library",
    "authors": [
        {
            "name": "nikhilkuria",
            "email": "[email protected]"
        }
    ],
    "require": {
        "monolog/monolog": "^1.22"
    },
    "require-dev": {
      "phpunit/phpunit": "5.7.*"
    },
    "autoload": {
        "psr-4": {"NikeAndPhp\\": "src/NikeAndPhp"}
}
}

The problem is that Travis is not able to find my autoload.php. This is what i see in travis logs,

Cannot open file "/home/travis/build/nikhilkuria/nikeandphp/vendor/autoload.php".

The entire logs are here.

What seems to be missing here?

3
The link to the entire logs doesn't worktschale

3 Answers

7
votes

As I can see from your log output you're not running composer install command, that's why you're getting Cannot open file "/home/travis/build/nikhilkuria/nikeandphp/vendor/autoload.php". error message.

Add

before_script:
    - composer install
6
votes

Aside from the fact that your Travis configuration is missing the composer install step there is also something wrong with the way you install PHPUnit.

script: phpunit means that you invoke PHPUnit using the globally installed PHPUnit that is available as phpunit on the $PATH. You most likely do not want that as you have listed PHPUnit as a development dependency in your composer.json. To use the PHPUnit installed using Composer you need to use script: ./vendor/bin/phpunit instead.

0
votes

Individual bin-path

for the case that in composer.json an individual bin-path is defined, the path to phpunit has to be adjusted accordingly.

composer.json:

{
  ...
  "config": {
    "vendor-dir": ".Build/vendor",
    "bin-dir": ".Build/bin",
  },
  ...
}

.travis.yaml:

language: php  
...
script:
  - >
    echo;
    echo "Running unit tests";
    .Build/bin/phpunit --colors  -c .Build/vendor/.../UnitTests.xml
...