最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHPUnit 單元測試安裝與使用入門教程

 更新時間:2020年04月22日 11:22:15   作者:Ryan_zheng  
這篇文章主要介紹了PHPUnit 單元測試安裝與使用,結(jié)合實例形式分析了PHPunit單元測試的下載、安裝、測試運(yùn)行相關(guān)操作技巧與使用注意事項,需要的朋友可以參考下

本文實例講述了PHPUnit 單元測試安裝與使用。分享給大家供大家參考,具體如下:

一、官網(wǎng)下載對應(yīng) PHP 版本的代碼庫

https://phpunit.de/getting-started-with-phpunit.html

二、安裝 PHPUnit 

官網(wǎng)提供了兩種方法安裝

1. PHP Archive (PHAR)

➜ wget -O phpunit https://phar.phpunit.de/phpunit-8.phar

➜ chmod +x phpunit

➜ ./phpunit --version
PHPUnit 8.0.0 by Sebastian Bergmann and contributors.

2. Composer

➜ composer require --dev phpunit/phpunit ^8

➜ ./vendor/bin/phpunit --version
PHPUnit 8.0.0 by Sebastian Bergmann and contributors.

三、使用 PHPUnit 進(jìn)行測試,以下代碼默認(rèn)你是使用 Composer 安裝的 PHPUnit

安裝完成后在當(dāng)前目錄下添加文件 EmailTest.php,文件內(nèi)容如下

<?php
declare(strict_types=1);

use PHPUnit\Framework\TestCase;

final class EmailTest extends TestCase
{
  public function testCanBeCreatedFromValidEmailAddress(): void
  {
    $this->assertInstanceOf(
      Email::class,
      Email::fromString('user@example.com')
    );
  }

  public function testCannotBeCreatedFromInvalidEmailAddress(): void
  {
    $this->expectException(InvalidArgumentException::class);

    Email::fromString('invalid');
  }

  public function testCanBeUsedAsString(): void
  {
    $this->assertEquals(
      'user@example.com',
      Email::fromString('user@example.com')
    );
  }
}

運(yùn)行測試

➜ ./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/EmailTest
PHPUnit 8.0.0 by Sebastian Bergmann and contributors.

...                                 3 / 3 (100%)

Time: 70 ms, Memory: 10.00MB

OK (3 tests, 3 assertions)

更多關(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è)計入門教程》及《php優(yōu)秀開發(fā)框架總結(jié)

希望本文所述對大家PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論

惠来县| 西和县| 大荔县| 潜山县| 高尔夫| 韶山市| 连山| 纳雍县| 柏乡县| 四会市| 房山区| 普兰店市| 泊头市| 赫章县| 乌拉特中旗| 治多县| 萨嘎县| 永川市| 高雄市| 遂溪县| 泸定县| 徐闻县| 贡嘎县| 漳平市| 揭西县| 金山区| 丰镇市| 锦屏县| 全椒县| 西和县| 乐平市| 田林县| 永济市| 张家界市| 石棉县| 株洲市| 渭源县| 浙江省| 三原县| 大石桥市| 弥勒县|