2016-05-17 69 views
0

我使用travis-ci來運行我的測試。在我的本地計算機中,我檢查了兩個PHP版本,這很好。但在Travis 5.6 PHP版本下的測試失敗了。但測試通過PHP 7.0版本傳遞。我不知道什麼是真正的問題。PHPUnit比較xml字符串與xml文件在PHP 5.6中失敗,但通過PHP 7.0

$client = static::createClient(); 
$crawler = $client->request('GET', '/sitemap.xml'); 

$this->assertEquals(200, $client->getResponse()->getStatusCode()); 
$this->assertXmlStringEqualsXmlFile(
    __DIR__ . '/../Resources/sample.xml', 
    $client->getResponse()->getContent() 
); 

我有一個sample.xml包含正確的XML結構的值。 我通過/sitemap.xml鏈接生成sitemap.xml。

我總是得到錯誤:兩個DOM不相等。

PHPUnit版本是5.1.3在我的電腦上。

這裏特拉維斯慈的日誌文件:

$ php --version 

PHP 5.6.5 (cli) (built: Feb 12 2015 01:41:10) 

Copyright (c) 1997-2014 The PHP Group 

Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies 

    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies 

    with Xdebug v2.2.7, Copyright (c) 2002-2015, by Derick Rethans 

$ composer --version 

You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug 

Composer version 1.2-dev (32a8a60695b9b9c9e2da01406ac3713903182669) 2016-05-17 13:08:17 

before_install.1 

0.00s$ if [[ ! $PHP = ${MIN_PHP%.*} && $TRAVIS_PULL_REQUEST != false ]]; then skip=1; fi 

before_install.2 

2.11s$ composer self-update --stable; 

You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug 

Updating to version 1.1.1 (stable channel). 

    Downloading: Connecting... Downloading: 100% 

Use composer self-update --rollback to return to version 32a8a60695b9b9c9e2da01406ac3713903182669 

before_install.3 

0.00s$ if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/symfony:${SYMFONY_VERSION}; fi 

install 

60.18s$ if [ ! $skip ]; then composer update --prefer-dist; fi 

You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug 

Loading composer repositories with package information 

Updating dependencies (including require-dev) 

    - Installing psr/log (1.0.0) 

    Loading from cache 

    - Installing doctrine/lexer (v1.0.1) 

    Loading from cache 

    - Installing doctrine/annotations (v1.2.7) 

    Loading from cache 

    - Installing doctrine/collections (v1.3.0) 

    Loading from cache 

    - Installing doctrine/cache (v1.6.0) 

    Loading from cache 

    - Installing doctrine/inflector (v1.1.0) 

    Loading from cache 

    - Installing doctrine/common (v2.6.1) 

    Loading from cache 

    - Installing symfony/polyfill-util (v1.1.1) 

    Loading from cache 

    - Installing paragonie/random_compat (v1.4.1) 

    Loading from cache 

    - Installing symfony/polyfill-php70 (v1.1.1) 

    Loading from cache 

    - Installing symfony/polyfill-php56 (v1.1.1) 

    Loading from cache 

    - Installing symfony/polyfill-mbstring (v1.1.1) 

    Loading from cache 

    - Installing symfony/symfony (v3.0.6) 

    Loading from cache 

    - Installing symfony/polyfill-intl-icu (v1.1.1) 

    Loading from cache 

    - Installing twig/twig (v1.24.0) 

    Loading from cache 

    - Installing sensio/framework-extra-bundle (v3.0.16) 

    Loading from cache 

    - Installing doctrine/instantiator (1.0.5) 

    Loading from cache 

    - Installing doctrine/dbal (v2.5.4) 

    Loading from cache 

    - Installing doctrine/orm (v2.5.4) 

    Loading from cache 

    - Installing doctrine/doctrine-cache-bundle (1.3.0) 

    Loading from cache 

    - Installing jdorn/sql-formatter (v1.2.17) 

    Loading from cache 

    - Installing doctrine/doctrine-bundle (1.6.2) 

    Loading from cache 

    - Installing myclabs/deep-copy (1.5.1) 

    Loading from cache 

    - Installing sebastian/version (1.0.6) 

    Loading from cache 

    - Installing sebastian/resource-operations (1.0.0) 

    Loading from cache 

    - Installing sebastian/global-state (1.1.1) 

    Loading from cache 

    - Installing sebastian/recursion-context (1.0.2) 

    Loading from cache 

    - Installing sebastian/exporter (1.2.1) 

    Loading from cache 

    - Installing sebastian/environment (1.3.7) 

    Loading from cache 

    - Installing sebastian/diff (1.4.1) 

    Loading from cache 

    - Installing sebastian/comparator (1.2.0) 

    Loading from cache 

    - Installing phpdocumentor/reflection-docblock (2.0.4) 

    Loading from cache 

    - Installing phpspec/prophecy (v1.6.0) 

    Loading from cache 

    - Installing phpunit/php-text-template (1.2.1) 

    Loading from cache 

    - Installing phpunit/phpunit-mock-objects (3.1.3) 

    Loading from cache 

    - Installing phpunit/php-timer (1.0.8) 

    Loading from cache 

    - Installing sebastian/code-unit-reverse-lookup (1.0.0) 

    Loading from cache 

    - Installing phpunit/php-token-stream (1.4.8) 

    Loading from cache 

    - Installing phpunit/php-file-iterator (1.4.1) 

    Loading from cache 

    - Installing phpunit/php-code-coverage (3.3.1) 

    Loading from cache 

    - Installing phpunit/phpunit (5.1.7) 

    Loading from cache 

paragonie/random_compat suggests installing ext-libsodium (Provides a modern crypto API that can be used to generate random bytes.) 

sensio/framework-extra-bundle suggests installing symfony/psr-http-message-bridge (To use the PSR-7 converters) 

doctrine/doctrine-cache-bundle suggests installing symfony/security-acl (For using this bundle to cache ACLs) 

sebastian/global-state suggests installing ext-uopz (*) 

phpdocumentor/reflection-docblock suggests installing dflydev/markdown (~1.0) 

phpdocumentor/reflection-docblock suggests installing erusev/parsedown (~1.0) 

phpunit/phpunit suggests installing phpunit/php-invoker (~1.1) 

Generating autoload files 

1.10s$ phpunit Tests/; 

PHPUnit 5.1.7 by Sebastian Bergmann and contributors. 

F....                5/5 (100%) 

Time: 973 ms, Memory: 28.25MB 

There was 1 failure: 

1) RepoSitemapBundle\Tests\Controller\DefaultControllerTest::testSitemapAction 

Failed asserting that two DOM documents are equal. 

--- Expected 

+++ Actual 

@@ @@ 

<?xml version="1.0"?> 

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9"> 

- <url> 

-  <loc>http://www.localhosttest/1</loc> 

-  <lastmod>2010-01-01</lastmod> 

-  <changefreq>daily</changefreq> 

-  <priority>0.9</priority> 

- </url> 

-</urlset> 

+      <url> 

+    <loc>http://www.localhosttest/1</loc> 

+    <lastmod>2010-01-01</lastmod> 

+    <changefreq>daily</changefreq> 

+    <priority>0.9</priority> 

+   </url> 

+   </urlset> 

/home/travis/build/botalaszlo/tmp-sitemap-bundle/Tests/Controller/DefaultControllerTest.php:37 

phar:///home/travis/.phpenv/versions/5.6.5/bin/phpunit/phpunit/TextUI/Command.php:152 

phar:///home/travis/.phpenv/versions/5.6.5/bin/phpunit/phpunit/TextUI/Command.php:104 

FAILURES! 

Tests: 5, Assertions: 10, Failures: 1. 

The command "phpunit Tests/;" exited with 1. 

但在PHP 7.0,這是沒有失敗。 我曾嘗試使用SimpleXml加載sample.xml文件,但我遇到了同樣的問題。

短期解決方案並不在PHP 5.6

回答

0

那是因爲從你的輸出字符串,並在文件中的字符串包含不等於彼此的空間和新的生產線運行測試。

如果你使用phpstorm並在那裏運行你的unittest。你可以看到差異並進行比較。 Phpstorm將通過點擊控制檯中斷言錯誤消息來向你顯示一個差異窗口。

+0

謝謝,但是如果我使用DomDocument,那麼保留whitespaces = false,不起作用。我沒有任何想法。這非常棘手。 – Dabagab

+0

你真的必須概述xml是完全一樣的。沒有額外的空格或製表符 –