phpunit、Travis-CI 和 Symfony2 - 在本地通过但在 Travis 上失败
phpunit, Travis-CI, and Symfony2 - Passes locally but fails on Travis
我安装了 Symfony2 (2.6),并在通过 Travis CI 提交时运行 phpunit。目前,我只有一个测试。它只是验证主页上是否存在文本。然而,它在通过一段时间后突然在 Travis 上开始失败,我不知道为什么。
当我在本地运行 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.
终于找到问题了。为了解决它,特别是针对 Symfony2/Travis,我不得不在测试中执行 var_dump($client->getResponse()->getContent());
并让 Travis 重新运行以确定测试到底看到了什么。
看起来 Symfony2 在开发模式下 运行 默认情况下(意料之中)并且显示了一些在生产模式下被抑制的警告,在本地是 运行。
我安装了 Symfony2 (2.6),并在通过 Travis CI 提交时运行 phpunit。目前,我只有一个测试。它只是验证主页上是否存在文本。然而,它在通过一段时间后突然在 Travis 上开始失败,我不知道为什么。
当我在本地运行 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.
终于找到问题了。为了解决它,特别是针对 Symfony2/Travis,我不得不在测试中执行 var_dump($client->getResponse()->getContent());
并让 Travis 重新运行以确定测试到底看到了什么。
看起来 Symfony2 在开发模式下 运行 默认情况下(意料之中)并且显示了一些在生产模式下被抑制的警告,在本地是 运行。