【发布时间】:2014-08-06 03:53:56
【问题描述】:
我正在尝试使用 DemoController 在 Symfony2 中运行我的第一个功能测试。
如果我从浏览器加载页面,则显示的数据是正确的。
但是,如果我尝试使用命令 phpunit -c app 运行测试,则会收到以下错误消息:
There was 1 error:
1) Blog\CoreBundle\Tests\Controller\AuthorControllerTest::testShow
Object of class Symfony\Component\DomCrawler\Crawler could not be converted to string
这是我的 AuthorControllerTest 类:
<?php
namespace Blog\CoreBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* Class AuthorControllerTest
*/
class AuthorControllerTest extends WebTestCase
{
/**
* Test show author
*/
public function testShow()
{
$client = static::createClient();
/** @var Author $author */
$author = $client->getContainer()
->get('doctrine')
->getManager()
->getRepository('ModelBundle:Author')
->findFirst();
$authorPostCount = $author->getPosts()->count();
$crawler = $client->request('GET', '/author/'.$author->getSlug());
$this->assertTrue($client->getResponse()->isSuccessful(), 'The response was not successful');
$this->assertTrue($authorPostCount, $crawler->filter('h2'), 'There should be '.$authorPostCount.' posts');
}
}
【问题讨论】:
标签: symfony symfony-2.1