【问题标题】:phpunit replies unrecongnized option --envphpunit 回复无法识别的选项 --env
【发布时间】:2020-01-09 06:27:48
【问题描述】:

我试图在 laravel 中使用 phpunit 命令执行我的测试用例,但命令回复如下

$ phpunit --env=testing
PHPUnit 3.7.28 by Sebastian Bergmann.

unrecognized option --env

有人熟悉吗,请帮帮我。

编辑:

以下是该选项不存在的命令的帮助。我该怎么办?

$ phpunit --help
PHPUnit 3.7.28 by Sebastian Bergmann.

Usage: phpunit [switches] UnitTest [UnitTest.php]
       phpunit [switches] <directory>

  --log-junit <file>        Log test execution in JUnit XML format to file.
  --log-tap <file>          Log test execution in TAP format to file.
  --log-json <file>         Log test execution in JSON format.

  --coverage-clover <file>  Generate code coverage report in Clover XML format.
  --coverage-html <dir>     Generate code coverage report in HTML format.
  --coverage-php <file>     Serialize PHP_CodeCoverage object to file.
  --coverage-text=<file>    Generate code coverage report in text format.
                            Default to writing to the standard output.

  --testdox-html <file>     Write agile documentation in HTML format to file.
  --testdox-text <file>     Write agile documentation in Text format to file.

  --filter <pattern>        Filter which tests to run.
  --testsuite <pattern>     Filter which testsuite to run.
  --group ...               Only runs tests from the specified group(s).
  --exclude-group ...       Exclude tests from the specified group(s).
  --list-groups             List available test groups.
  --test-suffix ...         Only search for test in files with specified
                            suffix(es). Default: Test.php,.phpt

  --loader <loader>         TestSuiteLoader implementation to use.
  --printer <printer>       TestSuiteListener implementation to use.
  --repeat <times>          Runs the test(s) repeatedly.

  --tap                     Report test execution progress in TAP format.
  --testdox                 Report test execution progress in TestDox format.

  --colors                  Use colors in output.
  --stderr                  Write to STDERR instead of STDOUT.
  --stop-on-error           Stop execution upon first error.
  --stop-on-failure         Stop execution upon first error or failure.
  --stop-on-skipped         Stop execution upon first skipped test.
  --stop-on-incomplete      Stop execution upon first incomplete test.
  --strict                  Run tests in strict mode.
  -v|--verbose              Output more verbose information.
  --debug                   Display debugging information during test execution.

  --process-isolation       Run each test in a separate PHP process.
  --no-globals-backup       Do not backup and restore $GLOBALS for each test.
  --static-backup           Backup and restore static attributes for each test.

  --bootstrap <file>        A "bootstrap" PHP file that is run before the tests.
  -c|--configuration <file> Read configuration from XML file.
  --no-configuration        Ignore default configuration file (phpunit.xml).
  --include-path <path(s)>  Prepend PHP's include_path with given path(s).
  -d key[=value]            Sets a php.ini value.

  -h|--help                 Prints this usage information.
  --version                 Prints the version and exits.

【问题讨论】:

    标签: unit-testing laravel-5 phpunit


    【解决方案1】:

    您应该知道您的 PHPUnit 版本非常过时,2014 年 11 月。请更新。

    另外,你想用 --env 做什么?你可以在根目录下的phpunit.xml中配置应用环境,如下:

    <php>
        <env name="APP_ENV" value="testing"/>
        ... more variables
    </php>
    

    【讨论】:

    • 是的。我关注了 laravel doc laravel.com/docs/5.6/testing,其中提到了这个选项进行测试。我发现如果我运行“./vendor/bin/phpunit”然后没有选项它会尝试执行测试
    • “当运行 PHPUnit 测试或使用 --env=testing 选项执行 Artisan 命令时,此文件将覆盖 .env 文件。” 这意味着 OR “phpunit commands” 或 “artisan command with the --env范围”。所以不是 phpunit —env 而是 php artisan —env :)
    猜你喜欢
    • 1970-01-01
    • 2011-04-18
    • 2015-11-01
    • 2012-03-31
    • 2020-07-17
    • 2018-03-18
    • 2014-11-28
    • 1970-01-01
    • 2014-08-21
    相关资源
    最近更新 更多