jeudi 26 avril 2018

Why would PHPUnit fail at resolving a classname if using a xml config file?

I wrote a extremely basic class and accompanying test to play around.

The project is completely bare, it only requires-dev phpunit/phpunit (output for vendor/bin/phpunit --version' is "PHPUnit 7.1.4".

The tested class and actual tests are immaterial (one class, one method and two tests; but no substance to them).

Since this was a very quick test, both class and tester class are laying around in the root path.

- DummyClass.php
- DummyClassTest.php
- bootstrap.php
- vendor/

bootstrap.php simply contains:

require_once dirname(__FILE__)  .'DummyClass.php';
require_once dirname(__FILE__)  . "/vendor/autoload.php";

I'm only requiring DummyClass.php since it's not autoloadable, and then composer's autoloader.

If I execute the test like this:

vendor/bin/phpunit --bootstrap=bootstrap.php DummyClassTest.php

Everything works. Tests are executed, life is good.

But if I create a phpunit.xml file at the same level with this content:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.0/phpunit.xsd"
         bootstrap="bootstrap.php"
         verbose="true">
    <testsuite name="dummy">
        <directory suffix="Test.php">./</directory>
    </testsuite>
</phpunit>

It will fail complaining about not finding PHPUnit_Framework_TestCase:

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /project/path/vendor/phar-io/manifest/tests/ManifestDocumentMapperTest.php on line 45

Why does it stop working if I use a configuration file, if it works perfectly fine without one? What is it being broken by my config file?

Aucun commentaire:

Enregistrer un commentaire