1

I've got a small web application up and running, with phpunit testing included. It's built with composer, and has a pretty standard directory structure:

src/
    application files
tests/
    bootstrap.php
    test files
web/
    index.php
.travis.yml
composer.json
composer.lock
phpunit.xml

phpunit.xml contents:

<?xml version="1.0" encoding="UTF-8" ?>

<phpunit boostrap="./tests/bootstrap.php">
    <testsuites>
        <testsuite name="Chronos">
            <directory>./tests</directory>
        </testsuite>
    </testsuites>
</phpunit>

bootstrap.php contents:

<?php

require __DIR__ . "/../vendor/autoload.php";

My Problem

Running the following command works perfectly and my tests pass:

$ vendor/bin/phpunit
PHPUnit 4.8.26 by Sebastian Bergmann and contributors.

..

Time: 104 ms, Memory: 4.00MB

OK (2 tests, 2 assertions)

However, it fails when I run my globally installed version of phpunit:

$ phpunit
PHPUnit 4.8.26 by Sebastian Bergmann and contributors.

EE

Time: 117 ms, Memory: 4.00MB

There were 2 errors:

1) WelcomeTest::testReturnsAPayload
Error: Class 'Equip\Payload' not found

/Users/tony/Documents/projects/chronos/tests/Domain/WelcomeTest.php:13

2) WelcomeTest::testReturnsOkStatus
Error: Class 'Equip\Payload' not found

/Users/tony/Documents/projects/chronos/tests/Domain/WelcomeTest.php:13

FAILURES!
Tests: 2, Assertions: 0, Errors: 2.

It would seem that running the global installation of phpunit in my project's root directory does not include/resolve my phpunit.xml file (which specifies the autoloader). I get the same results on TravisCI.

Does anyone know why this is happening? I could just specify the local version of phpunit in my .travis.yml file, but I'd rather know what causes the difference here.

5
  • You should post the entire error message Commented Jul 17, 2016 at 22:46
  • Updated to include output Commented Jul 17, 2016 at 22:50
  • 1
    Please post the relevant parts of phpunit.xml. There could be a path-related issue on the bootstrap file. Post the bootstrap file (or command) as well. Commented Jul 18, 2016 at 18:54
  • Updated to include both phpunit.xml and bootstrap file Commented Jul 18, 2016 at 19:02
  • Thanks @MichaelBerkowski, you made me realize I had a typo in phpunit.xml Commented Jul 18, 2016 at 19:05

1 Answer 1

0

Ah I figured it out. Stupid typo in my phpunit.xml file (missing the t in "boostrap"). Turns out the composer version of phpunit automatically included the autoload so it worked fine, whereas the global phpunit WAS including phpunit.xml and thus not finding the bootstrap script.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.