phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

PHP Fatal error: Call to undefined function phpunit_mockobject_autoload()

Open texdc opened this issue 14 years ago • 19 comments

PHPUnit 3.6.12, MockObjects 1.2.1

Recent changes seem to have broken mock objects. Here is the stack trace from my Hudson build which has been working fine up until yesterday afternoon.

PHP Fatal error: Call to undefined function phpunit_mockobject_autoload() in /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Util/GlobalState.php on line 378 PHP Stack trace: PHP 1. {main}() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/bin/phpunit:0 PHP 2. PHPUnit_TextUI_Command::main() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/bin/phpunit:46 PHP 3. PHPUnit_TextUI_Command->run() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/TextUI/Command.php:130 PHP 4. PHPUnit_TextUI_TestRunner->doRun() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/TextUI/Command.php:192 PHP 5. PHPUnit_Framework_TestSuite->run() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/TextUI/TestRunner.php:325 PHP 6. PHPUnit_Framework_TestSuite->run() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestSuite.php:705 PHP 7. PHPUnit_Framework_TestSuite->run() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestSuite.php:705 PHP 8. PHPUnit_Framework_TestSuite->run() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestSuite.php:705 PHP 9. PHPUnit_Framework_TestSuite->runTest() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestSuite.php:745 PHP 10. PHPUnit_Framework_TestCase->run() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestSuite.php:772 PHP 11. PHPUnit_Framework_TestResult->run() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestCase.php:751 PHP 12. PHPUnit_Framework_TestResult->addFailure() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestResult.php:699 PHP 13. PHPUnit_Util_Log_JUnit->addFailure() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestResult.php:308 PHP 14. PHPUnit_Util_Filter::getFilteredStacktrace() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Util/Log/JUnit.php:210 PHP 15. PHPUnit_Util_GlobalState::phpunitFiles() /var/lib/hudson/jobs/MyProject/workspace/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Util/Filter.php:70

texdc avatar Oct 06 '12 18:10 texdc

The string phpunit_mockobject_autoload does not exist in any repository related to PHPUnit anymore. I cannot reproduce this.

sebastianbergmann avatar Oct 06 '12 22:10 sebastianbergmann

That was the first error. I've updated my copy, but now I'm getting the following error:

PHP Fatal error: Call to undefined function file_iterator_autoload() in /Library/WebServer/Documents/lifereach/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Util/GlobalState.php on line 379 PHP Stack trace: PHP 1. {main}() /Library/WebServer/Documents/project/vendor/pear-pear.phpunit.de/PHPUnit/bin/phpunit:0 PHP 2. PHPUnit_TextUI_Command::main() /Library/WebServer/Documents/project/vendor/pear-pear.phpunit.de/PHPUnit/bin/phpunit:46 PHP 3. PHPUnit_TextUI_Command->run() /Library/WebServer/Documents/project/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/TextUI/Command.php:130 PHP 4. PHPUnit_TextUI_TestRunner->doRun() /Library/WebServer/Documents/project/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/TextUI/Command.php:192 PHP 5. PHPUnit_Framework_TestSuite->run() /Library/WebServer/Documents/project/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/TextUI/TestRunner.php:325 PHP 6. PHPUnit_Framework_TestSuite->runTest() /Library/WebServer/Documents/project/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestSuite.php:745 PHP 7. PHPUnit_Framework_TestCase->run() /Library/WebServer/Documents/project/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestSuite.php:772 PHP 8. PHPUnit_Framework_TestResult->run() /Library/WebServer/Documents/project/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestCase.php:751 PHP 9. PHPUnit_Framework_TestResult->addError() /Library/WebServer/Documents/project/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestResult.php:695 PHP 10. PHPUnit_Util_Log_JUnit->addError() /Library/WebServer/Documents/project/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Framework/TestResult.php:260 PHP 11. PHPUnit_Util_Filter::getFilteredStacktrace() /Library/WebServer/Documents/projectvendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Util/Log/JUnit.php:177 PHP 12. PHPUnit_Util_GlobalState::phpunitFiles() /Library/WebServer/Documents/project/vendor/pear-pear.phpunit.de/PHPUnit/PHPUnit/Util/Filter.php:70

(Note: I'm not calling these methods directly. The test that fails is very simple. In fact, the test should fail due to an invalid array index, if that's of any help.)

texdc avatar Oct 07 '12 23:10 texdc

I have no idea how you are updating your copy. None of the *_autoload() functions are called directly any more. The string vendor/pear-pear.phpunit.de in your error message leads me to believe that you are not using the official Composer repository to install PHPUnit.

sebastianbergmann avatar Oct 08 '12 06:10 sebastianbergmann

vendor/pear-pear.phpunit.de is an artifact of installing PEAR packages via Composer using composer's "pear" package type. It is a seriously broken approach to handling PEAR-dependencies, and what caused me to go down the Composer path with PHPUnit in the first place.

@texdc PHPUnit 3.7.x has official Composer support. I suggest you upgrade your project's composer.json accordingly -- you'll find that things will be much smoother. If there is some particular reason to stay with PHPUnit 3.6.x, you probably need to specify all of the PEAR packages PHPUnit is dependent upon in your composer.json, not just PHPUnit. That way you can fix upon a working version combination and stay with it.

However, I recommend using this opportunity to upgrade to 3.7.x and get on a supported installation path.

claylo avatar Oct 08 '12 06:10 claylo

This is happening to me as well, after an attempt to upgrade 3.6.12 using pear only. Unfortunately, upgrading PHP to < 5.3.2 is not an option at this time.

PHP Fatal error: Call to undefined function file_iterator_autoload() in /usr/share/pear/PHPUnit/Util/GlobalState.php on line 379

phpunit --version PHPUnit 3.6.12 by Sebastian Bergmann.

pear list

Installed packages, channel pear.php.net:

Package Version State Archive_Tar 1.3.10 stable Config 1.10.12 stable Console_Getopt 1.3.1 stable Date 1.4.7 stable HTML_Template_IT 1.3.0 stable MDB2 2.4.1 stable MIME_Type 1.3.1 stable Mail 1.2.0 stable Mail_Mime 1.8.5 stable Mail_mimeDecode 1.5.1 stable Net_POP3 1.3.6 stable Net_SMTP 1.4.2 stable Net_Socket 1.0.10 stable PEAR 1.9.4 stable PEAR_Frontend_Web 0.7.4 beta PHP_CodeSniffer 1.4.0 stable PhpDocumentor 1.4.4 stable Structures_Graph 1.0.4 stable XML_Util 1.2.1 stable

Any suggestions other than upgrading to support Composer?

brendanhill avatar Oct 11 '12 23:10 brendanhill

Sorry for the delay. I upgraded to v3.7 and my issue(s) have been resolved. I still recommend looking into the changes made about a week ago, because that's when things started going wrong for no apparent reason.

On Oct 11, 2012, at 6:09 PM, brendanhill [email protected] wrote:

This is happening to me as well, after an attempt to upgrade 3.6.12 using pear only. Unfortunately, upgrading PHP to < 5.3.2 is not an option at this time.

PHP Fatal error: Call to undefined function file_iterator_autoload() in /usr/share/pear/PHPUnit/Util/GlobalState.php on line 379

phpunit --version PHPUnit 3.6.12 by Sebastian Bergmann.

pear list

Installed packages, channel pear.php.net:

Package Version State Archive_Tar 1.3.10 stable Config 1.10.12 stable Console_Getopt 1.3.1 stable Date 1.4.7 stable HTML_Template_IT 1.3.0 stable MDB2 2.4.1 stable MIME_Type 1.3.1 stable Mail 1.2.0 stable Mail_Mime 1.8.5 stable Mail_mimeDecode 1.5.1 stable Net_POP3 1.3.6 stable Net_SMTP 1.4.2 stable Net_Socket 1.0.10 stable PEAR 1.9.4 stable PEAR_Frontend_Web 0.7.4 beta PHP_CodeSniffer 1.4.0 stable PhpDocumentor 1.4.4 stable Structures_Graph 1.0.4 stable XML_Util 1.2.1 stable

Any suggestions other than upgrading to support Composer?

— Reply to this email directly or view it on GitHub.

texdc avatar Oct 12 '12 02:10 texdc

The package.xml in the 3.6 branch now has the metadata information on the maximum version supported for each dependency. PHPUnit 3.6.12 was re-released using that metadata.

sebastianbergmann avatar Oct 12 '12 07:10 sebastianbergmann

I had the same problem reported at the beginning of this thread, and it was solved by removing lastest version of phpunit/PHPUnit_MockObject and installing phpunit/PHPUnit_MockObject-1.1.1 in the pear packages.

growies avatar Oct 23 '12 21:10 growies

Same problem here, but was an APC cache issue.

php -dapc.enable_cli=1 -r "apc_clear_cache();"

Guibod avatar Oct 25 '12 14:10 Guibod

Hi, I also have the "Call to undefined function phpunit_mockobject_autoload()" problem. On development machine, it's not a problem: my testUnits run fine. Running them under Jenkins (or on the cmd-line of the same machine) gives me the error. I do not run XDebug on development machine, I have XDebug on Jenkin's machine. Maybe this help.

stephane-wis avatar Oct 26 '12 12:10 stephane-wis

This is a copy of the stack when I have the error. The error disappears if I skip the database testing.

  1. {main}() /usr/bin/phpunit:0
  2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:44
  3. PHPUnit_TextUI_Command->run() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:125
  4. PHPUnit_TextUI_TestRunner->doRun() /usr/local/zend/share/pear/PHPUnit/TextUI/Command.php:187
  5. PHPUnit_TextUI_ResultPrinter->printResult() /usr/local/zend/share/pear/PHPUnit/TextUI/TestRunner.php:331
  6. PHPUnit_TextUI_ResultPrinter->printErrors() /usr/local/zend/share/pear/PHPUnit/TextUI/ResultPrinter.php:156
  7. PHPUnit_TextUI_ResultPrinter->printDefects() /usr/local/zend/share/pear/PHPUnit/TextUI/ResultPrinter.php:284
  8. PHPUnit_TextUI_ResultPrinter->printDefect() /usr/local/zend/share/pear/PHPUnit/TextUI/ResultPrinter.php:226
  9. PHPUnit_TextUI_ResultPrinter->printDefectTrace() /usr/local/zend/share/pear/PHPUnit/TextUI/ResultPrinter.php:239
  10. PHPUnit_Util_Filter::getFilteredStacktrace() /usr/local/zend/share/pear/PHPUnit/TextUI/ResultPrinter.php:275
  11. PHPUnit_Util_GlobalState::phpunitFiles() /usr/local/zend/share/pear/PHPUnit/Util/Filter.php:70

stephane-wis avatar Oct 26 '12 12:10 stephane-wis

upgraded to 3.7.8 on Jenkin's machine, solved the problem.

stephane-wis avatar Oct 26 '12 12:10 stephane-wis

Got the same error that @texdc mentioned (undefined function file_iterator_autoload) with the following "pear list":

Package          Version State
Archive_Tar      1.3.7   stable
Console_Getopt   1.2.3   stable
PEAR             1.9.4   stable
PHPUnit          1.3.2   stable
Structures_Graph 1.0.4   stable
XML_RPC          1.5.4   stable
XML_Util         1.2.1   stable

Ran a "pear upgrade", which bumped:

Archive_Tar      1.3.7 => 1.3.10
Console_getopt   1.2.3 => 1.3.1
XML_RPC          1.5.4 => 1.5.5

And it works now. Not sure if one of the packages was at fault, or something just needed to be reset within Pear.

alexekorn avatar Oct 27 '12 19:10 alexekorn

how to upgraded 3.7.8 on Jenkin's machine in fedora 17

kumanan-c avatar Nov 05 '12 11:11 kumanan-c

I faced similar errors, but upgrading php was not an option. I successfully got PHPUnit 3.6 working with PHP 5.3.2. After lots of installs/uninstalls I figured out that you need to downgrade the dependencies by 1 minor version. Pear will install latest versions for all dependencies which do not work. Details are here http://blog.ashwinidhekane.com/installing-phpunit-with-php-5-3-2/

ashwinikd avatar Jan 04 '13 16:01 ashwinikd

I solved the problem by downgrading PHPUnit_MockObject from 1.2.3 to 1.1.0, I guess this is because the function phpunit_mockobject_autoload is no longer available in PHPUnit_MockObject 1.2.x

tansteventan avatar Jan 19 '13 10:01 tansteventan

pear was prevented from upgrading if PHP_Invoker was installed on a windows system as it's new version requires PCNTL extension not available on windows.

>pear uninstall phpunit/PHP_Invoker
phpunit/PHP_Invoker (version >= 1.0.0) can be optionally used by installed package "phpunit/PHPUnit"
uninstall ok: channel://pear.phpunit.de/PHP_Invoker-1.0.1

Upgrade then went well:

>pear upgrade
Did not download optional dependencies: phpunit/PHP_Invoker, use --alldeps to download automatically
phpunit/PHPUnit can optionally use package "phpunit/PHP_Invoker" (version >= 1.1.0)
downloading DbUnit-1.2.2.tgz ...
Starting to download DbUnit-1.2.2.tgz (41,888 bytes)
............done: 41,888 bytes
downloading PHPUnit-3.7.13.tgz ...
Starting to download PHPUnit-3.7.13.tgz (117,403 bytes)
...done: 117,403 bytes
downloading PHPUnit_Selenium-1.2.12.tgz ...
Starting to download PHPUnit_Selenium-1.2.12.tgz (40,358 bytes)
...done: 40,358 bytes
upgrade ok: channel://pear.phpunit.de/PHPUnit-3.7.13
upgrade ok: channel://pear.phpunit.de/DbUnit-1.2.2
upgrade ok: channel://pear.phpunit.de/PHPUnit_Selenium-1.2.12

I know pear is not really cool but as my system had it I was lazy to switch. PEAR even is too dumb to recognize that the optinal PHP_Invoker doesn't work on my platform.

Earlier the upgrade failed:

phpunit/PHP_Invoker requires PHP extension "pcntl"
phpunit/PHPUnit requires package "phpunit/PHP_Invoker" (version >= 1.1.0), installed version is 1.0.1
phpunit/DbUnit requires package "phpunit/PHPUnit" (version >= 3.7.0), installed version is 3.6.7
phpunit/PHPUnit_Selenium requires package "phpunit/PHPUnit" (version >= 3.7.0), installed version is 3.6.7
No valid packages found
upgrade failed

ref

hakre avatar Feb 09 '13 11:02 hakre

I have similar problem in Ampps on Mac...

Fatal error: Call to undefined function ctype_alpha() in /..../libraries/rokcommon/RokCommon/Service/Container/Loader/File.php on line 90

and here is my script:

abstract class RokCommon_Service_Container_Loader_File extends RokCommon_Service_Container_AbstractLoader
{
  protected
    $paths = array();

  /**
   * Constructor.
   *
   * @param RokCommon_Service_Container_Builder $container A RokCommon_Service_Container_Builder instance
   * @param string|array              $paths     A path or an array of paths where to look for resources
   */
  public function __construct(RokCommon_Service_Container_Builder $container = null, $paths = array())
  {
    parent::__construct($container);

    if (!is_array($paths))
    {
      $paths = array($paths);
    }

    $this->paths = $paths;
  }

  /**
   * Loads a resource.
   *
   * A resource is a file or an array of files.
   *
   * The concrete classes always have access to an array of files
   * as this method converts single file argument to an array.
   *
   * @param mixed $resource The resource path
   */
  public function load($resource)
  {
    if (!is_array($resource))
    {
      $resource = array($resource);
    }

    return parent::load($resource);
  }

  protected function getAbsolutePath($file, $currentPath = null)
  {
    if (self::isAbsolutePath($file))
    {
      return $file;
    }
    else if (null !== $currentPath && file_exists($currentPath.DIRECTORY_SEPARATOR.$file))
    {
      return $currentPath.DIRECTORY_SEPARATOR.$file;
    }
    else
    {
      foreach ($this->paths as $path)
      {
        if (file_exists($path.DIRECTORY_SEPARATOR.$file))
        {
          return $path.DIRECTORY_SEPARATOR.$file;
        }
      }
    }

    return $file;
  }

  static protected function isAbsolutePath($file)
  {
    if ($file[0] == '/' || $file[0] == '\\' ||
        (strlen($file) > 3 && ctype_alpha($file[0]) &&
         $file[1] == ':' &&
         ($file[2] == '\\' || $file[0] == '/')
        )
       )
    {
      return true;
    }

    return false;
  }
}

Can someone help me because i'm a real beginner. Please!

bluejoo avatar Jul 13 '14 20:07 bluejoo

@bluejoo This is not a PHPUnit-related issue. Your code uses the Ctype extension, but you don't have it installed/enabled.

whatthejeff avatar Jul 13 '14 21:07 whatthejeff