Table of contents
Project root directory configuration
effect
jenkins automated unit test continuous integration php Phpunit build pipeline example configuration, here is a winwods configuration example
premise
-
java11 download address
-
Jenkins download address
-
php environment
-
Phpunit
Install
are installed by default
After installing the request address http://127.0.0.1:8080/
Need to set account password later
Install the xUnit plugin
One of the strengths of Jenkins is that it can visualize the results of various unit testing frameworks (JUnit, CppUnit, PHPUnit, etc.) on the page. We first install xUnit (which includes support for PHPUnit) in order to view the results of subsequent unit tests.
win10 restart Jenkins
cmd命令方式:
以管理员身份运行cmd.exe
进入到自己的jenkins安装目录:cd D:\Jenkins
停止服务:jenkins.exe stop
启动服务:jenkins.exe start
重启服务:jenkins.exe restart
url重启
关闭jenkins服务
http://localhost:8080/exit 网址就能关闭jenkins服务
重新启动jenkins服务器
http://localhost:8080/restart 网址就能重启jenkins服务
重新加载配置信息
http://localhost:8080/reload 网址就能重新加载配置信息
Global environment settings
Address: http://127.0.0.1:8080/manage/configure
Let's talk more about this environment variable
Create project configuration
describe
fill it out yourself
source code management
build trigger
Automatically build configuration after configuration code changes
build steps
windows select executewindwos
linux select Execute shell
plugin installation
phpunit needs to install the JUnit Plugin component
There is also a package that can be installed to display the test report
Workspace
After the git configuration is successful, the workspace can get the code
Build new->Select Build to build the code package
php code phpunit file example
Project root directory configuration
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'); //当前部署环境(在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": [
]
}
}
install phpunit
Composer install
If the composer configuration is modified
composer dump-autoload