簡體   English   中英

PHPUnit 無法識別給定目錄中的測試

[英]PHPUnit doesn't recognize tests in given directory

我正在創建一個項目,我在其中使用作曲家來獲取我所有的依賴項。 我也使用 phpunit,我剛剛將我的項目遷移到 phpunit 6.0。 在此更改之前,我的 phpunit 始終正常工作。

在此之前,我使用的是5.7.13版本。

我目前在我的composer.json中需要這樣的包:

  "require-dev": {
    "phpunit/phpunit": "^6.0"
  },

我讓我所有的測試擴展\PHPUnit\Framework\TestCase類而不是PHPUnit_Framework_TestCase類。

我的配置保持不變,看起來像這樣:

<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="vendor/autoload.php"
         color="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         stopOnFailures="false"
         syntaxCheck="false">
    <testsuites>
        <testsuite name="Unit Tests">
            <directory>./tests/bas/ProjectName/</directory>
        </testsuite>
    </testsuites>
</phpunit>

我的目錄結構如下所示:

├───src
│   └───bas
│       └───ProjectName
│           └───... source files
├───tests
│   └───bas
│       └───ProjectName
│           ├───...test files like "ExampleTest.php"

在項目的根目錄中打開終端並輸入phpunit命令時,它會顯示以下消息:

Sebastian Bergmann 的 PHPUnit 3.7.21。

從 C:\Users\Bas\Web_development\ProjectName\phpunit.xml 讀取的配置

時間:30 毫秒,內存:4.00MB

沒有執行任何測試!

我已經嘗試將suffix="Test.php"添加到 phpunit 配置中的directory標記中。

我還嘗試從 Composer 中刪除/vendor/文件夾並通過composer update命令安裝包。

我所有的測試函數都以test詞開頭。


根據John Smith 的回答,我收到以下錯誤消息:

dir=$(d=${0%[/\\]*}; cd "$d"; cd "../phpunit/phpunit" && pwd)

# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
        # Cygwin paths start with /cygdrive/ which will break windows PHP,
        # so we need to translate the dir path to windows format. However
        # we could be using cygwin PHP which does not require this, so we
        # test if the path to PHP starts with /cygdrive/ rather than /usr/bin
        if [[ $(which php) == /cygdrive/* ]]; then
                dir=$(cygpath -m "$dir");
        fi
fi

dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/phpunit" "$@"

如果您使用作曲家來管理依賴項,那么當您從項目的根目錄運行phpunit時,您可能會執行全局和舊的 phpunit 二進制文件。

您只需運行測試:

Sebastian Bergmann 的 PHPUnit 3.7.21。

您應該使用命令php./vendor/bin/phpunit運行本地依賴項,而不是全局執行

嘗試運行php "vendor/phpunit/phpunit/phpunit"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM