From 19843541e77d538f1f05d858f026599b76b5ee97 Mon Sep 17 00:00:00 2001 From: Mantas Date: Wed, 29 Jun 2016 10:09:17 +0300 Subject: [PATCH 1/2] added a Caser:snake to the getDocumentType() method --- Mapping/DocumentParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mapping/DocumentParser.php b/Mapping/DocumentParser.php index 761e7e16..782409b6 100644 --- a/Mapping/DocumentParser.php +++ b/Mapping/DocumentParser.php @@ -375,7 +375,7 @@ private function getDocumentType($document) $reflectionClass = new \ReflectionClass($namespace); $document = $this->getDocumentAnnotationData($reflectionClass); - return empty($document->type) ? $reflectionClass->getShortName() : $document->type; + return empty($document->type) ? Caser::snake($reflectionClass->getShortName()) : $document->type; } /** From f9ac941e135c35277cd0aa716f4a27c6d124dfc2 Mon Sep 17 00:00:00 2001 From: Mantas Date: Wed, 29 Jun 2016 10:24:40 +0300 Subject: [PATCH 2/2] fixed an issue with bad serialization --- Profiler/ElasticsearchProfiler.php | 2 +- .../Profiler/ElasticsearchProfilerTest.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Profiler/ElasticsearchProfiler.php b/Profiler/ElasticsearchProfiler.php index eaa596e0..85bde2fb 100644 --- a/Profiler/ElasticsearchProfiler.php +++ b/Profiler/ElasticsearchProfiler.php @@ -173,7 +173,7 @@ private function handleRecords($route, $records) private function addQuery($route, $record, $queryBody) { parse_str(parse_url($record['context']['uri'], PHP_URL_QUERY), $httpParameters); - $body = json_decode(trim($queryBody, " '\r\t\n"), true); + $body = json_decode(trim($queryBody, " '\r\t\n")); $this->queries[$route][] = array_merge( [ 'body' => $body !== null ? json_encode($body, JSON_PRETTY_PRINT) : '', diff --git a/Tests/Functional/Profiler/ElasticsearchProfilerTest.php b/Tests/Functional/Profiler/ElasticsearchProfilerTest.php index 7869ecb6..086477b7 100644 --- a/Tests/Functional/Profiler/ElasticsearchProfilerTest.php +++ b/Tests/Functional/Profiler/ElasticsearchProfilerTest.php @@ -13,6 +13,8 @@ use ONGR\ElasticsearchBundle\Profiler\ElasticsearchProfiler; use ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\BarBundle\Document\Product; +use ONGR\ElasticsearchDSL\Aggregation\GlobalAggregation; +use ONGR\ElasticsearchDSL\Query\MatchAllQuery; use ONGR\ElasticsearchDSL\Query\TermQuery; use ONGR\ElasticsearchBundle\Service\Repository; use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase; @@ -161,4 +163,22 @@ private function getCollector() return $collector; } + + public function testMatchAllQuery() + { + $manager = $this->getManager(); + + $repository = $manager->getRepository('AcmeBarBundle:Product'); + $search = $repository + ->createSearch() + ->addAggregation(new GlobalAggregation('g')); + $repository->execute($search); + + $queries = $this->getCollector()->getQueries(); + $lastQuery = end($queries[ElasticsearchProfiler::UNDEFINED_ROUTE]); + $this->checkQueryParameters($lastQuery); + $lastQuery['body'] = trim(preg_replace('/\s+/', '', $lastQuery['body'])); + + $this->assertEquals('{"aggregations":{"g":{"global":{}}}}', $lastQuery['body']); + } }