【问题标题】:php\r nu such file or directory when trying to run phpunitphp\r 尝试运行 phpunit 时没有这样的文件或目录
【发布时间】:2019-10-11 06:37:39
【问题描述】:

我正在尝试在 virtualbox(Ubuntu) 中的 vagrant 服务器中为学校项目运行 phpunit,但我做不到。

我确定我的那个 phpunit 位于 vendor/bin/phpunit 中,并且我的测试项目也在正确的目录中,并且所有内容都拼写正确,所以我不明白为什么会出现此错误。

我尝试做:

vendor/bin/phpunit test/model/PDOGameModelTest.php

我得到的错误是:

usr/bin/env: 'php\r': 没有这样的文件或目录

【问题讨论】:

    标签: php phpunit vagrant


    【解决方案1】:

    您的文件使用 DOS 文件结尾 (CR+LF) 而 Ubuntu 使用 Unix one (LF)。您必须使用命令 dos2unix 转换您的文件:

    安装它:

    sudo apt install dos2unix
    

    将其转换为:

    dos2unix test/model/PDOGameModelTest.php
    

    然后:

    vendor/bin/phpunit test/model/PDOGameModelTest.php
    

    编辑:另一种解决方案

    awk '{ sub("\r$", ""); print }' test/model/PDOGameModelTest.php > test/model/PDOGameModelTest_converted.php 
    

    【讨论】:

    • 你可以试试:awk '{ sub("\r$", ""); print }' test/model/PDOGameModelTest.php > test/model/PDOGameModelTest_converted.php 然后 vendor/bin/phpunit test/model/PDOGameModelTest_converted.php ?
    • 我很高兴能帮上忙!我已经编辑了我的答案。问题解决后,您现在可以将问题标记为resolved。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2016-08-15
    • 2013-07-03
    • 2013-09-04
    • 2016-02-19
    • 2021-11-18
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    相关资源
    最近更新 更多