簡體   English   中英

PHPUnit - 我可以為較低版本的PHP運行測試嗎?

[英]PHPUnit - Can I run tests for a lower version of PHP?

正如這里所解釋的,如果PHP版本至少為5.3.0,我可以運行測試。

但是,如果我想為低於5.3.0的PHP版本運行測試?

我寫這個:

<file phpVersion="5.3.0" phpVersionOperator="<=">./tests/unit/test-file.php</file>

但是我收到了這個錯誤

Unescaped '<' not allowed in attributes values

我怎么能這樣做?

version_compare函數的doc一致:

可能的運算符分別為:<,lt,<=,le,>,gt,> =,ge,==,=,eq,!=,<>,ne。

即在PHPUnit的核心用在這里 ,你可以簡單地指定lt的價值。 例如:

<file phpVersion="5.3.0" phpVersionOperator="lt">./tests/unit/test-file.php</file>

希望這有幫助

注意:

如果文件也包含在測試套件的另一個指令中,那么它將被執行,例如在這種情況下:

<testsuite name="Project Test Suite">
    <directory>tests</directory>  <!-- This line execute the test -->
    <file phpVersion="5.3.0" phpVersionOperator="<=">./tests/unit/test-file.php</file>
</testsuite>

因此,在測試套件定義中要有選擇性。

您需要在屬性內部轉義<:

<file phpVersion="5.3.0" phpVersionOperator="&lt;=">./tests/unit/test-file.php</file>

暫無
暫無

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

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