我有一個PHPUnit測試,它用一個正則表達式驗證日誌文件的輸出。日誌文件看起來像這樣(第一行是空的,但我不知道如何顯示在這裏):phpunit assertRegExp()測試在UNIX中傳遞,在Windows中失敗
<empty line>
lfworker01:
-----------------------------------------------------------
Last update: 2012-06-14 11:43:17
Last Segment Sent: 2009-12-02 23:25:00 (1259792700)
Current Segement: 2009-12-03 00:25:00 (1259796300)
Clicks processed Segment: 3
Open sessions Segment: 1
Duration Segment: 0,06 sec
Speed Segment: 47,67 clicks/sec
Uptime: 0 days 00:00:00
Clicks processed overall: 3
Avg Speed overall: 81,70 clicks/sec
Current memory used: 16,75 MB
Max memory used: 16,75 MB
我驗證了正則表達式的內容:
$strExpectedMeasurementLog = "#
lfworker01:
-----------------------------------------------------------
Last update: \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}
Last Segment Sent: 2009-12-02 23:25:00 \(1259792700\)
Current Segement: 2009-12-03 00:25:00 \(1259796300\)
Clicks processed Segment: 3
Open sessions Segment: 1
Duration Segment: \d*,\d{2} sec
Speed Segment: \d*,\d{2} clicks/sec
Uptime: 0 days 00:00:00
Clicks processed overall: 3
Avg Speed overall: \d*,\d{2} clicks/sec
Current memory used: \d*,\d{2} MB
Max memory used: \d*,\d{2} MB#";
$strActualMeasurementLog = file_get_contents(dirname(__FILE__)."/applogs/measurement.log");
self::assertRegExp($strExpectedMeasurementLog, $strActualMeasurementLog);
PHPUnit的測試是在unix環境中創建的。此測試通過unix測試環境,但在Windows測試環境中失敗。我已經appyling此功能可將measurement.log文件替換爲UNIX換行符窗口換行:
public function unixtodos($strPathFile)
{
$strCurrent = file_get_contents($strPathFile);
$strPattern = "|\r\n|";
$strReplace = "\n";
$strNew = preg_replace($strPattern, $strReplace, $strCurrent);
file_put_contents($strPathFile, $strNew);
}
它仍然不匹配,我的想法:(
如果我下面的回答不工作也可能是某處的一個錯誤,所以請發表您使用您的每個UNIX和Windows環境的是PHP和PHPUnit的版本。還可以得到一個文本編輯器(例如scite就可以了),您可以在其中查看LF和CR字節,查看每臺計算機上的報告以及每臺計算機上的phpunit源文件。 –
並不完全,但您指出了我正確的方向來查看LF和CR字節並查看phpunit源文件。謝謝達倫! – mles