Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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().

like image 460
Centurion Avatar asked Oct 05 '10 18:10

Centurion


People also ask

How do I run a PHPUnit test?

How to Run Tests in PHPUnit. You can run all the tests in a directory using the PHPUnit binary installed in your vendor folder. You can also run a single test by providing the path to the test file. You use the --verbose flag to get more information on the test status.

What is PHPUnit testing?

PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit design for unit testing systems that began with SUnit and became popular with JUnit. Even a small software development project usually takes hours of hard work.

What is assertion in PHPUnit?

PHPunit | assertEquals() Function The assertEquals() function is a builtin function in PHPUnit and is used to assert whether the actual obtained value is equals to expected value or not. This assertion will return true in the case if the expected value is the same as the actual value else returns false.

What is a fixture PHP?

Writing Fixtures Data fixtures are PHP classes where you create objects and persist them to the database. Imagine that you want to add some Product objects to your database. No problem! Create a fixtures class and start adding products: Copy.


2 Answers

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

like image 129
Chris Gallo Avatar answered Oct 03 '22 14:10

Chris Gallo


Are you running the unit test from the command line with the phpunit command line tools?

phpunit --verbose StackTest stacktest.php
like image 24
Craig Avatar answered Oct 03 '22 14:10

Craig