From 71ded9e7bcb095f302e1c8d20b1d02059647fe31 Mon Sep 17 00:00:00 2001
From: Mantas Marcinkevicius <m@243.k4.nfq.lt>
Date: Tue, 19 Jul 2016 15:06:57 +0300
Subject: [PATCH] added a test for the inner hits endpoint

---
 .../SearchEndpoint/InnerHitsEndpointTest.php  | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 tests/SearchEndpoint/InnerHitsEndpointTest.php

diff --git a/tests/SearchEndpoint/InnerHitsEndpointTest.php b/tests/SearchEndpoint/InnerHitsEndpointTest.php
new file mode 100644
index 0000000..268bfcc
--- /dev/null
+++ b/tests/SearchEndpoint/InnerHitsEndpointTest.php
@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This file is part of the ONGR package.
+ *
+ * (c) NFQ Technologies UAB <info@nfq.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint;
+
+use ONGR\ElasticsearchDSL\SearchEndpoint\InnerHitsEndpoint;
+
+/**
+ * Class AggregationsEndpointTest.
+ */
+class InnerHitsEndpointTest extends \PHPUnit_Framework_TestCase
+{
+    /**
+     * Tests constructor.
+     */
+    public function testItCanBeInstantiated()
+    {
+        $this->assertInstanceOf(
+            'ONGR\ElasticsearchDSL\SearchEndpoint\InnerHitsEndpoint',
+            new InnerHitsEndpoint()
+        );
+    }
+
+    /**
+     * Tests if endpoint returns builders.
+     */
+    public function testEndpointGetter()
+    {
+        $hitName = 'foo';
+        $innerHit = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock();
+        $endpoint = new InnerHitsEndpoint();
+        $endpoint->add($innerHit, $hitName);
+        $builders = $endpoint->getAll();
+
+        $this->assertCount(1, $builders);
+        $this->assertSame($innerHit, $builders[$hitName]);
+    }
+
+    /**
+     * Tests normalize method
+     */
+    public function testNormalization()
+    {
+        $normalizer = $this
+            ->getMockBuilder('Symfony\Component\Serializer\Normalizer\NormalizerInterface')
+            ->getMock();
+        $innerHit = $this
+            ->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')
+            ->setMethods(['getName', 'toArray', 'getType'])
+            ->getMock();
+        $innerHit->expects($this->any())->method('getName')->willReturn('foo');
+        $innerHit->expects($this->any())->method('toArray')->willReturn(['foo' => 'bar']);
+
+        $endpoint = new InnerHitsEndpoint();
+        $endpoint->add($innerHit, 'foo');
+        $expected = [
+            'foo' => [
+                'foo' => 'bar'
+            ]
+        ];
+
+        $this->assertEquals(
+            $expected,
+            $endpoint->normalize($normalizer)
+        );
+    }
+}
-- 
GitLab