Php Travis测试失败,但在本地计算机上通过

Php Travis测试失败,但在本地计算机上通过,php,phpunit,travis-ci,Php,Phpunit,Travis Ci,以下测试从一个路径加载所有标记文件。它在本地工作,但在Travis上随机失败。有时,它会在没有任何故障的情况下通过,有时它会在一些PHP版本上通过。正在测试的类是 公共函数testLoadMultipleFiles() { $index\u content=“这是一个子页面索引”。PHP\u EOL.PHP\u EOL “这是'sub'文件夹中的index.md。”.PHP\u EOL.PHP\u EOL “Lorem ipsum door sit amet,concetetur adipisc

以下测试从一个路径加载所有标记文件。它在本地工作,但在Travis上随机失败。有时,它会在没有任何故障的情况下通过,有时它会在一些PHP版本上通过。正在测试的类是

公共函数testLoadMultipleFiles()
{
$index\u content=“这是一个子页面索引”。PHP\u EOL.PHP\u EOL
“这是'sub'文件夹中的index.md。

”.PHP\u EOL.PHP\u EOL “Lorem ipsum door sit amet,concetetur adipiscing elit.

”.PHP\u EOL.PHP\u EOL “Donec ultricies tristique nulla et mattis.

”.PHP\u EOL.PHP\u EOL “Phasellus id massa eget nisl congue blandit sit amet id ligula.

”。PHP\u EOL; $sub\u page\u content=“这是一个子页面”。PHP\u EOL.PHP\u EOL “这是'sub'文件夹中的page.md。

”.PHP\u EOL.PHP\u EOL “Lorem ipsum door sit amet,concetetur adipiscing elit.

”.PHP\u EOL.PHP\u EOL “Donec ultricies tristique nulla et mattis.

”.PHP\u EOL.PHP\u EOL “Phasellus id massa eget nisl congue blandit sit amet id ligula.

”。PHP\u EOL; //为SomeClass类创建存根。 $parser=$this->getMock('Michelf\MarkdownInterface',array('defaultTransform','transform'); $parser::staticExpects($this->at(0)) ->方法('defaultTransform') ->will($this->returnValue($index_content)); $parser::staticExpects($this->at(1)) ->方法('defaultTransform') ->will($this->returnValue($sub_page_content)); $loader=newmarkdownloader($parser); $files['sub/index.md']=数组( 'meta'=>数组( “标题”=>“子页索引” ), “内容”=>$index\u内容 ); $files['sub/page.md']=数组( 'meta'=>数组( “标题”=>“子页” ), “内容”=>$sub\u页面内容 ); $result=$loader->load(根目录'content/sub',数组('md'); $this->assertEquals($files,$result); }
Travis在失败的运行中显示以下内容:

There was 1 failure:
1) Zepto\FileLoader\MarkdownLoaderTest::testLoadMultipleFiles
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     'sub/index.md' => Array (
         'meta' => Array (...)
-        'content' => '<h2>This is a Sub Page Index</h2>
+        'content' => '<h2>This is a Sub Page</h2>

-        <p>This is index.md in the 'sub' folder.</p>
+        <p>This is page.md in the 'sub' folder.</p>
@@ @@
         'meta' => Array (...)
-        'content' => '<h2>This is a Sub Page</h2>
+        'content' => '<h2>This is a Sub Page Index</h2>

-        <p>This is page.md in the 'sub' folder.</p>
+        <p>This is index.md in the 'sub' folder.</p>

         <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

         <p>Donec ultricies tristique nulla et mattis.</p>

         <p>Phasellus id massa eget nisl congue blandit sit amet id ligula.</p>
         '
     )
 )
出现1次故障:
1) Zepto\FileLoader\MarkdownLoaderTest::TestLoadMultipleFile
断言两个数组相等失败。
---期望
+++实际的
@@ @@
排列(
'sub/index.md'=>数组(
'meta'=>数组(…)
-'内容'=>'这是一个子页索引
+'内容'=>'这是一个子页面
-这是'sub'文件夹中的index.md

+这是“子”文件夹中的page.md

@@ @@ 'meta'=>数组(…) -'内容'=>'这是一个子页面 +'内容'=>'这是一个子页索引 -这是“子”文件夹中的page.md

+这是'sub'文件夹中的index.md

Lorem ipsum dolor sit amet,是一位杰出的献身者

Donec ultricies tristique nulla et mattis

我喜欢吃巧克力,我喜欢舌苔

' ) )
很抱歉,雨篷衬板延迟了很长时间

只是一个猜测,但是你在本地使用MacOSX吗

MacOSX以字母顺序返回列表,但在linux上,文件系统以随机顺序列出文件


在您的测试错误消息中,您可以看到每次读取的文件都与预期相反,
索引
子页
,这让我相信,由于目录列表出现随机错误,测试失败(其他时候,当它通过文件系统时,会以正确的顺序返回两个文件)。我不了解任何phpunit,因此很遗憾,我无法帮助您了解具体情况

你完全正确,这很有道理。我已经重构/删除了那个代码,所以现在没关系了,但是谢谢你让我知道原因。
There was 1 failure:
1) Zepto\FileLoader\MarkdownLoaderTest::testLoadMultipleFiles
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
     'sub/index.md' => Array (
         'meta' => Array (...)
-        'content' => '<h2>This is a Sub Page Index</h2>
+        'content' => '<h2>This is a Sub Page</h2>

-        <p>This is index.md in the 'sub' folder.</p>
+        <p>This is page.md in the 'sub' folder.</p>
@@ @@
         'meta' => Array (...)
-        'content' => '<h2>This is a Sub Page</h2>
+        'content' => '<h2>This is a Sub Page Index</h2>

-        <p>This is page.md in the 'sub' folder.</p>
+        <p>This is index.md in the 'sub' folder.</p>

         <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

         <p>Donec ultricies tristique nulla et mattis.</p>

         <p>Phasellus id massa eget nisl congue blandit sit amet id ligula.</p>
         '
     )
 )