phpunit,Travis-CI和Symfony2 - 在本地通过但在Travis上失败

时间:2015-01-07 00:18:37

标签: php symfony phpunit travis-ci

我安装了Symfony2(2.6),并通过Travis CI运行phpunit。目前,我只有一个测试。它只是验证主页上是否存在文本。然而,经过一段时间后,它突然开始在特拉维斯失败了,我不明白为什么。

当我在本地运行phpunit时,除了Travis之外基本上都在运行。

Travis结果:https://travis-ci.org/etherealpost/etherealpost.com 示例失败:https://travis-ci.org/etherealpost/etherealpost.com/jobs/46139220

PHPUnit 4.4.0 by Sebastian Bergmann.
Configuration read from /home/travis/build/etherealpost/etherealpost.com/phpunit.xml.dist
Starting test 'EtherealPost\WebsiteBundle\Tests\Controller\DefaultControllerTest::testIndex'.
F
Time: 3.7 seconds, Memory: 78.00Mb
There was 1 failure:
1) EtherealPost\WebsiteBundle\Tests\Controller\DefaultControllerTest::testIndex
Failed asserting that false is true.
/home/travis/build/etherealpost/etherealpost.com/src/EtherealPost/WebsiteBundle/Tests/Controller/DefaultControllerTest.php:15

FAILURES!                            
Tests: 1, Assertions: 1, Failures: 1.
The command "phpunit -v --debug" exited with 1.
Done. Your build exited with 1.

.travis.yml文件:

language: php

php:
  - hhvm
  - 5.5
  - 5.6

services:
  - mongodb

matrix:
    allow_failures:
        - php: hhvm
        - php: 5.6

before_script:
  - phpenv config-add mongo.ini
  - composer install -n --no-interaction
  - cp app/config/parameters.yml.dist app/config/parameters.yml
  - php bin/console assets:install web --symlink
  - php bin/console assetic:dump

script: phpunit -v --debug

测试本身:

public function testIndex()
{
    $client = static::createClient();

    $crawler = $client->request('GET', '/');

    $this->assertTrue($crawler->filter('html:contains("Ethereal Post")')->count() > 0);
}

非常感谢任何建议。

编辑:分支并在$ crawlwer上执行var_dump会得到以下结果:

https://travis-ci.org/etherealpost/etherealpost.com/jobs/46141870

Starting test 'EtherealPost\WebsiteBundle\Tests\Controller\DefaultControllerTest::testIndex'.
Fclass Symfony\Component\DomCrawler\Crawler#1451 (4) {
  protected $uri =>
  string(17) "http://localhost/"
  private $defaultNamespacePrefix =>
  string(7) "default"
  private $namespaces =>
  array(0) {
  }
  private $storage =>
  array(1) {
    '0000000031ea54cc000000004ace6b3f' =>
    array(2) {
      'obj' =>
      class DOMElement#1197 (17) {
        ...
      }
      'inf' =>
      NULL
    }
  }
}
Time: 2.98 seconds, Memory: 77.75Mb
There was 1 failure:
1) EtherealPost\WebsiteBundle\Tests\Controller\DefaultControllerTest::testIndex
Failed asserting that false is true.

1 个答案:

答案 0 :(得分:-1)

最终找到了这个问题。为了解决这个问题,特别是对于Symfony2 / Travis,我必须在测试中进行var_dump($client->getResponse()->getContent());并让Travis重新运行以确定测试的确切内容。

默认情况下,Symfony2在Dev模式下运行(预期),并显示一些在生产模式下被禁止的警告,这些警告在本地运行。

相关问题