问题描述
在我的Laravel项目中,我想为一个文件运行PHPunit,就像这样:
$ composer run-script test tests/Unit/Services/OrderServiceTest.PHP
这是我的作曲家设置:
"scripts": {
"test": [
"@testenv","@PHPunit"
],"testenv": [
"PHP artisan config:cache --env=testing","PHP artisan config:clear"
],"PHPunit": [
"PHP ./vendor/PHPunit/PHPunit/PHPunit --"
]
}
但是,我遇到了这个错误:
www @ 287dd7480e22:/ var / www $ composer运行脚本测试tests / Unit / Services / OrderServiceTest.PHP
PHP artisan config:cache --env = testing'tests / Unit / Services / OrderServiceTest.PHP'
参数太多,预期参数为“ command”。
注意:
- 我看过这篇文章:How do you pass an argument to a composer script from the command line?。但是解决方案(在自定义作曲家脚本的末尾添加
--
)不适用于我的情况,或者我无法正确理解。 - 如果我不传递参数,则脚本可以正常运行。 (即为所有测试文件运行PHPunit)
解决方法
根据this comment in composer repository:
如果您执行脚本组并调用多个操作,则无法仅将参数传递给子脚本之一。