2010-08-28 14:23:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-08-28 14:23:21 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Tests\Component\HttpKernel\Profiler;
|
|
|
|
|
|
|
|
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
|
2011-02-15 03:07:07 +00:00
|
|
|
use Symfony\Component\HttpKernel\Profiler\SqliteProfilerStorage;
|
2010-08-28 14:23:21 +01:00
|
|
|
use Symfony\Component\HttpKernel\Profiler\Profiler;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
class ProfilerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testCollect()
|
|
|
|
{
|
2011-11-14 17:37:25 +00:00
|
|
|
if (!class_exists('SQLite3') && (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers()))) {
|
|
|
|
$this->markTestSkipped('This test requires SQLite support in your environment');
|
|
|
|
}
|
|
|
|
|
2010-08-28 14:23:21 +01:00
|
|
|
$request = new Request();
|
|
|
|
$request->query->set('foo', 'bar');
|
|
|
|
$response = new Response();
|
|
|
|
$collector = new RequestDataCollector();
|
|
|
|
|
2011-01-14 07:31:58 +00:00
|
|
|
$tmp = tempnam(sys_get_temp_dir(), 'sf2_profiler');
|
|
|
|
if (file_exists($tmp)) {
|
|
|
|
@unlink($tmp);
|
|
|
|
}
|
2011-03-16 14:16:21 +00:00
|
|
|
$storage = new SqliteProfilerStorage('sqlite:'.$tmp);
|
2011-01-18 13:53:15 +00:00
|
|
|
$storage->purge();
|
2010-08-28 14:23:21 +01:00
|
|
|
|
|
|
|
$profiler = new Profiler($storage);
|
2010-09-02 12:54:32 +01:00
|
|
|
$profiler->add($collector);
|
2011-05-30 17:54:40 +01:00
|
|
|
$profile = $profiler->collect($request, $response);
|
2010-08-28 14:23:21 +01:00
|
|
|
|
2011-05-30 17:54:40 +01:00
|
|
|
$profile = $profiler->loadProfile($profile->getToken());
|
2010-09-02 12:54:32 +01:00
|
|
|
$this->assertEquals(array('foo' => 'bar'), $profiler->get('request')->getRequestQuery()->all());
|
2011-01-14 07:31:58 +00:00
|
|
|
|
|
|
|
@unlink($tmp);
|
2010-08-28 14:23:21 +01:00
|
|
|
}
|
|
|
|
}
|