PHPUnit 命令行工具中的控制字符有什么问题?
当我从命令行运行 phpunit 时,控制字符被打印出来,而不是像控制字符一样。看看这个:
PHPUnit 3.6.5 by Sebastian Bergmann.
Configuration read from app\phpunit.xml.dist
...
Time: 1 second, Memory: 12.00Mb
‹[30;42m‹[2KOK (3 tests, 3 assertions)
‹[0m‹[2K
我假设像 <[30;42m<
> 这样的符号是某种控制字符,应该由控制台以不同的方式使用(定位光标、删除字符等)
。这里有错吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
发生这种情况是因为您已将 phpunit 配置为使用颜色。
但遗憾的是无法在 Windows 终端上创建彩色输出。
有一个未解决的问题
不显示这些问题Windows 上的字符无法转换为颜色
在 phpunit 问题跟踪器上,我正在为此开发一个补丁。现在您所能做的就是接受它或从 phpunit.xml 配置文件中删除
color="true"
。This happens because you have configured phpunit to use colors.
but sadly it is not possible to create colored output on a Windows terminal.
There is an open issue
to not show those chars on windows where they can't be translated into colors
on the phpunit issues tracker and I'm working on a patch for that.For now all you can do is to ether accept it or to remove the
color="true"
from your phpunit.xml configuration file.或者,只需使用 https://github.com/adoxa/ansicon/releases 即可获取 ansi 颜色在窗户上。
源代码:https://github.com/adoxa/ansicon
Alternatively, just use https://github.com/adoxa/ansicon/releases to get ansi colors on windows.
Source code: https://github.com/adoxa/ansicon
我最近在尝试在 Windows 7 上的 git bash 中从命令行运行 phpunit 时遇到了同样的问题。在对可能的各种解决方案进行了一些研究之后,我决定在这里分享我选择为自己实现的解决方案。
您可以从 git bash 中过滤掉 ANSI 颜色控制字符。创建一个名为
phpunit
的文件(注意:实际的 phpunit 脚本不在我的路径中,我主要仅从 intellij 运行单元测试)并将其放在$PATH
(我自己更喜欢~/bin
但没有任何规则):"$@"
告诉 bash 获取传递给脚本的其余参数并将它们转发到phpunit。2>&1
将 stderr 重定向到 stdout,确保在生成时生成的任何控制字符错误输出也将被过滤掉。最后,phpunit 生成的所有输出都通过 Perl 进行管道传输,并通过正则表达式
's/(?<= \e\[)2;//g'
,删除控制字符。最终结果是 phpunit 运行得很好,无论您使用什么 设置。
希望这有帮助!
I just recently ran into this same problem in trying to run phpunit from the command line in git bash on windows 7. After conducting some research into possible various solutions I decided to share the solution I chose to implement for myself, here.
You can filter out the ANSI color control characters from git bash. Create a file named
phpunit
(note: the actual phpunit script wasn't in my path and I was mainly running unit tests from intellij only) and put it anywhere in your$PATH
(I prefer~/bin
myself but there's no rule about that):The
"$@"
tells bash to take the rest of the arguments passed to the script and forward them to phpunit. The2>&1
redirects stderr to stdout, ensuring that any control characters generated in producing error output will also be filtered out.Finally, all of the output produced by phpunit is piped through perl and run through the regular expression
's/(?<=\e\[)2;//g'
, which strips out the control characters.The end result is that phpunit runs just fine, regardless of what
<phpunit colors=""
setting you are using.Hope this helps!
谢谢丹尼,你的回答非常有帮助。
对于想要实现这一点的用户,有一些提示:
在 ~/.bashrc 中为 phpunit 添加别名(只需添加以下行) 。如果您还没有 .bashrc,只需创建一个空文件。
alias phpunit="~/.phpunit.sh"
关闭你的bash并再次打开它
Thanx Danny, your answer was very helpful.
For users that want to implement this a few tips:
add an alias to phpunit in ~/.bashrc (just add the following line). If you don't have a .bashrc yet, just create an empty file.
alias phpunit="~/.phpunit.sh"
close your bash and open it again
正如他们所说,这对我有用。
转到 ~/ 目录中的 .bashrc 并添加
然后我只在 git bash 中使用 phpunitc 。您发送到 phpunit 的所有参数也将通过。
Just like what they said, this worked for me.
Go to .bashrc in your ~/ directory and add
Then I just use phpunitc in git bash. All parameters you send to phpunit will also pass through.