PHPUnit - Error?

I'm new to PHPUnit. Can someone tell me what this means?

Class 'PHPUnit_Framework_MockObject_Matcher_InvokedRecorder' not found

39 comments

Hi Keith,

I'm new to PHPUnit. Can someone tell me what this means?

Class 'PHPUnit_Framework_MockObject_Matcher_InvokedRecorder' not found

That means that file which contains that class cannot be found on your PHPUnit installation (I know -- it's obvious ... but you asked :p ).


It sounds like you have PHPUnit v3.5 installed over 3.4.x (or your PHPUnit installation is somehow incomplete/broken).

Have a look at this link: http://sebastian-bergmann.de/categories/14-PHPUnit; these posts in particular:
http://sebastian-bergmann.de/archives/899-PHPUnit-3.5-Upgrading-Woes.html#content & http://sebastian-bergmann.de/archives/897-PHPUnit-3.5.html#content

Please ensure that you have this file present (where that class should be located): PHPUnit\Framework\MockObject\Matcher\InvokedRecorder.php

0

Yes, I have that file.

PHPUnit v3.5 installed over 3.4.x

Well, I did upgrade using the PEAR upgrade-all command.

0

Here's one thing I don't understand. One of those sites says I'm supposed to not include Framework.php, but instead include Autoload.php. Which I'm doing in my test file here:

require_once 'PHPUnit/Autoload.php';

Yet, that file does not exist in my PHPUnit folder.

And I don't get an error (maybe the other fatal error is before this.)

0

Ok, so I thought I would start over. I uninstalled PHPUnit

pear uninstall pear.phpunit.de/PHPUnit

Now, I cannot install PHPUnit:

c:\PHP>pear install phpunit/PHPUnit
Failed loading
Unknown remote channel: components.ez.no
Unknown remote channel: components.ez.no
phpunit/PHPUnit can optionally use PHP extension "dbus"
phpunit/PHPUnit can optionally use PHP extension "soap"
phpunit/PHP_CodeCoverage requires package "channel://components.ez.no/ConsoleToo
ls" (version >= 1.6)
phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2
.0.5)
phpunit/PHPUnit requires package "phpunit/PHP_CodeCoverage" (version >= 1.0.2)
phpunit/PHP_TokenStream requires package "channel://components.ez.no/ConsoleTool
s" (version >= 1.6)
No valid packages found
install failed

0

I assure you -- that file (PHPUnit/Autoload.php) should exist.

I recommend these steps (works like a charm for me -- but I do have only few simple tests right now):

pear uninstall phpunit/PHPUnit
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear install phpunit/PHPUnit

After that:
pear list -c phpunit

And that what shoudl be there:

INSTALLED PACKAGES, CHANNEL PEAR.PHPUNIT.DE:
============================================
PACKAGE            VERSION STATE
DbUnit             1.0.0   stable
File_Iterator      1.2.3   stable
PHPUnit            3.5.4   stable
PHPUnit_MockObject 1.0.2   stable
PHPUnit_Selenium   1.0.1   stable
PHP_CodeCoverage   1.0.2   stable
PHP_Timer          1.0.0   stable
PHP_TokenStream    1.0.1   stable
Text_Template      1.0.0   stable
0

As far as the installation problem goes, this fixed it:

pear channel-discover components.ez.no

Why in the heck is that not in the install guide?

0

I do not want to disappoint you, but it is present in the manual:
http://www.phpunit.de/manual/current/en/installation.html

Also look at my first reply here: I have posted a few links, the last of them has it (precise instructions) as well:
http://sebastian-bergmann.de/archives/897-PHPUnit-3.5.html#content


You must be tired...

0

I was looking at the installation page for the wrong version (never seen installation instructions change so much from version to version):

http://www.phpunit.de/manual/3.0/en/installation.html

0

Now getting a whole new set of errors:

C:\PHP\php.exe C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php -config C:\Inetpub\Intranet_Local\phpunit\configuration.xml c PHPToJSTest C:\Inetpub\Intranet_Local\phpunit\library\classes\PHPToJSTest.php
Testing started at 3:59 PM ...
E_WARNING: include_once(C:\Inetpub\Intranet_Local\phpunit): failed to open stream: Permission denied
#0 C:\PHP\PEAR\PHPUnit\Util\Fileloader.php(103): load()
#1 C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php(543): load()
#2 C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php(743): main()
E_WARNING: include_once(): Failed opening '' for inclusion (include_path='.;C:\PHP\PEAR\pear;C:\PHP\pear;C:\inetpub\3rd Party Apps\fckeditor;C:\inetpub\3rd Party Apps\zf\library;')
#0 C:\PHP\PEAR\PHPUnit\Util\Fileloader.php(103): load()
#1 C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php(543): load()
#2 C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php(743): main()
Empty test suite.

Process finished with exit code 0

0

Again, I HATE this forum editor (http://devnet.jetbrains.net/thread/292063?tstart=0.) This post was not meant to be threaded where I put it the first time.

-----------------------------------------------------

The above errors appear to be caused by the name of my bootstrap file not loading in the configuration:

PHPUnit_Util_Fileloader::load($phpunitConfiguration['bootstrap']);

0

How do you launch the test -- from PhpStorm or via command line ? I can run my simple tests using both methods with no issue.

It sound like you have to change your corrent directory -- see these threads:
http://devnet.jetbrains.net/message/5275424
http://devnet.jetbrains.net/message/5262409

0

From PHPStorm, but I'll try the command line. I don't think it's even loading my configuration.xml file properly. See this:

E_WARNING: include_once(): Failed opening '' for inclusion (include_path='.;C:\PHP\PEAR\pear;C:\PHP\pear;C:\inetpub\3rd Party Apps\fckeditor;C:\inetpub\3rd Party Apps\zf\library;')

It's referring to my bootstrap property, and it's indicating that that value is blank.

This is my configuration.xml file:

<?xml version="1.0"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->

<!-- see http://www.phpunit.de/wiki/Documentation -->
<phpunit bootstrap="/phpunit/bootstrap.php"
         colors="false"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         stopOnFailure="true">
</phpunit>

I read the posts you indicate, and I've tried different combinations of where the files were located and working directory settings, but nothing works.

0

I get a different error from running it from command line.

c:\PHP>phpunit -config C:\Inetpub\Intranet_Local\phpunit\configuration.xml m tes
tOtherFunction PHPToJSTest C:\Inetpub\Intranet_Local\phpunit\PHPToJSTest.php
Failed loading
PHP Fatal error:  Uncaught exception 'PHPUnit_Framework_Exception' with message
'Could not read "onfig".' in C:\PHP\PEAR\PHPUnit\Util\Configuration.php:212
Stack trace:
#0 C:\PHP\PEAR\PHPUnit\TextUI\Command.php(620): PHPUnit_Util_Configuration::getI
nstance('onfig')
#1 C:\PHP\PEAR\PHPUnit\TextUI\Command.php(138): PHPUnit_TextUI_Command->handleAr
guments(Array)
#2 C:\PHP\PEAR\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Arra
y, true)
#3 C:\PHP\phpunit(53): PHPUnit_TextUI_Command::main()
#4 {main}
  thrown in C:\PHP\PEAR\PHPUnit\Util\Configuration.php on line 212
0

I abandoned trying to learn PHPUnit once before. It's just too complicated to setup. I know we need to start

using it, but it's so time consuming just trying to make it work, much less all the time we'll have to spend learning how to and writing tests.                         

0

After further review, the installation is still not working and I've followed the directions exactly several times. I am missing this file:

PHPUnit_Extensions_SeleniumTestCase

It was there at one point, but now it's not and no amount of re-installing is bring it back.

0

Ok, it is loading the configuration.xml file correctly. Still, I don't know why it's trying to include '' on one line and it appears that it's
getting permission denied when trying to access my boostrap.php file???? good grief,

0

Hi Keith,

What is phpunit -config ?  Maybe you still using old syntax (unsure), but I cannot find such switch in PHPUnit v3.5. I guess you meant:

phpunit --configuration



Can you try to run a test without any config files? Can you create brand new simple test and run it -- without any config file or bootstrap file? If it's successful, then add some config file, then add bootsrtrap file, then test your real file (but very simple test), and only then you can use already existing tests.


I'm not using any config or bootstrap files (I guess I should, but I did not bother). Obviously, in such scenario I need to make sure that my own classes can be found/loaded. For this reason I'm including my own autoloader on the top of each test file. Something like:

<?php
require_once 'E:\Projects\web\Core\Loader.php';
cfLoader::registerAutoload();

class CreditCardTest extends PHPUnit_Framework_TestCase
{
.....

0

Do not give up -- I believe you can handle it ;).

0

Sorry, that was copying and pasting from PHPStorm, I fixed, but it still won't work.

So, I'm trying a more simplified test.

c:\PHP>phpunit C:\Inetpub\Intranet_Local\phpunit\PHPToJSTest.php
Failed loading
PHP Fatal error:  Class 'adLDAP' not found in C:\Inetpub\Intranet_Local\library\
common.php on line 701

It's not registering my autoloader:

//************************************************************************************************************
function __autoload($sClassName){

if(substr($sClassName, 0, 5) == 'Apps_') $sClassName = str_ireplace('Apps_', 'apps/', $sClassName);

if(file_exists(_DOCROOT.'/library/classes/'.$sClassName.'.php'))
  require_once _DOCROOT."/library/classes/$sClassName.php";
elseif($sClassName == "Zend_Loader_Autoloader") require_once 'Zend/Loader/Autoloader.php';
//This works too for ZF
//  require_once 'c:\Inetpub\3rd Party Apps\zf\library\Zend\Loader\Autoloader.php';
elseif(file_exists("c:/PHP/PEAR/".str_replace("_", "/", $sClassName).".php"))
  require_once "c:/PHP/PEAR/".str_replace("_", "/", $sClassName).".php";

}

Why is that? Doesn't it register the autoloader automatically as usual? Do I have to call the autoloader manually?

My problem with this whole setup is that it makes me have to have two different configurations: one for DEV/PROD and one for testing. If I can't test my environment, like I run it, what's the point?

I am seriously thinking of writing my own unit testing procedure/protocol.

0

From what I've read, __autoload() does not work with CLI. I'm assuming that is why this doesn't work.

We work in heavily integrated environment - classes call many other classes. __autoload() is central to our enviroment.

0

Hi Keith,

http://uk3.php.net/manual/en/function.spl-autoload-register.php -- that is how I'm doing it -- I do not know why it's not triggering your __autoload() implementation.

RE: different setup to production environment.
I'm using PHPUnit for testing individual classes/functions/simple scenarios, not the whole application/complex scenarios. And so far I have only seen it used elsewhere for the same purposes (and I'm not claiming that I've seen a lot). I do not have any knowledge or information about how PHPUnit can be used to test the whole application.

I may recommend to look for some open source PHP applications and see how they done it (for example: Yii framework, Swift Mailer, Zend Framework, maybe WordPress (if they actually do this) etc).

Alternatives:
http://www.opensourcetesting.org/unit_php.php
http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#PHP

0

Ok, this seems to solve the autoload issue. Added this line to my common.php, which has to load with every page we run:

spl_autoload_register("__autoload");

0

I am using to test individual classes, like you suggest, but even with those, they are heavily integrated and

call upon many different resources, so it's not so simple to just call a class without loading the environment (maybe it needs to be separated more, but if that has to happen first, we might never start unit testing.)

0

Well, I can only advise then to ask this sort of question (how to test whole app/heavily integrated classes) on much crowded place -- like stackoverflow.com for example. At least there will be more than one person involved in discussion + you can find more knowledgeable people who may give you better advice on how it can be achieved with PHPUnit or point you to a more suitable tool.

EDIT:
http://www.phpunit.de/wiki/WhoUsesPHPUnit -- These guys do use PHPUnit -- it's a good idea to ask on their site/forum for an advice.

0

Ok, I have got the thing working. However, I really need the configuration.xml and bootstrap.php

files. We use the same configuration, but the folder name changes, among other things (like $_SERVER variables are not available, and so I have to create these manually.) I still get tons of errors when I try to use it, but the tests still work:

E_WARNING: include_once(C:\Inetpub\Intranet_TEAM1\phpunit): failed to open stream: Permission denied
#0 C:\PHP\PEAR\PHPUnit\Util\Fileloader.php(103): load()
#1 C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php(543): load()
#2 C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php(743): main()


E_WARNING: include_once(): Failed opening '' for inclusion (include_path='.;C:\PHP\PEAR\pear;C:\PHP\pear;C:\inetpub\3rd Party Apps\fckeditor;C:\inetpub\3rd Party Apps\zf\library;')
#0 C:\PHP\PEAR\PHPUnit\Util\Fileloader.php(103): load()
#1 C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php(543): load()
#2 C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php(743): main()


E_WARNING: Cannot modify header information - headers already sent by (output started at C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php:241)
#0 C:\Inetpub\Intranet_Local\library\common.php(19): header()
#1 C:\Inetpub\Intranet_Local\phpunit\library\class\apps\Apps_Steps75Test.php(8): require_once()
#2 C:\PHP\PEAR\PHPUnit\Util\Fileloader.php(103): include_once()
#3 C:\PHP\PEAR\PHPUnit\Util\Fileloader.php(85): load()
#4 C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php(459): checkAndLoad()
#5 C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php(628): collectTestsFromFile()
#6 C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php(743): main()

0

Oh, and that -config you were asking me about, I got that from PHPStorm. This is the exact command it runs:

C:\PHP\php.exe C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php -config C:\Inetpub\Intranet_Local\phpunit\configuration.xml m testOtherFunction PHPToJSTest C:\Inetpub\Intranet_Local\phpunit\library\class\PHPToJSTest.php

0

Ok, I figured it out, but the solution doesn't really help. This is my configuration.xml file:

<?xml version="1.0"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->

<!-- see http://www.phpunit.de/wiki/Documentation -->
<phpunit bootstrap="c:\Inetpub\Intranet_Local\phpunit\bootstrap.php"
         colors="false"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         stopOnFailure="true">
</phpunit>

Also, the actual run configurations are designed to be shared.

Both of these have the problem that the directory name indicated above will change.

Man, this is a lot of overhead to make this work in a team environment.

0

Hi Keith,

Well ... this command, as I understand, is run by PhpStorm -- this is how it actually look behind the pretty interface: C:\Users\keithdavis\AppData\Local\Temp\phpunit_Intranet_Local_keithdavis.php is a custom test runner which runs tests and reports results back to PhpStorm so that we can see them nicely presented in that PHPUnit tool window. And -config is a custom command/parameter which has nothing to do with phpunit command/file.

I'd storngly advice not to use this command manually as that phpunit_Intranet_Local_keithdavis.php file can be autogenerated (and therefore be different) for each run. You should either use PhpStorm GUI or phpunit command from command shell (with appropriate parameters).

0

I got the __autoload to work by calling spl_autoload_register ()

0

Please sign in to leave a comment.