本文實(shí)例講述了PHP單元測試配置與使用方法。分享給大家供大家參考,具體如下:
php與其他語言不太一樣,單元測試需要自己安裝和配置,相對麻煩一點(diǎn),不過單元測試對于提高庫的穩(wěn)定性和健壯性還是非常給力的,下面教大家怎么配置PHP單元測試
注意:php需升級到7.1版本以上
$ wget https://phar.phpunit.de/phpunit-7.0.phar $ chmod +x phpunit-7.0.phar $ sudo mv phpunit-7.0.phar /usr/local/bin/phpunit $ phpunit --version PHPUnit x.y.z by Sebastian Bergmann and contributors.
composer global require phpunit/phpunit
phpunit bootstrap="vendor/autoload.php"> testsuites> testsuite name="service"> directory>tests/directory> /testsuite> /testsuites> /phpunit>
如我的phpunit本地的路徑為/usr/local/bin/phpunit
如我的phpunit包本地的路徑為/Users/chenqionghe/.composer/vendor/phpunit
?php use Eoffcn\Utils\Arrays; use PHPUnit\Framework\TestCase; /** * Array測試用例 * Class ArraysTest */ class ArraysTest extends TestCase { public function testGet() { $array = [ 1 => [ 'b' => [ 'c' => 'cqh' ] ], 2 => [ 'b' => [ 'c' => 'cqh' ] ] ]; $this->assertEquals('cqh', Arrays::get($array, '1.b.c')); } }
Phpstorm方式,當(dāng)前測試類右鍵Run即可
命令行的方式,進(jìn)行項(xiàng)目目錄執(zhí)行
phpunit tests/ArraysTest.php
phpstorm方式
命令行方式,命令行下進(jìn)入當(dāng)前項(xiàng)目執(zhí)行
phpunit
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP錯誤與異常處理方法總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》及《php優(yōu)秀開發(fā)框架總結(jié)》
希望本文所述對大家PHP程序設(shè)計(jì)有所幫助。
標(biāo)簽:宜賓 黃南 湛江 鎮(zhèn)江 寶雞 南陽 婁底 銅川
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP單元測試配置與使用方法詳解》,本文關(guān)鍵詞 PHP,單元,測試,配置,與,使用方法,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。