PhpUnit Netbeans 極簡配置

來源:互聯網
上載者:User

標籤:

0x01. 下載兩個 Phar 包:

wget https://phar.phpunit.de/phpunit.pharwget https://phar.phpunit.de/phpunit-skelgen.phar

0x02. 讓這兩個包可執行

chmod +x phpunit.pharchmod +x phpunit-skelgen.phar

0x03. 移動(或建立軟串連)到你的環境變數的目錄下

mv phpunit.phar /usr/local/bin/phpunitmv phpunit-skelgen.phar /usr/local/bin/phpunit-skelgen

至此,PHPUnit 以及產生測試的架構,已經部署完畢。簡單吧!

0x04. Netbeans 全域配置

菜單 --> 工具[Tools] --> 選項[Options] --> PHP --> Frameworks & Tools選中左側的 PHPUnit,設定 [PHPUnit Script] 與 [Skeleton Generator Script]如果在你的 PATH 環境變數下,點擊 [Search] 即可到,如果不在,自己填路徑。本例中,這兩個路徑分別為:  /usr/local/bin/phpunit   /usr/local/bin/phpunit-skelgen 點擊確定,退出配置

0x05. NetBeans 項目配置

在項目名稱上右擊 --> 屬性[Properties] --> 測試[Testing]添加測試目錄。展開左側 測試[Testing] 樹,點擊 [PHPUnit]勾選 [Use Bootstrap],然後選擇啟動指令碼或點擊[Generate]自動產生一個。勾選 [Use Bootstrap for Creating New Unit Tests]
如果不勾選 [Use Bootstrap for Creating New Unit Tests],在產生有繼承或實現介面的類時,會提示
Final Error: Interface ... not found in ...Final Error: Class ... not found in ...
0x06. 修改 bootstrap.php

自動產生的 bootstrap.php 可能不大符合自己的實際要求,修改一下即可,它的作用一般是自動載入類庫。比如你使用一些架構,載入自己的類,則把架構的 autoload.php 檔案包含進來,把自己的 autoload.php 包含進來即可。比如:

<?php/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. *//** * @author */// TODO: check include path//ini_set(‘include_path‘, ini_get(‘include_path‘));// put your code hererequire __DIR__ . ‘../../../my/autoload.php‘;
0x07. 使用方法
在代碼視窗選中要測試的檔案,菜單 --> 工具[Tools] --> 產生測試[Create Tests]或在項目視窗,選中要測試的檔案,右鍵 --> 工具[Tools] --> 產生測試[Create Tests]

0x08. 附命令列使用方法

phpunit-skelgen

"/usr/bin/php" "/usr/local/bin/phpunit-skelgen" "--ansi" "generate-test" "--bootstrap=/path/to/bootstrap.php" "Namespace\MyClass" "/path/to/Namespace/MyClass.php" "Namespace\MyClassTest" "/path/to/Namespace/MyClassTest.php"

phpunit

"/usr/bin/php" "/usr/local/bin/phpunit" "--colors" "--log-junit" "/tmp/nb-phpunit-log.xml" "--bootstrap" "/path/to/bootstrap.php" "/path/to/netbeans-8.0/php/phpunit/NetBeansSuite.php" "--run=/path/to/test/Namespace/MyClassTest.php"

PhpUnit Netbeans 極簡配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.