Must PHPUnit require Composer\Autoload\ClassLoader.php? -


trying integrate phpunit , ide (phpstorm 2017.2). i'm executing phpunit.phar file directly (version 5.7.21) don't use composer , don't have installed.

phpunit.xml

<phpunit bootstrap="phpunit-bootstrap.php">     <testsuites>         <testsuite name="test suite">             <directory>./</directory>         </testsuite>     </testsuites> </phpunit> 

phpunit-bootstrap.php

spl_autoload_register('my_autoload');  /**  * @param string $classname qualified name autoload  */ function my_autoload($classname){     require $_server['document_root'] . "\\$classname.php"; } 

this autoloader works fine when execute project files. when try run phpunit test, see error:

fatal error: require(): failed opening required '\composer\autoload\classloader.php'

if remove autoload, project classes can no longer found (same error, different class name).

does phpunit depend on composer being installed globally , available on system path?

update 1

following kuba's suggestion in comments, changed autoload to:

require __dir__ . "\\$classname.php"; 

new error:

fatal error: require(): failed opening required 'c:\project-root\composer\autoload\classloader.php'

i needed adjust autoloader nothing when php tried load composer\autoload\classloader.php. changed autoloader from:

function my_autoload($classname){     require __dir__ . "\\$classname.php"; } 

to

function my_autoload($classname){     $path = __dir__ . "\\$classname.php";     if (file_exists($path)) require $path; } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -