当前位置: 首页 > ai >正文

VSCode中PHP使用Xdebug

本地环境

  • windows10
  • php8.2 nts
  • xdebug v3
  • thinkphp v8

下载Xdebug

Xdebug下载地址

从xdebug下载地址,下载最新的xdebug,解压后将php_xdebug.dll放入php目录的ext目录下

配置php.ini

[Xdebug]
zend_extension = php_xdebug
xdebug.client_host = 127.0.0.1
xdebug.client_port = 9003
xdebug.mode = debug,coverage
xdebug.start_with_request = yes
xdebug.idekey=VSCODE

安装扩展

配置launch.json

{// 使用 IntelliSense 了解相关属性。// 悬停以查看现有属性的描述。// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "Launch built-in server and debug","type": "php","request": "launch","runtimeArgs": ["-S","localhost:8000","-t","."],"port": 9003,"serverReadyAction": {"action": "openExternally"}},{"name": "Debug current script in console","type": "php","request": "launch","program": "${file}","cwd": "${fileDirname}","externalConsole": false,"port": 9003},{"name": "Listen for Xdebug","type": "php","request": "launch","port": 9003}]
}

运行调试

配合单元测试

安装phpunit

composer require phpunit/phpunit --dev

因为我用的是tp8,单元测试bootstrap需要启动tp的容器,所以安装一下我的扩展bingher/think-test

composer require bingher/think-test --dev

安装PHPUnit Test Explorer

扩展配置

"phpunit.command": "php",
"phpunit.phpunit": "vendor/bin/phpunit",
"phpunit.showAfterExecution": "always",
"phpunit.debuggerConfig": "Listen for Xdebug",
"phpunit.xdebugPort": 9003

重点是phpunit.command,phpunit.phpunit,我原来仅配置phpunit.phpunit: vendor/bin/phpunit.bat 发现扩展执行了一直在转圈圈,调试模式报错: Error: spawn -dxdebug.mode=debug ENOENT at Process.ChildProcess._handle.onexit (node:internal/child_process:285:19) at onErrorNT (node:internal/child_process:483:16) at processTicksAndRejections (node:internal/process/task_queues:82:21)

根据以上配置后PHPUnit Test Explorer顺利运行

phpunit.xml

<phpunit colors="true" verbose="true" bootstrap="./vendor/bingher/think-test/src/init.php"><coverage cacheDirectory="./runtime/phpunit/" pathCoverage="true"><include><directory suffix=".php">./app/</directory></include><report><html outputDirectory="./runtime/phpunit/" lowUpperBound="50" highLowerBound="90"/></report></coverage><testsuites><testsuite name="test"><directory>tests</directory></testsuite></testsuites>
</phpunit>

phpunit.xml可以参考phpunit官网进行配置.

如果没有安装bingher/think-test, 可以不用配置bootstrap

单元测试

http://www.xdnf.cn/news/13135.html

相关文章:

  • IP 地址查询在证券交易中的应用方式
  • spark数据处理练习题番外篇【上】
  • ffmpeg windows 32位编译
  • 如何安全地准备 iPhone 以旧换新(分步说明)
  • 深度解析qemu-guest-agent:架构原理、核心场景与部署实践
  • 【笔记】NVIDIA AI Workbench 安装记录
  • Docker加入用户组
  • 【解决串口数据丢包问题】下位机环形缓冲区+上位机串口生产者-消费者不定长接收(基于keil5和Labview)
  • 数字艺术品的“身份证”危机:当NFT遇见法律红绿灯
  • 延伸大疆AI能力:Coovally一键训练模型,直通无人机部署
  • COCO数据集转YOLO数据集
  • 一体系数据平台的进化:基于阿里云 EMR Serverless Spark的持续演进
  • docker 安装 milvus standalone 版本 + attu
  • 工业路由器赋能仓库消防预警,智慧消防物联网解决方案
  • 用户体验升级:表单失焦调用接口验证,错误信息即时可视化
  • Siri在WWDC中的缺席显得格外刺眼
  • 深入解析 Nacos MCP Router:云原生时代的 MCP 服务调度中枢
  • 高考倒计时(vb.net,持续更新版本)
  • axios取消请求
  • skynet源码学习-skynet_timer定时器
  • Camera相机人脸识别系列专题分析之十二:人脸特征检测FFD算法之libvega_face.so数据结构详解
  • 【部署】使用华为云容器化部署Java项目指南
  • Linux 文件类型,目录与路径,文件与目录管理
  • 金融机构的网络安全
  • Ansible小试牛刀
  • django filter 统计数量 按属性去重
  • ubuntu搭建nfs服务centos挂载访问
  • Web应用安全漏洞扫描:原理、常用方法及潜在风险解析?
  • 破局与重构:人工智能深度赋能基础教育变革研究
  • Maxun:开源无代码网页数据提取平台的新选择