I am unit-testing a repository that uses FOS Elastica and I was wondering if anyone knows how to get the string version of a query, rather than in array form. Here is my repository method:
/**
* Creates query object by either first or last name, with given parameters
*
* @param $name
*
* @param array $params
*
* @return Query
*/
public function findByFirstOrLast($name, array $params)
{
$queryString = new QueryString();
$queryString->setQuery($name);
$queryString->setFields(array('firstName', 'lastName'));
$query = new Query();
$query->setQuery($queryString);
$query->setSort(array($params['sort'] => array('order' => $params['direction'])));
return $query;
}
Assuming $name = 'foo';
(and that I am sorting on id), I believe the corresponding FOS Elastica query should be
{
"query":
{
"query_string":
{
"query":
"foo",
"fields":["firstName","lastName"]
}
},
"sort":
{
"id":
{
"order":"asc"
}
}
}
Does anyone know how to get this json-string representation of the query? It doesn't necessarily have to be in this pretty format either, it can be a one-line string.