phpunit 更改php路径,源代码更改时自动重新运行PHPUnit测试

Automatically rerun PHPUnit tests when source code changes

68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f706870756e69742d776174636865722e7376673f7374796c653d666c61742d73717561726568747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f706870756e69742d776174636865722f6d61737465722e7376673f7374796c653d666c61742d73717561726568747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f706870756e69742d776174636865722e7376673f7374796c653d666c61742d73717561726568747470733a2f2f7374796c6563692e696f2f7265706f732f39383136333932332f736869656c643f6272616e63683d6d617374657268747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f706870756e69742d776174636865722e7376673f7374796c653d666c61742d737175617265

Wouldn't it be great if your PHPUnit tests would be automatically rerun whenever you change some code? This package can do exactly that.

With the package installed you can do this:

phpunit-watcher watch

Here's how it looks like:

296144fa59478109e01c9c76bfbdc8a4.png

This will run the tests and rerun them whenever a file in the app, src or tests directory is modified.

Want to pass some arguments to PHPUnit? No problem, just tack them on:

phpunit-watcher watch --filter=it_can_run_a_single_test

In his excellent talk at Laracon EU 2017 Amo Chohan shows our phpunit-watcher in action.

48bd34d14bdbacf7f2cb968da0ff3287.png

Support us

Learn how to create a package like this one, by watching our premium video course:

f5a7e6def3c8cda25268f7b20310a1b9.png

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install this package globally like this

composer global require spatie/phpunit-watcher

After that phpunit-watcher watch can be run in any directory on your system.

Alternatively you can install the package locally as a dev dependency in your project

composer require spatie/phpunit-watcher --dev

Locally installed you can run it with vendor/bin/phpunit-watcher watch

Usage

All the examples assume you've installed the package globally. If you opted for the local installation prepend vendor/bin/ everywhere where phpunit-watcher is mentioned.

You can start the watcher with:

phpunit-watcher watch

This will run the tests and rerun them whenever a file in the src or tests directory is modified.

Want to pass some arguments to PHPUnit? No problem, just tack them on:

phpunit-watcher watch --filter=it_can_run_a_single_test

Notes on interactive commands

When running phpunit-watcher from a Composer script, you may need to redirect input in order for the interactive commands to work:

"test:watch": "phpunit-watcher watch < /dev/tty"

On Windows, Currently, TTY is not being supported, so any interaction has been disabled. While watching for changes works, any arguments for PHPUnit have to be provided when initially calling phpunit-watcher.

Customization

Certain aspects of the behaviour of the tool can be modified. The file for options may be named .phpunit-watcher.yml, phpunit-watcher.yml or phpunit-watcher.yml.dist. The tool will look for a file in that order.

If a config file does not exist in the project directory, the tool will check if a file exists in any of the parent directories of the project directory.

Here's some example content. Read on for a more detailed explanation of all the options.

watch:

directories:

- src

- tests

fileMask: '*.php'

notifications:

passingTests: false

failingTests: false

phpunit:

binaryPath: vendor/bin/phpunit

arguments: '--stop-on-failure'

timeout: 180

Customize watched directories and files

You can customize the directories being watched by creating a file named .phpunit-watcher.yml in your project directory. Here's some example content:

watch:

directories:

- src

- tests

fileMask: '*.php'

Desktop notifications

By default the tool will display desktop notifications whenever the tests pass or fail. If you want to disable certain desktop notifications update .phpunit-watcher.yml by adding a notifications key.

notifications:

passingTests: false

failingTests: false

Help messages

By default the tool will display a helper for keyboard actions after each run. You can hide these help messages by adding a hideManual key in the .phpunit-watcher.yml.

hideManual: true

Customize PHPUnit

Binary

By default the tool use vendor/bin/phpunit as default PHPUnit binary file, however, it may be useful to be able to customize this value for people who have a binary file in a different location.

You can specificy it in the .phpunit-watcher.yml config file. Here's an example:

phpunit:

binaryPath: ./vendor/phpunit/phpunit/phpunit

Initial arguments

If you want to use pass the same arguments to PHPUnit everytime to watcher starts, you can specificy those in the .phpunit-watcher.yml config file. Here's an example:

phpunit:

arguments: '--stop-on-failure'

When starting the tool with some arguments (eg phpunit-watcher watch --filter=my_favourite_test) those arguments will get used instead of the ones specified in the config file.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.

Postcardware

You're free to use this package (it's MIT-licensed), but if you use it often we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

We started creating this package after reading this excellent article by Christoper Pitt

Interactive commands were inspired by Jest.

License

The MIT License (MIT). Please see License File for more information.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值