我的服务器和symfony2项目上有PHPCi。当我运行构建项目时,我从phpunit得到了这个错误:
失败:ApiBundle \ Tests \ Controller \ BooksControllerTest :: testBooksAction 无法断言预期的500场比赛为200。
但是如果我在控制台中运行:$ phpunit -c app/
- 一切正常,我没有得到错误
有人可以面对吗?
我的BooksControllerTest.php:
<?php
namespace ApiBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class BooksControllerTest extends WebTestCase
{
public function testBooksAction()
{
$client = static::createClient();
$crawler = $client->request('GET', '/api/books');
$this->assertEquals(
200,
$client->getResponse()->getStatusCode()
);
$this->assertTrue(
$client->getResponse()->headers->contains(
'Content-Type',
'application/json'
)
);
}
}
和phpci.yml:
build_settings:
ignore:
- "vendor"
- "tests"
setup:
composer:
action: "update"
test:
php_unit:
config:
- "app/phpunit.xml"
我在app /中的phpunit.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="bootstrap.php.cache"
>
<testsuites>
<testsuite name="Project Test Suite">
<directory>../src/ApiBundle/Tests</directory>
</testsuite>
</testsuites>
</phpunit>
答案 0 :(得分:0)
首先,在测试环境中,您必须运行composer install,否则测试环境将包含不同版本的依赖项。
setup:
composer:
action: "install"