added query string to collector and updated tests
This commit is contained in:
parent
d04a403f71
commit
5be3a8c22e
|
@ -27,7 +27,7 @@ class Client extends ElasticaClient
|
|||
'transport' => $connection->getTransport(),
|
||||
);
|
||||
|
||||
$this->_logger->logQuery($path, $method, $data, $time, $connection_array);
|
||||
$this->_logger->logQuery($path, $method, $data, $time, $connection_array, $query);
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
|
|
@ -37,10 +37,11 @@ class ElasticaLogger implements LoggerInterface
|
|||
* @param string $path Path to call
|
||||
* @param string $method Rest method to use (GET, POST, DELETE, PUT)
|
||||
* @param array $data arguments
|
||||
* @param array $query arguments
|
||||
* @param float $time execution time
|
||||
* @param array $connection host, port and transport of the query
|
||||
*/
|
||||
public function logQuery($path, $method, $data, $time, $connection = array())
|
||||
public function logQuery($path, $method, $data, $time, $connection = array(), $query = array())
|
||||
{
|
||||
if ($this->debug) {
|
||||
$this->queries[] = array(
|
||||
|
@ -48,7 +49,8 @@ class ElasticaLogger implements LoggerInterface
|
|||
'method' => $method,
|
||||
'data' => $data,
|
||||
'executionMS' => $time,
|
||||
'connection' => $connection
|
||||
'connection' => $connection,
|
||||
'queryString' => $query,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
{% for key, query in collector.queries %}
|
||||
<li class="{{ cycle(['odd', 'even'], loop.index) }}">
|
||||
<strong>Path</strong>: {{ query.path }}<br />
|
||||
<strong>Query</strong>: {{ query.queryString|url_encode }}<br />
|
||||
<strong>Method</strong>: {{ query.method }} <small>({{ query.connection.transport }} on {{ query.connection.host }}:{{ query.connection.port }})</small>
|
||||
<div>
|
||||
<code>{{ query.data|json_encode }}</code>
|
||||
|
@ -60,7 +61,7 @@
|
|||
</a>
|
||||
|
||||
<div style="display: none;" id="elastica_curl_query_{{ key }}">
|
||||
<code>curl -X{{ query.method }} '{{ query.connection.transport|lower }}://{{ query.connection.host }}:{{ query.connection.port }}/{{ query.path }}' -d '{{ query.data|json_encode }}'</code>
|
||||
<code>curl -X{{ query.method }} '{{ query.connection.transport|lower }}://{{ query.connection.host }}:{{ query.connection.port }}/{{ query.path }}{% if query.queryString|length %}?{{ query.queryString|url_encode }}{% endif %}' -d '{{ query.data|json_encode }}'</code>
|
||||
</div>
|
||||
{% endif %}
|
||||
</li>
|
||||
|
|
|
@ -24,6 +24,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|||
Request::GET,
|
||||
$this->isType('array'),
|
||||
$this->isType('float'),
|
||||
$this->isType('array'),
|
||||
$this->isType('array')
|
||||
);
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase
|
|||
$data = array('data');
|
||||
$time = 12;
|
||||
$connection = array('host' => 'localhost', 'port' => '8999', 'transport' => 'https');
|
||||
$query = array('search_type' => 'dfs_query_then_fetch');
|
||||
|
||||
$expected = array(
|
||||
'path' => $path,
|
||||
|
@ -77,9 +78,10 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase
|
|||
'data' => $data,
|
||||
'executionMS' => $time,
|
||||
'connection' => $connection,
|
||||
'queryString' => $query,
|
||||
);
|
||||
|
||||
$elasticaLogger->logQuery($path, $method, $data, $time, $connection);
|
||||
$elasticaLogger->logQuery($path, $method, $data, $time, $connection, $query);
|
||||
$returnedQueries = $elasticaLogger->getQueries();
|
||||
$this->assertEquals($expected, $returnedQueries[0]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue