在更改时运行 PHPUnit 测试 [英] Run PHPUnit tests on change

查看:34
本文介绍了在更改时运行 PHPUnit 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当磁盘上的文件发生更改时,我想运行我的 PHPUnit 测试(或至少其中的一部分).非常类似于您可以使用grunt watch"执行的操作.我有一个项目,其中我有 JS 和 PHP,并且正在使用 Grunt.在那里,我使用 grunt watch 让 PHPUnit 在我的 JS 测试之上运行.虽然这很好用,但在仅 PHP 的项目中执行此操作似乎非常麻烦.我需要引入 grunt,并添加对 node.js 的依赖.另外,我有很多这样的 PHP 项目.因此,需要一个更简单的解决方案.

I'd like to run my PHPUnit tests (or at least a subset of them) whenever a file changes on disk. Very similar to what you can do with "grunt watch". I have a project in which I have both JS and PHP, and am using Grunt. There I shell out to PHPUnit to have it run on top of my JS tests using grunt watch. While that works just fine, it seems like an awful lot of hassle to do this in a PHP only project. I'd need to introduce grunt, and add a dependency on node. Plus I have a lot of such PHP projects. A more simple solution is thus in order.

推荐答案

可以使用node watch,挺甜的:

You can use node watch which is quite sweet:

运行 npm init 设置一个包(需要一分钟),然后

Run npm init to set up a package (takes a minute), then

npm install --save-dev watch

然后编辑您的 package.json 文件以包含这两个条目:

Then edit your package.json file to include these two entries:

"scripts": {
  "test": "bin/phpunit tests --color",
  "test:watch": "watch 'npm run --silent test' ."
},

然后触发观看:

npm run test:watch

(归功于 这很有趣文章)

这篇关于在更改时运行 PHPUnit 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆