{"id":248,"title":"phpunit\u5728linux\u4e0b\u7684\u5b89\u88c5\u53ca\u793a\u4f8b","good":0,"bad":0,"hit":2167,"created_at":"2016-11-17 00:00:00","content":"
\u8fd9\u91cclinux\u73af\u5883\u4e3acentos6.7,\u6b64\u7248\u672c\u9700\u8981php5.6\u53ca\u4ee5\u4e0a\u73af\u5883<\/p>
PHPUnit\u5168\u5c40\u5b89\u88c5<\/p>
1\u3001\u4e0b\u8f7d PHPUnit \u7684 PHP \u6863\u6848\u5305 (PHAR)\uff0c\u5b83\u5c06 PHPUnit \u6240\u9700\u8981\u7684\u6240\u6709\u5fc5\u8981\u7ec4\u4ef6\uff08\u4ee5\u53ca\u67d0\u4e9b\u53ef\u9009\u7ec4\u4ef6\uff09\u6346\u7ed1\u5728\u5355\u4e2a\u6587\u4ef6\u4e2d\uff1a<\/p>
$ wget https:\/\/phar.phpunit.de\/phpunit-5.6.3.phar<\/p>
2\u3001\u6dfb\u52a0\u53ef\u6267\u884c\u6743\u9650<\/p>
$ chmod +x phpunit-5.6.3.phar<\/p>
3\u3001\u5b89\u88c5\u5230\u6307\u5b9a\u76ee\u5f55<\/p>
$ mv phpunit-5.6.3.phar \/usr\/local\/bin\/phpunit<\/p>
4\u3001\u6d4b\u8bd5\u662f\u5426\u5b89\u88c5<\/p>
a\u3001\u67e5\u770b\u7248\u672c\u4fe1\u606f<\/p>
$ phpunit --version<\/p>
\u4f1a\u770b\u5230\u5982\u4e0b\u4fe1\u606f\uff1a<\/p>
PHPUnit 5.6.3 by Sebastian Bergmann and contributors.
<\/p>
\u5efa\u7acb\u6d4b\u8bd5\u6587\u4ef6\uff1a<\/p>
\/www\/wwwroot\/test\/hrTest.php(\u6587\u4ef6\u540d\u4e3axxTest.php\u683c\u5f0f)
\u5176\u4e2d\u5185\u5bb9\u4e3a\uff08\u6ce8\u610f\u7c7b\u540d\u53ca\u65b9\u6cd5\u540d\u7684\u5199\u6cd5\uff09\uff1a<\/p>
<?php [root@iZ62vgzgugyZ test]# phpunit hrTest.php <\/strong> \u770b\u5230\u5931\u8d25\uff0c\u8868\u793a\u7a0b\u5e8f\u6709\u9519\u8bef\uff0c\u6211\u4eec\u518d\u5c06hrTest.php\u4e2d\u7684\u90a3\u884c\u9519\u8bef\u4ee3\u7801\u6539\u4e00\u4e0b<\/p> $this->assertEquals(0,count($arr));<\/p> \u518d\u6d4b\u4e00\u6b21\uff0c\u6210\u529f\uff1a<\/p> [root@iZ62vgzgugyZ test]# phpunit hrTest.php \u5982\u679c\u7528phpunit hrTest.php\u65f6\u62a5\u5982\u4e0b\u9519\u8bef\uff1a<\/p> \/usr\/bin\/env: php: No such file or directory \r\n \r\n <\/p> \u4e3b\u8981\u662fphp\u5b89\u88c5\u6587\u4ef6\u4e0d\u5728\/usr\/local\/bin\u3002\u5047\u5982php\u5b89\u88c5\u5728\/usr\/local\/php5513\u4e2d<\/p> \u627e\u5230php\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\/usr\/local\/php5513\/bin\/php<\/p> ln -s \/usr\/local\/php5513\/bin\/php \/usr\/local\/bin\/php \u628a\u53ef\u6267\u884c\u6587\u4ef6\u8fde\u63a5\u8fc7\u53bb\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>
class hrTest<\/strong> extends PHPUnit_Framework_TestCase{
public function testIndex<\/strong>(){
$arr=array();
$this->assertEquals(1,count($arr));\/\/\u671f\u5f85\u7684\u7ed3\u679c\u4e3a1\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u4e3a0\uff0c\u8fd9\u662f\u9519\u8bef\u7684\uff0c\u4e3a\u4ec0\u4e48\u8981\u8fd9\u4e48\u505a\uff0c\u662f\u4e3a\u4e86\u770b\u770bphpunit\u662f\u5426\u751f\u6548
}
}
?>
\u5f00\u59cb\u6d4b\u8bd5\uff1aphpunit hrTest.php<\/p>
PHPUnit 5.6.3 by Sebastian Bergmann and contributors.
F 1 \/ 1 (100%)
Time: 164 ms, Memory: 3.00MB<\/p>
<\/p>
There was 1 failure:
1) hrTest::testIndex
Failed asserting that 0 matches expected 1.
\/www\/wwwroot\/test\/hrTest.php:5
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.<\/p>
<\/p>
PHPUnit 5.6.3 by Sebastian Bergmann and contributors.
. 1 \/ 1 (100%)
Time: 207 ms, Memory: 3.00MB
OK (1 test, 1 assertion)
[root@iZ62vgzgugyZ test]#
<\/p>
<\/p>
<\/p>
<\/p>
<\/p>"}