PHPUnit Note (1) PHPUnit Note (1) & nbsp; recently I conceived my own project, and I had to use php to do something on the web, so I naturally got into touch with phpunit. & Nbsp; development platform: Debian & nbsp; the first step is to install PHPUnit. the simpler the configuration environment is, the better. I am a lazy person. I think... & nbsp; PHPUnit security PHPUnit notes (1)
PHPUnit notes (1)
Recently, I have conceived my own project, which involves something on the web. I want to use php to do it. so I naturally came into contact with phpunit.
Development Platform:Debian
The first step is to install PHPUnit. the simpler the configuration environment, the better. I am a lazy, I think...
PHPUnit installation
1 |
Pear channel-discover pear.phpunit.de |
2 |
Pear channel-discover components. ez. no |
3 |
Pear channel-discover pear.symfony-project.com |
4 |
Pear install phpunit/PHPUnit |
After that, I will wait for a while. at first, I was in a hurry. when I saw no reflection, I directly ctrl + c. It turns out that I am 2.
Pear is required for installation. of course, you can continue to get my style.
Pear installation
1 |
Apt-get install php5-curl php-pear |
Install curl and pear |
2 |
Pear upgrade-all |
Update software package |
After everything is ready, you can enter phpunit in the terminal. if it is not reflected, you are ready to find the reason. Anyway, I believe that most of the software problems on linux are dependency problems. I have tried to play with lfs before. this is a good guy who didn't let me die.
Next, use phpunit.
Most of baidu and google are used as follows:
Enter
1 |
Phpuint test. php |
Test. php is the test code file. |
The tragedy is that the PHPUnit/Framework. php file cannot be found, so after viewing the include_path parameter of php. ini, the phpunit directory is found and the Framework directory is found.
assertEquals(0, sizeof($fixture));}public function testArrayContainsAnElement(){/* Create the Array fixture*/$fixture = array();/*Add an element to the Array * fixture*/$fixture[] = 'Element';/*Assert that the size of the * Array fixture is 1*/$this->assertEquals(1, sizeof($fixture));}}?>
This is okay. basically, a simple testcase is ready to run.
Of course, if there are too many Test files, such a phpunit is quite a pain point. Therefore, I found how to use the xml configuration file.
Tests
Tests/Freezer/HashGenerator/NonRecursiveSHA1Test.php
Tests/Freezer/IdGenerator/UUIDTest.php
Tests/Freezer/UtilTest.php
Tests/FreezerTest.php
Tests/Freezer/StorageTest.php
Tests/Freezer/Storage/CouchDB/WithLazyLoadTest.php
Tests/Freezer/Storage/CouchDB/WithoutLazyLoadTest.php
You can go to http://www.phpunit.de/manual/3.6/en/index.htmlto find more methods.
Terminal commands
1 |
Phpunit -- configuration test. xml -- debug |
Test. xnl is the test configuration file |
OK. The first note is complete.
Finally, I felt that phpunit is really quite good. if I want to use JUnit for java, Jmock and easymock are required for mock. net is also similar. for unit test NUnit, mock needs Rhino Mocks; c is even more tearful. Phpunit, not just mock, but Code Coverage.