merged branch stloyd/profiler_by_method (PR #2824)

Commits
-------

5f22268 [Profiler] Sync with master
1aef4e8 Adds collecting info about request method and allowing searching by it

Discussion
----------

[WebProfiler] Add ability to filter data by request method

Bug fix: no
Feature addition: yes
Backwards compatibility break: yes
Symfony2 tests pass: yes
Fixes the following tickets: #1515

For discussion & description checkout: #1515 & #2279

---------------------------------------------------------------------------

by fabpot at 2011/12/11 10:02:41 -0800

After merging this PR, the toolbar is not displayed anymore for me.

---------------------------------------------------------------------------

by stof at 2011/12/12 14:18:20 -0800

@fabpot the toolbar works for me using this branch
This commit is contained in:
Fabien Potencier 2011-12-13 14:13:16 +01:00
commit bf45b22447
13 changed files with 173 additions and 83 deletions

View File

@ -191,22 +191,25 @@ class ProfilerController extends ContainerAware
$profiler->disable();
if (null === $session = $this->container->get('request')->getSession()) {
$ip =
$url =
$limit =
$token = null;
$ip =
$method =
$url =
$limit =
$token = null;
} else {
$ip = $session->get('_profiler_search_ip');
$url = $session->get('_profiler_search_url');
$limit = $session->get('_profiler_search_limit');
$token = $session->get('_profiler_search_token');
$ip = $session->get('_profiler_search_ip');
$method = $session->get('_profiler_search_method');
$url = $session->get('_profiler_search_url');
$limit = $session->get('_profiler_search_limit');
$token = $session->get('_profiler_search_token');
}
return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:search.html.twig', array(
'token' => $token,
'ip' => $ip,
'url' => $url,
'limit' => $limit,
'token' => $token,
'ip' => $ip,
'method' => $method,
'url' => $url,
'limit' => $limit,
));
}
@ -223,15 +226,17 @@ class ProfilerController extends ContainerAware
$profile = $profiler->loadProfile($token);
$ip = $this->container->get('request')->query->get('ip');
$url = $this->container->get('request')->query->get('url');
$limit = $this->container->get('request')->query->get('limit');
$ip = $this->container->get('request')->query->get('ip');
$method = $this->container->get('request')->query->get('method');
$url = $this->container->get('request')->query->get('url');
$limit = $this->container->get('request')->query->get('limit');
return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:results.html.twig', array(
'token' => $token,
'profile' => $profile,
'tokens' => $profiler->find($ip, $url, $limit),
'tokens' => $profiler->find($ip, $url, $limit, $method),
'ip' => $ip,
'method' => $method,
'url' => $url,
'limit' => $limit,
'panel' => null,
@ -250,13 +255,15 @@ class ProfilerController extends ContainerAware
$request = $this->container->get('request');
$ip = preg_replace('/[^\d\.]/', '', $request->query->get('ip'));
$url = $request->query->get('url');
$limit = $request->query->get('limit');
$token = $request->query->get('token');
$ip = preg_replace('/[^\d\.]/', '', $request->query->get('ip'));
$method = $request->query->get('method');
$url = $request->query->get('url');
$limit = $request->query->get('limit');
$token = $request->query->get('token');
if (null !== $session = $request->getSession()) {
$session->set('_profiler_search_ip', $ip);
$session->set('_profiler_search_method', $method);
$session->set('_profiler_search_url', $url);
$session->set('_profiler_search_limit', $limit);
$session->set('_profiler_search_token', $token);
@ -266,20 +273,21 @@ class ProfilerController extends ContainerAware
return new RedirectResponse($this->container->get('router')->generate('_profiler', array('token' => $token)));
}
$tokens = $profiler->find($ip, $url, $limit);
$tokens = $profiler->find($ip, $url, $limit, $method);
return new RedirectResponse($this->container->get('router')->generate('_profiler_search_results', array(
'token' => $tokens ? $tokens[0]['token'] : 'empty',
'ip' => $ip,
'url' => $url,
'limit' => $limit,
'token' => $tokens ? $tokens[0]['token'] : 'empty',
'ip' => $ip,
'method' => $method,
'url' => $url,
'limit' => $limit,
)));
}
protected function getTemplateNames($profiler)
{
$templates = array();
foreach ($this->container->getParameter('data_collector.templates') as $id => $arguments) {
foreach ($this->container->getParameter('data_collector.templates') as $arguments) {
if (null === $arguments) {
continue;
}

View File

@ -8,6 +8,7 @@
<tr>
<th>Token</th>
<th>IP</th>
<th>Method</th>
<th>URL</th>
<th>Time</th>
</tr>
@ -15,6 +16,7 @@
<tr>
<td><a href="{{ path('_profiler', { 'token': elements.token }) }}">{{ elements.token }}</a></td>
<td>{{ elements.ip }}</td>
<td>{{ elements.method }}</td>
<td>{{ elements.url }}</td>
<td>{{ elements.time|date('r') }}</td>
</tr>

View File

@ -7,6 +7,13 @@
<label for="ip">IP</label>
<input type="text" name="ip" id="ip" value="{{ ip }}" />
<div class="clear_fix"></div>
<label for="method">Method</label>
<select name="method" id="method">
{% for m in ['', 'DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'] %}
<option{{ m == method ? ' selected="selected"' : '' }}>{{ m }}</option>
{% endfor %}
</select>
<div class="clear_fix"></div>
<label for="url">URL</label>
<input type="text" name="url" id="url" value="{{ url }}" />
<div class="clear_fix"></div>

View File

@ -46,7 +46,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
/**
* {@inheritdoc}
*/
public function find($ip, $url, $limit)
public function find($ip, $url, $limit, $method)
{
$file = $this->getIndexFilename();
@ -66,26 +66,27 @@ class FileProfilerStorage implements ProfilerStorageInterface
break;
}
if ($line === "") {
if ($line === '') {
continue;
}
list($csvToken, $csvIp, $csvUrl, $csvTime, $csvParent) = str_getcsv($line);
list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent) = str_getcsv($line);
if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url)) {
if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url) || $method && false === strpos($csvMethod, $method)) {
continue;
}
$row = array(
'token' => $csvToken,
'ip' => $csvIp,
'method' => $csvMethod,
'url' => $csvUrl,
'time' => $csvTime,
'parent' => $csvParent,
);
$result[] = $row;
$limit--;
--$limit;
}
fclose($file);
@ -143,6 +144,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
'children' => array_map(function ($p) { return $p->getToken(); }, $profile->getChildren()),
'data' => $profile->getCollectors(),
'ip' => $profile->getIp(),
'method' => $profile->getMethod(),
'url' => $profile->getUrl(),
'time' => $profile->getTime(),
);
@ -159,6 +161,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
fputcsv($file, array(
$profile->getToken(),
$profile->getIp(),
$profile->getMethod(),
$profile->getUrl(),
$profile->getTime(),
$profile->getParent() ? $profile->getParent()->getToken() : null,
@ -219,7 +222,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
break;
}
$str = $char . $str;
$str = $char.$str;
if (ftell($file) === 1) {
// All file is read, so we move cursor to the position 0
@ -237,6 +240,7 @@ class FileProfilerStorage implements ProfilerStorageInterface
{
$profile = new Profile($token);
$profile->setIp($data['ip']);
$profile->setMethod($data['method']);
$profile->setUrl($data['url']);
$profile->setTime($data['time']);
$profile->setCollectors($data['data']);

View File

@ -37,9 +37,9 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
*
* @return array An array of tokens
*/
public function find($ip, $url, $limit)
public function find($ip, $url, $limit, $method)
{
$cursor = $this->getMongo()->find($this->buildQuery($ip, $url), array('_id', 'parent', 'ip', 'url', 'time'))->sort(array('time' => -1))->limit($limit);
$cursor = $this->getMongo()->find($this->buildQuery($ip, $url, $method), array('_id', 'parent', 'ip', 'method', 'url', 'time'))->sort(array('time' => -1))->limit($limit);
$tokens = array();
foreach ($cursor as $profile) {
@ -93,6 +93,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
'parent' => $profile->getParent() ? $profile->getParent()->getToken() : null,
'data' => serialize($profile->getCollectors()),
'ip' => $profile->getIp(),
'method' => $profile->getMethod(),
'url' => $profile->getUrl(),
'time' => $profile->getTime()
);
@ -165,9 +166,10 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
/**
* @param string $ip
* @param string $url
* @param string $method
* @return array
*/
private function buildQuery($ip, $url)
private function buildQuery($ip, $url, $method)
{
$query = array();
@ -179,6 +181,10 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
$query['url'] = $url;
}
if (!empty($method)) {
$query['method'] = $method;
}
return $query;
}
@ -192,6 +198,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
'token' => $data['_id'],
'parent' => isset($data['parent']) ? $data['parent'] : null,
'ip' => isset($data['ip']) ? $data['ip'] : null,
'method' => isset($data['method']) ? $data['method'] : null,
'url' => isset($data['url']) ? $data['url'] : null,
'time' => isset($data['time']) ? $data['time'] : null,
'data' => isset($data['data']) ? $data['data'] : null,
@ -206,6 +213,7 @@ class MongoDbProfilerStorage implements ProfilerStorageInterface
{
$profile = new Profile($data['token']);
$profile->setIp($data['ip']);
$profile->setMethod($data['method']);
$profile->setUrl($data['url']);
$profile->setTime($data['time']);
$profile->setCollectors(unserialize($data['data']));

View File

@ -33,7 +33,7 @@ class MysqlProfilerStorage extends PdoProfilerStorage
}
$db = new \PDO($this->dsn, $this->username, $this->password);
$db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token VARCHAR(255) PRIMARY KEY, data LONGTEXT, ip VARCHAR(64), url VARCHAR(255), time INTEGER UNSIGNED, parent VARCHAR(255), created_at INTEGER UNSIGNED, KEY (created_at), KEY (ip), KEY (url), KEY (parent))');
$db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token VARCHAR(255) PRIMARY KEY, data LONGTEXT, ip VARCHAR(64), method VARCHAR(6), url VARCHAR(255), time INTEGER UNSIGNED, parent VARCHAR(255), created_at INTEGER UNSIGNED, KEY (created_at), KEY (ip), KEY (method), KEY (url), KEY (parent))');
$this->db = $db;
}
@ -44,7 +44,7 @@ class MysqlProfilerStorage extends PdoProfilerStorage
/**
* {@inheritdoc}
*/
protected function buildCriteria($ip, $url, $limit)
protected function buildCriteria($ip, $url, $limit, $method)
{
$criteria = array();
$args = array();
@ -59,6 +59,11 @@ class MysqlProfilerStorage extends PdoProfilerStorage
$args[':url'] = '%'.addcslashes($url, '%_\\').'%';
}
if ($method) {
$criteria[] = 'method = :method';
$args[':method'] = $method;
}
return array($criteria, $args);
}
}

View File

@ -45,14 +45,14 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
/**
* {@inheritdoc}
*/
public function find($ip, $url, $limit)
public function find($ip, $url, $limit, $method)
{
list($criteria, $args) = $this->buildCriteria($ip, $url, $limit);
list($criteria, $args) = $this->buildCriteria($ip, $url, $limit, $method);
$criteria = $criteria ? 'WHERE '.implode(' AND ', $criteria) : '';
$db = $this->initDb();
$tokens = $this->fetch($db, 'SELECT token, ip, url, time, parent FROM sf_profiler_data '.$criteria.' ORDER BY time DESC LIMIT '.((integer) $limit), $args);
$tokens = $this->fetch($db, 'SELECT token, ip, method, url, time, parent FROM sf_profiler_data '.$criteria.' ORDER BY time DESC LIMIT '.((integer) $limit), $args);
$this->close($db);
return $tokens;
@ -65,7 +65,7 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
{
$db = $this->initDb();
$args = array(':token' => $token);
$data = $this->fetch($db, 'SELECT data, parent, ip, url, time FROM sf_profiler_data WHERE token = :token LIMIT 1', $args);
$data = $this->fetch($db, 'SELECT data, parent, ip, method, url, time FROM sf_profiler_data WHERE token = :token LIMIT 1', $args);
$this->close($db);
if (isset($data[0]['data'])) {
return $this->createProfileFromData($token, $data[0]);
@ -85,6 +85,7 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
':parent' => $profile->getParent() ? $profile->getParent()->getToken() : '',
':data' => base64_encode(serialize($profile->getCollectors())),
':ip' => $profile->getIp(),
':method' => $profile->getMethod(),
':url' => $profile->getUrl(),
':time' => $profile->getTime(),
':created_at' => time(),
@ -92,7 +93,7 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
if ($this->read($profile->getToken())) {
try {
$this->exec($db, 'UPDATE sf_profiler_data SET parent = :parent, data = :data, ip = :ip, url = :url, time = :time, created_at = :created_at WHERE token = :token', $args);
$this->exec($db, 'UPDATE sf_profiler_data SET parent = :parent, data = :data, ip = :ip, method = :method, url = :url, time = :time, created_at = :created_at WHERE token = :token', $args);
$this->cleanup();
$status = true;
} catch (\Exception $e) {
@ -100,7 +101,7 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
}
} else {
try {
$this->exec($db, 'INSERT INTO sf_profiler_data (token, parent, data, ip, url, time, created_at) VALUES (:token, :parent, :data, :ip, :url, :time, :created_at)', $args);
$this->exec($db, 'INSERT INTO sf_profiler_data (token, parent, data, ip, method, url, time, created_at) VALUES (:token, :parent, :data, :ip, :method, :url, :time, :created_at)', $args);
$this->cleanup();
$status = true;
} catch (\Exception $e) {
@ -129,10 +130,11 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
* @param string $ip The IP
* @param string $url The URL
* @param string $limit The maximum number of tokens to return
* @param string $method The request method
*
* @return array An array with (criteria, args)
*/
abstract protected function buildCriteria($ip, $url, $limit);
abstract protected function buildCriteria($ip, $url, $limit, $method);
/**
* Initializes the database
@ -197,11 +199,12 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
{
$profile = new Profile($token);
$profile->setIp($data['ip']);
$profile->setMethod($data['method']);
$profile->setUrl($data['url']);
$profile->setTime($data['time']);
$profile->setCollectors(unserialize(base64_decode($data['data'])));
if (!$parent && isset($data['parent']) && $data['parent']) {
if (!$parent && !empty($data['parent'])) {
$parent = $this->read($data['parent']);
}
@ -218,13 +221,14 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface
* Reads the child profiles for the given token.
*
* @param string $token The parent token
* @param string $parent The parent instance
*
* @return array An array of Profile instance
*/
protected function readChildren($token, $parent)
{
$db = $this->initDb();
$data = $this->fetch($db, 'SELECT token, data, ip, url, time FROM sf_profiler_data WHERE parent = :token', array(':token' => $token));
$data = $this->fetch($db, 'SELECT token, data, ip, method, url, time FROM sf_profiler_data WHERE parent = :token', array(':token' => $token));
$this->close($db);
if (!$data) {

View File

@ -23,11 +23,17 @@ class Profile implements \Serializable
private $token;
private $collectors;
private $ip;
private $method;
private $url;
private $time;
private $parent;
private $children;
/**
* Constructor.
*
* @param string $token The token
*/
public function __construct($token)
{
$this->token = $token;
@ -90,6 +96,21 @@ class Profile implements \Serializable
$this->ip = $ip;
}
/**
* Returns the request method.
*
* @return string The request method
*/
public function getMethod()
{
return $this->method;
}
public function setMethod($method)
{
$this->method = $method;
}
/**
* Returns the URL.
*
@ -138,6 +159,11 @@ class Profile implements \Serializable
}
}
/**
* Adds the child token
*
* @param Profile $child The child Profile
*/
public function addChild(Profile $child)
{
$this->children[] = $child;
@ -178,11 +204,11 @@ class Profile implements \Serializable
public function serialize()
{
return serialize(array($this->token, $this->parent, $this->children, $this->collectors, $this->ip, $this->url, $this->time));
return serialize(array($this->token, $this->parent, $this->children, $this->collectors, $this->ip, $this->method, $this->url, $this->time));
}
public function unserialize($data)
{
list($this->token, $this->parent, $this->children, $this->collectors, $this->ip, $this->url, $this->time) = unserialize($data);
list($this->token, $this->parent, $this->children, $this->collectors, $this->ip, $this->method, $this->url, $this->time) = unserialize($data);
}
}

View File

@ -82,7 +82,7 @@ class Profiler
/**
* Saves a Profile.
*
* @param Profile A Profile instance
* @param Profile $profile A Profile instance
*
* @return Boolean
*/
@ -106,6 +106,8 @@ class Profiler
/**
* Exports the current profiler data.
*
* @param Profile $profile A Profile instance
*
* @return string The exported data
*/
public function export(Profile $profile)
@ -136,15 +138,16 @@ class Profiler
/**
* Finds profiler tokens for the given criteria.
*
* @param string $ip The IP
* @param string $url The URL
* @param string $limit The maximum number of tokens to return
* @param string $ip The IP
* @param string $url The URL
* @param string $limit The maximum number of tokens to return
* @param string $method The request method
*
* @return array An array of tokens
*/
public function find($ip, $url, $limit)
public function find($ip, $url, $limit, $method)
{
return $this->storage->find($ip, $url, $limit);
return $this->storage->find($ip, $url, $limit, $method);
}
/**
@ -166,11 +169,11 @@ class Profiler
$profile->setTime(time());
$profile->setUrl($request->getUri());
$profile->setIp($request->server->get('REMOTE_ADDR'));
$profile->setMethod($request->getMethod());
$response->headers->set('X-Debug-Token', $profile->getToken());
$collectors = array();
foreach ($this->collectors as $name => $collector) {
foreach ($this->collectors as $collector) {
$collector->collect($request, $response, $exception);
// forces collectors to become "read/only" (they loose their object dependencies)
@ -217,6 +220,8 @@ class Profiler
* Returns true if a Collector for the given name exists.
*
* @param string $name A collector name
*
* @return Boolean
*/
public function has($name)
{

View File

@ -21,13 +21,14 @@ interface ProfilerStorageInterface
/**
* Finds profiler tokens for the given criteria.
*
* @param string $ip The IP
* @param string $url The URL
* @param string $limit The maximum number of tokens to return
* @param string $ip The IP
* @param string $url The URL
* @param string $limit The maximum number of tokens to return
* @param string $method The request method
*
* @return array An array of tokens
*/
function find($ip, $url, $limit);
function find($ip, $url, $limit, $method);
/**
* Reads data associated with the given token.

View File

@ -41,9 +41,10 @@ class SqliteProfilerStorage extends PdoProfilerStorage
}
$db->exec('PRAGMA temp_store=MEMORY; PRAGMA journal_mode=MEMORY;');
$db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token STRING, data STRING, ip STRING, url STRING, time INTEGER, parent STRING, created_at INTEGER)');
$db->exec('CREATE TABLE IF NOT EXISTS sf_profiler_data (token STRING, data STRING, ip STRING, method STRING, url STRING, time INTEGER, parent STRING, created_at INTEGER)');
$db->exec('CREATE INDEX IF NOT EXISTS data_created_at ON sf_profiler_data (created_at)');
$db->exec('CREATE INDEX IF NOT EXISTS data_ip ON sf_profiler_data (ip)');
$db->exec('CREATE INDEX IF NOT EXISTS data_method ON sf_profiler_data (method)');
$db->exec('CREATE INDEX IF NOT EXISTS data_url ON sf_profiler_data (url)');
$db->exec('CREATE INDEX IF NOT EXISTS data_parent ON sf_profiler_data (parent)');
$db->exec('CREATE UNIQUE INDEX IF NOT EXISTS data_token ON sf_profiler_data (token)');
@ -97,7 +98,7 @@ class SqliteProfilerStorage extends PdoProfilerStorage
/**
* {@inheritdoc}
*/
protected function buildCriteria($ip, $url, $limit)
protected function buildCriteria($ip, $url, $limit, $method)
{
$criteria = array();
$args = array();
@ -112,6 +113,11 @@ class SqliteProfilerStorage extends PdoProfilerStorage
$args[':url'] = '%'.addcslashes($url, '%_\\').'%';
}
if ($method) {
$criteria[] = 'method = :method';
$args[':method'] = $method;
}
return array($criteria, $args);
}

View File

@ -25,8 +25,7 @@ class FileProfilerStorageTest extends \PHPUnit_Framework_TestCase
$iterator = new \RecursiveDirectoryIterator(self::$tmpDir, $flags);
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file)
{
foreach ($iterator as $file) {
if (is_file($file)) {
unlink($file);
}
@ -58,9 +57,10 @@ class FileProfilerStorageTest extends \PHPUnit_Framework_TestCase
$profile = new Profile('token_'.$i);
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar');
$profile->setMethod('GET');
self::$storage->write($profile);
}
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar', 20)), 10, '->write() stores data in the database');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar', 20, 'GET')), 10, '->write() stores data in the database');
}
@ -130,12 +130,13 @@ class FileProfilerStorageTest extends \PHPUnit_Framework_TestCase
{
$profile = new Profile('token');
$profile->setIp('127.0.0.1');
$profile->setMethod('GET');
self::$storage->write($profile);
$this->assertEquals(count(self::$storage->find('127.0.0.1', '', 10)), 1, '->find() retrieve a record by IP');
$this->assertEquals(count(self::$storage->find('127.0.%.1', '', 10)), 0, '->find() does not interpret a "%" as a wildcard in the IP');
$this->assertEquals(count(self::$storage->find('127.0._.1', '', 10)), 0, '->find() does not interpret a "_" as a wildcard in the IP');
$this->assertEquals(count(self::$storage->find('127.0.0.1', '', 10, 'GET')), 1, '->find() retrieve a record by IP');
$this->assertEquals(count(self::$storage->find('127.0.%.1', '', 10, 'GET')), 0, '->find() does not interpret a "%" as a wildcard in the IP');
$this->assertEquals(count(self::$storage->find('127.0._.1', '', 10, 'GET')), 0, '->find() does not interpret a "_" as a wildcard in the IP');
}
public function testRetrieveByUrl()
@ -143,38 +144,44 @@ class FileProfilerStorageTest extends \PHPUnit_Framework_TestCase
$profile = new Profile('simple_quote');
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar/\'');
$profile->setMethod('GET');
self::$storage->write($profile);
$profile = new Profile('double_quote');
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar/"');
$profile->setMethod('GET');
self::$storage->write($profile);
$profile = new Profile('backslash');
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo\\bar/');
$profile->setMethod('GET');
self::$storage->write($profile);
$profile = new Profile('percent');
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar/%');
$profile->setMethod('GET');
self::$storage->write($profile);
$profile = new Profile('underscore');
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar/_');
$profile->setMethod('GET');
self::$storage->write($profile);
$profile = new Profile('semicolon');
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar/;');
$profile->setMethod('GET');
self::$storage->write($profile);
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/\'', 10)), 1, '->find() accepts single quotes in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/"', 10)), 1, '->find() accepts double quotes in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo\\bar/', 10)), 1, '->find() accepts backslash in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/;', 10)), 1, '->find() accepts semicolon in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/%', 10)), 1, '->find() does not interpret a "%" as a wildcard in the URL');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/_', 10)), 1, '->find() does not interpret a "_" as a wildcard in the URL');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/\'', 10, 'GET')), 1, '->find() accepts single quotes in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/"', 10, 'GET')), 1, '->find() accepts double quotes in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo\\bar/', 10, 'GET')), 1, '->find() accepts backslash in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/;', 10, 'GET')), 1, '->find() accepts semicolon in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/%', 10, 'GET')), 1, '->find() does not interpret a "%" as a wildcard in the URL');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/_', 10, 'GET')), 1, '->find() does not interpret a "_" as a wildcard in the URL');
}
}

View File

@ -47,9 +47,10 @@ class SqliteProfilerStorageTest extends \PHPUnit_Framework_TestCase
$profile = new Profile('token_'.$i);
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar');
$profile->setMethod('GET');
self::$storage->write($profile);
}
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar', 20)), 10, '->write() stores data in the database');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar', 20, 'GET')), 10, '->write() stores data in the database');
}
public function testStoreSpecialCharsInUrl()
@ -89,12 +90,13 @@ class SqliteProfilerStorageTest extends \PHPUnit_Framework_TestCase
{
$profile = new Profile('token');
$profile->setIp('127.0.0.1');
$profile->setMethod('GET');
self::$storage->write($profile);
$this->assertEquals(count(self::$storage->find('127.0.0.1', '', 10)), 1, '->find() retrieve a record by IP');
$this->assertEquals(count(self::$storage->find('127.0.%.1', '', 10)), 0, '->find() does not interpret a "%" as a wildcard in the IP');
$this->assertEquals(count(self::$storage->find('127.0._.1', '', 10)), 0, '->find() does not interpret a "_" as a wildcard in the IP');
$this->assertEquals(count(self::$storage->find('127.0.0.1', '', 10, 'GET')), 1, '->find() retrieve a record by IP');
$this->assertEquals(count(self::$storage->find('127.0.%.1', '', 10, 'GET')), 0, '->find() does not interpret a "%" as a wildcard in the IP');
$this->assertEquals(count(self::$storage->find('127.0._.1', '', 10, 'GET')), 0, '->find() does not interpret a "_" as a wildcard in the IP');
}
public function testRetrieveByUrl()
@ -102,32 +104,37 @@ class SqliteProfilerStorageTest extends \PHPUnit_Framework_TestCase
$profile = new Profile('simple_quote');
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar/\'');
$profile->setMethod('GET');
self::$storage->write($profile);
$profile = new Profile('double_quote');
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar/"');
$profile->setMethod('GET');
self::$storage->write($profile);
$profile = new Profile('backslash');
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo\\bar/');
$profile->setMethod('GET');
self::$storage->write($profile);
$profile = new Profile('percent');
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar/%');
$profile->setMethod('GET');
self::$storage->write($profile);
$profile = new Profile('underscore');
$profile->setIp('127.0.0.1');
$profile->setUrl('http://foo.bar/_');
$profile->setMethod('GET');
self::$storage->write($profile);
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/\'', 10)), 1, '->find() accepts single quotes in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/"', 10)), 1, '->find() accepts double quotes in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo\\bar/', 10)), 1, '->find() accepts backslash in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/%', 10)), 1, '->find() does not interpret a "%" as a wildcard in the URL');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/_', 10)), 1, '->find() does not interpret a "_" as a wildcard in the URL');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/\'', 10, 'GET')), 1, '->find() accepts single quotes in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/"', 10, 'GET')), 1, '->find() accepts double quotes in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo\\bar/', 10, 'GET')), 1, '->find() accepts backslash in URLs');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/%', 10, 'GET')), 1, '->find() does not interpret a "%" as a wildcard in the URL');
$this->assertEquals(count(self::$storage->find('127.0.0.1', 'http://foo.bar/_', 10, 'GET')), 1, '->find() does not interpret a "_" as a wildcard in the URL');
}
}