getMock() undefined in PHPUnit tests with HHVM - php

We updated PHPUnit to the latest version yersterday and renamed all calls to createMock() from getMock().
Our unit tests pass with PHP 5.6 and PHP 7.0 but fail with HHVM, we get the following error:
Fatal error: Call to undefined method Gomoob\Pushwoosh\Client\CURLClientTest::createMock() in /home/travis/build/gomoob/php-pushwoosh/src/test/php/Gomoob/Pushwoosh/Client/CURLClientTest.php on line 33
You can see the complete build on Travis.
It's very strange because this is a simple call to a protected method declared inside a parent class (see the createMock() method here).
Do you have any idea why this is failing? Could it be a bug in HHVM?

The createMock() method was introduced in PHPUnit 5.4.0. You use an older version on travis - 5.1.3. See https://travis-ci.org/gomoob/php-pushwoosh/jobs/142799864#L910
Your builds for other PHP versions use PHPUnit 5.4.6.
It's probably something you should report to travis. Your other option is to install phpunit via composer as a dev dependency.

Related

How to fix phpunit fatal error must be compatible?

While using phpunit 8.5 with php 7.2.24 I keep getting the following error while running my test:
Fatal error: Declaration of PHPUnit\TextUI\ResultPrinter::addError(PHPUnit\Framework\Test $test, Throwable $t, float $time): void must be compatible with PHPUnit_Framework_TestListener::addError(PHPUnit_Framework_Test $test, Exception $e, $time) in /var/local/gc-global.01/vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php on line 31
I had tried different versions of phpunit and reviewed my tests but I still can't understand what is the problem.
Anyone has seen something like this?
It appears that you have different installations of PHPUnit mixed up (because PHPUnit_Framework_TestListener has not existed for ages, and certainly does not exist in PHPUnit 8.5).
For instance, you may have used Composer to install PHPUnit and have configured the autoloader generated by Composer as PHPUnit's bootstrap script but then you invoke PHPUnit using an executable other than vendor/bin/phpunit.

TestCase not found in KernelTestCase.php with Symfony 3.2.7

I'm having problems when running Symfony (PHPUnit integrated) tests in my server, it works as expected in my build host but when I upload them to Gitlab CI via Git it throws me the next error:
Class 'PHPUnit\Framework\TestCase' not found in /project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php on line 24
I tried executing phpunit, phpunit ., phpunit tests all with the same results
It was working until a few weeks ago.
My server Symfony version is 3.2.7 and the PHPUnit version is 4.2.6
PHPUnit version is 4.2.6 is very old, and does not contain any Namespaced classes. The Symfony KernelTestCase.php now uses those PHPUnit namespaces to pull on the TestCase class.
There is forward compatibility in PHPUnit 5.4.3, though v5.7, if not 6.0 would be better.
So, you'll want to upgrade your composer.json file and tests to use the new namespaces.

PHPUnit test failed

I'm currently trying to run PHPUnit on my Ubuntu 12.04 virtual machine and when I run phpunit under my application root that has phpunit.xml.dist file it reads from the config but I'm getting below error and it fails:
PHP Fatal error: Call to undefined method PHPUnit_Util_Test::getHookMethods() in phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php on line 633
Is there a reason why this is happening?
I had a similar issue in a different environment.
The problem was that another library's loader was registered too early which also contained another version of PHPUnit which had no that method. The proper order of autoloaders solved the problem.

PHPUnit_Util_Skeleton_Test not found in CakePHP

I'm able to run my individual tests for each model in a plugin called Agg, but when I try to run a CakeTestSuite, then I get an error.
class ModelsTest extends CakeTestSuite
{
public static function suite()
{
$suite = new CakeTestSuite('All model tests');
$suite->addTestDirectory(TESTS . 'Case' . DS . 'Model');
return $suite;
}
}
Running that suite generates this error.
Fatal error: Class 'PHPUnit_Util_Skeleton_Test' not found in C:\work\zend\cake\Cake\TestSuite\CakeTestSuiteCommand.php on line 77
I'm using PHP 5.3.15 and have PHPUnit 3.7.12 installed with CakePHP 2.2.5
I get this error when running tests both via the web and the CLI.
Any help would be appreciated.
UPDATE:
If I search for 'PHPUnit_Util_Skeleton_Test' in PEAR folder for PHPUnit it's not found. This seems strange to me. Am I using the wrong version of PHPUnit? When was this class introduced?
UPDATE:
It seems that this class is no longer used in PHPUnit 3.7.x, and I'm wondering if CakePHP 2.2 will only work with PHPUnit 3.6. I tried to uninstall the pear package, and then install the 3.6.x version but always installs the newest version. Any ideas on how to downgrade PHPUnit?
UPDATE:
Downgrading using the --force to install older versions of PHPUnit didn't resolve the problem. I tried 3.6.12, 3.6.5 and 3.5. With the 3.6.12 I got an error with is_file() somewhere in the PHPUnit code.
PHPUnit_Util_Skeleton_Test is available in PHPUnit 3.6, see https://github.com/sebastianbergmann/phpunit/blob/3.6/PHPUnit/Util/Skeleton/Test.php
I suggest uninstalling all phpunit packages and reinstalling phpunit 3.6 with
$ pear install phpunit/phpunit-3.6.12
It might be that dependencies were broken when downgrading the single phpunit package with --force, and this should fix it.

PHPUnit StackTest::assertEmpty() deprecated

I am learning building php unit tests using PHPUnit . There they have a manual and I encountered this example Where they use assertEmpty(), but when I run this code in command line I get this error : Call to undefined method StackTest::assertEmpty() in /var/www/.../tests/StackTest.php on line 20. So if this method is deprecated or something why they use it , also is there another method for this? (of course I can try this $this->assertEquals(0, count($stack));) but anyways...
The same with assertNotEmpty().
I'm on debian, and it looks like the default install of PHPunit is a bit old (3.4.14).
If you search for "assertEmpty" in this url, you will see what version it was added in (3.5.0-1).
http://packages.debian.org/changelogs/pool/main/p/phpunit/phpunit_3.6.10-1/changelog.html
What worked for me was removing phpunit from the system with apt, and installing it with pear
http://www.santiagolizardo.com/article/how-to-install-pear-and-phpunit-in-debianubuntu/57001
These links also helped me.
"Fatal error: Call to undefined method PHPUnit_Util_Filter::addfiletofilter() in /usr/bin/phpunit on line 48"
Cannot get PHPunit working
Are you running the unit test from the command line with the phpunit command line tools?
phpunit --verbose StackTest stacktest.php

Categories