PHPUnit StackTest::assertEmpty() deprecated - php

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

Related

Xdebug not available in Composer plugin

I'm trying to debug a Composer plugin with Xdebug. I have my environment set up (export XDEBUG_SESSION=1) and the Xdebug loaded in php.d. The script breaks at first line in Composer so everything works so far.
In a composer-plugin class method code I add an xdebug_break(). What I get when that code gets executed is Uncaught Error: Call to undefined function xdebug_break().
Does Composer spawn a crippled shell of sorts without the environment set or runs PHP without extensions? How can I fix this to debug the Composer plugin?
Found myself the answer: As per Xdebug documentation,
export COMPOSER_ALLOW_XDEBUG=1
did the trick.

getMock() undefined in PHPUnit tests with HHVM

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.

PHPUnit with Symfony Fatal error: Class 'Doctrine\Bundle\DoctrineBundle\DoctrineBundle' not found

I'm trying to testing my app made with Symfony. I wrote a test and when I launch it, i get the following error:
Fatal error: Class 'Doctrine\Bundle\DoctrineBundle\DoctrineBundle'
not found in /.../app/AppKernel.php on line 17
I had the same error with Symfony's MonologBundle, AsseticBundle and SwiftmailerBundle: then I've manually added these bundles into my app, so pheraps I have fixed those errors, but with Doctrine I've not found any solutions yet.
It looks like maybe you did not install the Doctrine bundle.
Try to go to the root of your project where the composer.phar is located through a console, and try to run it like this:
php composer.phar
It will install all dependencies of Symfony2,and hopefully everything is going to work :)

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.

PHP Fatal error: Class 'CTestCase' not found in

Just trying to run a simple test on my local box but i get the following error:
PHP Fatal error: Class 'CTestCase' not found in ....
when running
$ phpunit UserTest
I guess my configuration must be missing something? I just can't figure out what.
Using:
OSX 10.6.7
PHP 5.3.4
PHPUnit 3.5.13
Yii 1.1.7
Make sure you run phpunit at the same directory where your phpunit.xml is. :)
The error message is telling you that the class CTestCase cannot be located. PHPUnit accepts an --include-path option on the command line. You could try something like this:
$ phpunit --include-path .:/path/to/dir/containing/CTestCase UserTest
I found the solution for me. But i am not sure whether this works for you all or not.
Here is the url for the solution
http://www.yiiframework.com/forum/index.php/topic/4728-running-unit-tests-on-windows-problem/

Categories