【发布时间】:2015-06-24 09:39:49
【问题描述】:
我正在使用 symfony2 和 phpunit 进行测试。
有没有类似的东西:
$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 config_dev.yml:
web_profiler:
toolbar: true
intercept_redirects: false
仍然得到:
致命错误:在 D:\Divers\Programmation\Web\xxx\src\AppBundle\Tests\Controller\ApplicationAvailabilityFunctionalTest.php 第 59 行中的非对象上调用成员函数 getCollector()
【问题讨论】:
-
再次查看我的答案。
标签: php symfony doctrine-orm phpunit