在Ubuntu上使用PhpStorm进行单元测试,可以按照以下步骤操作:
File
> Settings
(或使用快捷键 Ctrl+Alt+S
)。Language & Frameworks
> PHP
> CLI Interpreter
。+
按钮,选择 From Docker, Vagrant, VM, WSL, Remote...
。WSL
,然后选择你的WSL虚拟机中的Linux发行版本以及PHP可执行文件的路径。OK
确定配置。Settings
> Languages & Frameworks
> PHP
> Test Frameworks
> PHPUnit
中,设置PHPUnit库的路径。php --ini
命令查看Xdebug的配置文件,并添加以下配置:zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9001
xdebug.remote_autostart=1
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/tmp"
xdebug.idekey=PHPSTORM
Project
视图中,找到你的测试类或方法。Run
或 Debug
来运行单元测试。通过以上步骤,你就可以在PhpStorm中集成WSL虚拟机的PHP环境,并在Ubuntu上运行单元测试了。这样可以确保你的测试环境与生产环境一致,从而获得更准确的测试结果。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>