summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/ResponseTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/ResponseTest.php')
-rw-r--r--vendor/ruflin/elastica/test/lib/Elastica/Test/ResponseTest.php141
1 files changed, 126 insertions, 15 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/ResponseTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/ResponseTest.php
index 1e026eae..e7b83ade 100644
--- a/vendor/ruflin/elastica/test/lib/Elastica/Test/ResponseTest.php
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/ResponseTest.php
@@ -1,16 +1,20 @@
<?php
-
namespace Elastica\Test;
+
use Elastica\Document;
use Elastica\Facet\DateHistogram;
use Elastica\Query;
use Elastica\Query\MatchAll;
use Elastica\Request;
-use Elastica\Type\Mapping;
+use Elastica\Response;
use Elastica\Test\Base as BaseTest;
+use Elastica\Type\Mapping;
class ResponseTest extends BaseTest
{
+ /**
+ * @group unit
+ */
public function testClassHierarchy()
{
$facet = new DateHistogram('dateHist1');
@@ -19,25 +23,26 @@ class ResponseTest extends BaseTest
unset($facet);
}
+ /**
+ * @group functional
+ */
public function testResponse()
{
$index = $this->_createIndex();
$type = $index->getType('helloworld');
$mapping = new Mapping($type, array(
- 'name' => array('type' => 'string', 'store' => 'no'),
- 'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss')
- ));
+ 'name' => array('type' => 'string', 'store' => 'no'),
+ 'dtmPosted' => array('type' => 'date', 'store' => 'no', 'format' => 'yyyy-MM-dd HH:mm:ss'),
+ ));
$type->setMapping($mapping);
- $doc = new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => "2011-06-23 21:53:00"));
- $type->addDocument($doc);
- $doc = new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => "2011-06-23 09:53:00"));
- $type->addDocument($doc);
- $doc = new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => "2011-07-08 08:53:00"));
- $type->addDocument($doc);
- $doc = new Document(4, array('name' => 'elastica search', 'dtmPosted' => "2011-07-08 01:53:00"));
- $type->addDocument($doc);
+ $type->addDocuments(array(
+ new Document(1, array('name' => 'nicolas ruflin', 'dtmPosted' => '2011-06-23 21:53:00')),
+ new Document(2, array('name' => 'raul martinez jr', 'dtmPosted' => '2011-06-23 09:53:00')),
+ new Document(3, array('name' => 'rachelle clemente', 'dtmPosted' => '2011-07-08 08:53:00')),
+ new Document(4, array('name' => 'elastica search', 'dtmPosted' => '2011-07-08 01:53:00')),
+ ));
$query = new Query();
$query->setQuery(new MatchAll());
@@ -54,6 +59,9 @@ class ResponseTest extends BaseTest
$this->assertArrayHasKey('successful', $shardsStats);
}
+ /**
+ * @group functional
+ */
public function testIsOk()
{
$index = $this->_createIndex();
@@ -65,6 +73,9 @@ class ResponseTest extends BaseTest
$this->assertTrue($response->isOk());
}
+ /**
+ * @group functional
+ */
public function testIsOkMultiple()
{
$index = $this->_createIndex();
@@ -72,13 +83,114 @@ class ResponseTest extends BaseTest
$docs = array(
new Document(1, array('name' => 'ruflin')),
- new Document(2, array('name' => 'ruflin'))
+ new Document(2, array('name' => 'ruflin')),
);
$response = $type->addDocuments($docs);
$this->assertTrue($response->isOk());
}
+ /**
+ * @group unit
+ */
+ public function testIsOkBulkWithErrorsField()
+ {
+ $response = new Response(json_encode(array(
+ 'took' => 213,
+ 'errors' => false,
+ 'items' => array(
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707891', '_version' => 4, 'status' => 200)),
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707893', '_version' => 4, 'status' => 200)),
+ ),
+ )));
+
+ $this->assertTrue($response->isOk());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testIsNotOkBulkWithErrorsField()
+ {
+ $response = new Response(json_encode(array(
+ 'took' => 213,
+ 'errors' => true,
+ 'items' => array(
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707891', '_version' => 4, 'status' => 200)),
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707893', '_version' => 4, 'status' => 200)),
+ ),
+ )));
+
+ $this->assertFalse($response->isOk());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testIsOkBulkItemsWithOkField()
+ {
+ $response = new Response(json_encode(array(
+ 'took' => 213,
+ 'items' => array(
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707891', '_version' => 4, 'ok' => true)),
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707893', '_version' => 4, 'ok' => true)),
+ ),
+ )));
+
+ $this->assertTrue($response->isOk());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testIsNotOkBulkItemsWithOkField()
+ {
+ $response = new Response(json_encode(array(
+ 'took' => 213,
+ 'items' => array(
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707891', '_version' => 4, 'ok' => true)),
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707893', '_version' => 4, 'ok' => false)),
+ ),
+ )));
+
+ $this->assertFalse($response->isOk());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testIsOkBulkItemsWithStatusField()
+ {
+ $response = new Response(json_encode(array(
+ 'took' => 213,
+ 'items' => array(
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707891', '_version' => 4, 'status' => 200)),
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707893', '_version' => 4, 'status' => 200)),
+ ),
+ )));
+
+ $this->assertTrue($response->isOk());
+ }
+
+ /**
+ * @group unit
+ */
+ public function testIsNotOkBulkItemsWithStatusField()
+ {
+ $response = new Response(json_encode(array(
+ 'took' => 213,
+ 'items' => array(
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707891', '_version' => 4, 'status' => 200)),
+ array('index' => array('_index' => 'rohlik', '_type' => 'grocery', '_id' => '707893', '_version' => 4, 'status' => 301)),
+ ),
+ )));
+
+ $this->assertFalse($response->isOk());
+ }
+
+ /**
+ * @group functional
+ */
public function testGetDataEmpty()
{
$index = $this->_createIndex();
@@ -90,5 +202,4 @@ class ResponseTest extends BaseTest
$this->assertEquals(0, count($response));
}
-
}