目錄
作用
前提
安裝
安裝xUnit插件
win10重啟Jenkins
全局環(huán)境設(shè)置
創(chuàng)建項(xiàng)目配置
描述
源碼管理
構(gòu)建觸發(fā)器
構(gòu)建步驟
插件安裝
工作空間
php代碼phpunit文件示例
項(xiàng)目根目錄配置
phpunit.xml
Protect/Tests/test_start.php
composer.json
作用
jenkins 自動(dòng)化單元測(cè)試持續(xù)集成php Phpunit 構(gòu)建流水線示例配置,這里是winwods配置示例
前提
-
java11 下載地址
-
Jenkins 下載地址
-
php環(huán)境
-
Phpunit
安裝
都是默認(rèn)安裝
安裝完請(qǐng)求地址http://127.0.0.1:8080/
后面需要設(shè)置賬戶密碼
安裝xUnit插件
Jenkins的強(qiáng)大之處之一是可以把各種單元測(cè)試框架(JUnit、CppUnit、PHPUnit等)的結(jié)果以可視化的方式呈現(xiàn)在頁(yè)面上。我們先安裝xUnit(其中包含了對(duì)PHPUnit的支持),以便查看后續(xù)單元測(cè)試的結(jié)果。
win10重啟Jenkins
cmd命令方式:
以管理員身份運(yùn)行cmd.exe
進(jìn)入到自己的jenkins安裝目錄:cd D:\Jenkins
停止服務(wù):jenkins.exe stop
啟動(dòng)服務(wù):jenkins.exe start
重啟服務(wù):jenkins.exe restart
url重啟
關(guān)閉jenkins服務(wù)
http://localhost:8080/exit 網(wǎng)址就能關(guān)閉jenkins服務(wù)
重新啟動(dòng)jenkins服務(wù)器
http://localhost:8080/restart 網(wǎng)址就能重啟jenkins服務(wù)
重新加載配置信息
http://localhost:8080/reload 網(wǎng)址就能重新加載配置信息
全局環(huán)境設(shè)置
地址: http://127.0.0.1:8080/manage/configure
還是多說說這個(gè)環(huán)境變量的問題
創(chuàng)建項(xiàng)目配置
描述
自己填一下
源碼管理
構(gòu)建觸發(fā)器
配置代碼變更后自動(dòng)構(gòu)建配置
構(gòu)建步驟
windows選擇executewindwos
linux 選擇Execute shell
插件安裝
phpunit需要安裝JUnit Plugin組件
還有可以安裝一下顯示測(cè)試報(bào)告的包
工作空間
git配置成功后工作空間就能獲取到代碼
Build new->選擇構(gòu)建 可以構(gòu)建代碼包
php代碼phpunit文件示例
項(xiàng)目根目錄配置
phpunit.xml
<phpunit bootstrap="protect/Tests/test_start.php" colors="true">
<testsuites>
<testsuite name="unit">
<directory>protect/Tests/Unit</directory>
<directory>protect/Tests/Api</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">protect/Biz</directory>
<directory suffix=".php">protect/Service</directory>
<directory suffix=".php">protect/EntityService</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./reports" lowUpperBound="100" highLowerBound="100"/>
</logging>
</phpunit>
Protect/Tests/test_start.php
<?php
/**
* Author: wang.kai
* Date: 2023/07/06
* Time: 11:36 AM
*/
$hllEnv = get_cfg_var('dh.env'); //當(dāng)前部署環(huán)境(在php.ini中定義)
$hllEnv or $hllEnv = 'dev';
define('DH_ENV', strtolower($hllEnv)); //dev/stg/prd/gra
define('DH_IS_DEV', $hllEnv == 'dev');
if ($hllEnv != "dev") {
exit();
}
require(__DIR__.'/../../vendor/autoload.php');
composer.json
{
"name": "test/public-test",
"description": "Protect/Tests",
"require-dev": {
"phpunit/phpunit": "6.2.4"
},
"require": {
"php": "^7.0",
"ext-json": "*",
"ext-curl": "*",
"ext-redis": "*"
},
"autoload": {
"psr-4": {
"App\\": "Protect/"
},
"classmap": [
]
}
}
安裝phpunit文章來源:http://www.zghlxwxcb.cn/news/detail-543413.html
Composer install
如果修改了composer配置文章來源地址http://www.zghlxwxcb.cn/news/detail-543413.html
composer dump-autoload
到了這里,關(guān)于Php Jenkins phpunit配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!