如何在symfony webtestcase中测试内存使用情况

时间:2016-04-29 10:19:38

标签: symfony webtest

我只想通过WebTestCase方法跟踪我测试的请求所使用的全部内存量。 WebTestCase::testReturnValidUser方法中的类似内容:

$client = static::createClient();
        $client->enableProfiler();
        $crawler = $client->request(
            'GET',
            $userURL
        );

...

if ($profile = $client->getProfile()) {
    $this->assertLessThan(10, $profile->getSomethingForMemoryConsumption())
}

旁注:遗憾的是,我无法安装xhproof。 Brew似乎没有为我自己安装的php7提供xhproof。

1 个答案:

答案 0 :(得分:2)

好的我找到了:我可以简单地使用已存在的MemoryDataCollector而不定义我自己的DataCollector

    if ($profile = $client->getProfile()) {
        $this->assertLessThan(30000000, $profile->getCollector('memory')->getMemory());
    }