phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

assertEquals for strings gives strange error when strings are not equal

Open isokissa opened this issue 12 years ago • 5 comments

I am happily using phpunit 4.1.1.

Is it normal that

$this->assertEquals( "asd", "asdf" ); 

gives this kind of error:

PHP Fatal error:  Call to undefined function phpunit_mockobject_autoload() in .../PHPUnit/Util/GlobalState.php on line 378

I tried also with numbers, when they are equal, it's ok, but if they are different, then I get the strange "undefined function phpunit_mockobject_autoload()". To me looks like basic functionality got broken for some reason. My phpunit was installed with composer, so I presume all the dependent packages should be consistent with each other.

isokissa avatar May 24 '14 18:05 isokissa

The phpunit_*_autoload() functions were removed a long time ago. You probably have stale files from an old installation lying around.

sebastianbergmann avatar May 24 '14 18:05 sebastianbergmann

I installed phpunit with composer, and today upgraded to phpunit 4.1.1. I was hoping that it will remove the old stuff completely.

Is there an elegant way to get rid of those stale files? When installing with composer, I pretty much have no idea what it did and where.

And btw, Sebastian, thanks for quick reply, and everything you are doing, great job indeed! :)

Here is what gives me the "composer.phar show" command:

installed: phpunit/php-code-coverage 2.0.6 Library that provides collection, processing, and rendering f... phpunit/php-file-iterator 1.3.4 FilterIterator implementation that filters files based on a l... phpunit/php-text-template 1.2.0 Simple template engine. phpunit/php-timer 1.0.5 Utility class for timing phpunit/php-token-stream 1.2.2 Wrapper around PHP's tokenizer extension. phpunit/phpunit 4.1.1 The PHP Unit Testing framework. phpunit/phpunit-mock-objects 2.1.0 Mock Object library for PHPUnit sebastian/comparator 1.0.0 Provides the functionality to compare PHP values for equality sebastian/diff 1.1.0 Diff implementation sebastian/environment 1.0.0 Provides functionality to handle HHVM/PHP environments sebastian/exporter 1.0.1 Provides the functionality to export PHP variables for visual... sebastian/version 1.0.3 Library that helps with managing the version number of Git-ho... symfony/yaml v2.4.5 Symfony Yaml Component

isokissa avatar May 24 '14 18:05 isokissa

Now I removed everything, everything from phpunit, and even PHP and installed again everything from scratch

Still getting the same error

Fatal error: Call to undefined function phpunit_mockobject_autoload() in /opt/lampp/lib/php/PHPUnit/Util/GlobalState.php on line 378

isokissa avatar May 24 '14 20:05 isokissa

It looks like maybe you have a PEAR-based install on your system still. Something like:

pear uninstall phpunit/PHPUnit

should do the trick.

whatthejeff avatar May 24 '14 20:05 whatthejeff

Hi whatthejeff, before I spotted your reply, I gave up the composer idea and downloaded phpunit with wget and directly installed it to PATH and it works. I am very new to PHP world, probably I was doing some mistake somewhere.

I have PHP stuff from xampp, and downloaded phpunit with composer. Everything used to work fine. Today when I came back to my project after many weeks, those assertEquals() started to give me the strange error, so I ran composer update, and it did not fix the thing, even if I removed everything (so far I think I removed everything).

Thank you in all cases, good to know about "pear uninstall"

isokissa avatar May 24 '14 21:05 isokissa