MidnightCoder MidnightCoder - 6 months ago 58
PHP Question

PHPUnit (Phar) Fatal Error Only When Test Fails

I have chosen to use a

Phar
of
PHPUnit
(phpunit-4.8.26.phar) to unit test my custom built PHP Framework and Application. The reason I am using the old stable release is because I need compatibility with
PHP 5.4.29
.

The reason I have chosen not to use
Composer
to get PHPUnit is because it's tends to pollute my
vendors
folder with dependencies. I like to keep it as lean as possible.

I am using
Windows 7 Pro SP1
,
WampDeveloper v5.4.0.1
,
ProPhpStorm 2016.1.2
,
Phing
and a whole bunch of other cool stuff to do my thing.

The Problem




  • I CAN run a passing unit test successfully from within PhpStorm.

  • I CAN run a group of passing unit tests successfully from within PhpStorm.

  • I CAN NOT run a FAILING unit test successfully from within PhpStorm.

  • I CAN run a passing unit test successfully from the command line.

  • I CAN run a group of passing unit test successfully from the command.

  • I CAN NOT run a FAILING unit test successfully from the command line.



Instead of
PHPUnit
display a typical test failure message it exits with the below errors:


Warning: require(Composer\Autoload\ClassLoader.php): failed to open
stream: No such file or directory in
D:\WampDeveloper\Websites\qclean.development\bootstrap\Autoloader.php
on line 23

Fatal error: require(): Failed opening required 'Composer\Autoload\ClassLoader.php'
(include_path='.;D:\WampDeveloper\Tools\PEAR\pear;D:\WampDeveloper\Tools\PEAR;D:\WampDeveloper\Components\Php\PEAR;D:\WampDeveloper\Tools\PHPMailer;')
in
D:\WampDeveloper\Websites\qclean.development\bootstrap\Autoloader.php
on line 23


And a screen shot to expand on the above:

enter image description here

Supporting Info



My directory structure:

enter image description here

My unit test script ('ConfigurationTest.php'):

enter image description here

My PHPUnit XML configuration file ('TestAll.xml'):

enter image description here

And lastly my Autoloader ('Autoloader.php'):

enter image description here

The error and warning indicate the inability to load the
Composer\Autoload\ClassLoader.php
file. What I don't understand is why it is asking for this file when I am using a
Phar
? Reading snippets off the internet indicate the Phar should have an internal autoloader though I am unable to see one.

I do not want to have to install
Composer
just to get it's autoloader. That would defeat the purpose of trying to solely use the Phar.

I added the
PHPUnit Phar
path to my Windows
%path%
but this did not make any difference. I understand that this should be done if PHPUnit was installed using
PEAR
.

Any help on this 'hair pulling out matter' would be greatly appreciated...

Answer

All what you need to do it to go to Settings > Language & Frameworks > PHP > PHPUnit and Choose PHPUnit library - and set path to phpunit.phar, that's all.

enter image description here