phpunit和symfony2:如何断言来自客户端或响应的查询数?
我使用symfony2和phpunit进行测试 是否有类似于:phpunit和symfony2:如何断言来自客户端或响应的查询数?,php,symfony,doctrine-orm,phpunit,Php,Symfony,Doctrine Orm,Phpunit,我使用symfony2和phpunit进行测试 是否有类似于: $client->getResponse()->getNumberOfQueries() 如果不是类似的,那么从响应中检索查询数量的方法是什么 我想快速检查我没有优化查询的地方 编辑:我的变量$profile似乎总是空的 /** * @dataProvider urlProvider * @param $url */ public function testPageIsSuccessful($url) {
$client->getResponse()->getNumberOfQueries()
如果不是类似的,那么从响应中检索查询数量的方法是什么
我想快速检查我没有优化查询的地方
编辑:我的变量$profile
似乎总是空的
/**
* @dataProvider urlProvider
* @param $url
*/
public function testPageIsSuccessful($url)
{
$client = self::createClient(array(), array(
'PHP_AUTH_USER' => 'xx',
'PHP_AUTH_PW' => 'xx',
));
$client->enableProfiler();
$client->followRedirects();
$client->request('GET', $url);
$this->assertEquals(200, $client->getResponse()->getStatusCode());
if ($profile = $client->getProfile())
{
$this->assertLessThan(10, $profile->getCollector('db')->getQueryCount());
}
}
在lmy配置_dev.yml中:
web_profiler:
toolbar: true
intercept_redirects: false
仍然得到:
致命错误:在第59行的D:\Divers\Programmation\Web\xxx\src\AppBundle\Tests\Controller\ApplicationAvailabilityFunctionalTest.php中对非对象调用成员函数getCollector()
在功能测试中,您可以访问探查器,并获取请求期间的查询数:
类HelloControllerTest扩展WebTestCase
{
公共函数testIndex()
{
$client=static::createClient();
$client->enableProfiler();
$crawler=$client->request('GET','/hello/Fabien');
$this->assertLessThan(30,$profile->getCollector('db')->getQueryCount());
}
}
确保已将探查器配置为在测试环境中收集分析数据:
# app/config/config_test.yml
# ...
framework:
profiler:
enabled: true
collect: true
从“”食谱中了解更多信息。您好!谢谢,这似乎是正确的方法,但是按照描述的方式检索分析器,我只得到一个空的概要文件,你知道为什么吗?(请查看我的编辑)。再次查看我的答案。