Travis测试失败但通过本地机器

时间:2014-01-27 23:53:41

标签: php phpunit travis-ci

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

public function testLoadMultipleFiles()
{
    $index_content = "<h2>This is a Sub Page Index</h2>" . PHP_EOL . PHP_EOL
        . "<p>This is index.md in the 'sub' folder.</p>" . PHP_EOL . PHP_EOL
        . "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>" . PHP_EOL . PHP_EOL
        . "<p>Donec ultricies tristique nulla et mattis.</p>" . PHP_EOL. PHP_EOL
        . "<p>Phasellus id massa eget nisl congue blandit sit amet id ligula.</p>" . PHP_EOL;

    $sub_page_content = "<h2>This is a Sub Page</h2>" . PHP_EOL . PHP_EOL
            . "<p>This is page.md in the 'sub' folder.</p>" . PHP_EOL . PHP_EOL
            . "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>" . PHP_EOL . PHP_EOL
            . "<p>Donec ultricies tristique nulla et mattis.</p>" . PHP_EOL . PHP_EOL
            . "<p>Phasellus id massa eget nisl congue blandit sit amet id ligula.</p>". PHP_EOL;

    // Create a stub for the SomeClass class.
    $parser = $this->getMock('Michelf\MarkdownInterface', array('defaultTransform', 'transform'));

    $parser::staticExpects($this->at(0))
            ->method('defaultTransform')
            ->will($this->returnValue($index_content));

    $parser::staticExpects($this->at(1))
            ->method('defaultTransform')
            ->will($this->returnValue($sub_page_content));

    $loader = new MarkdownLoader($parser);

    $files['sub/index.md'] = array(
        'meta'    => array(
            'title'         => 'Sub Page Index'
        ),
        'content' => $index_content
    );

    $files['sub/page.md'] = array(
        'meta'    => array(
            'title'         => 'Sub Page'
        ),
        'content' => $sub_page_content
    );

    $result = $loader->load(ROOT_DIR . 'content/sub', array('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 个答案:

答案 0 :(得分:2)

对于长时间的瞄准而感到抱歉。

只是一个猜测,但你在本地使用Mac OS X吗?

Mac OS X按字母顺序返回列表,但在linux上,文件系统按随机顺序列出文件。

在您的测试错误消息中,您可以看到每个读取的文件都与预期的文件相反,indexsub page,这让我相信由于目录列表而导致测试失败在随机错误中(其他时候,它通过文件系统返回正确顺序的两个文件)。我不知道任何phpunit所以我不能帮你详细说明。