[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pecl-cvs
Subject:    [PECL-CVS] com =?UTF-8?Q?pecl/search=5Fengine/solr=3A=20Request=20=23=37=30=39=37=34?= =?UTF-8?Q?=3A
From:       Omar Shaban <omars () php ! net>
Date:       2015-11-28 18:33:18
Message-ID: php-mail-951a6b6c0f465872d7673f85dba6ef52712818788 () git ! php ! net
[Download RAW message or body]

Commit:    b2ba26c03ffaa99a78552a60478548e1f46533ad
Author:    Omar Shaban <omars@php.net>         Sat, 28 Nov 2015 20:33:18 +0200
Parents:   f53ed0b60b0943a73fd77177c8fb77cbc85f01a4
Branches:  master

Link:       http://git.php.net/?p=pecl/search_engine/solr.git;a=commitdiff;h=b2ba26c03ffaa99a78552a60478548e1f46533ad


Log:
Request #70974: Update document block test

Bugs:
https://bugs.php.net/70974

Changed paths:
  A  tests/034.solr_update_document_block.phpt


Diff:
diff --git a/tests/034.solr_update_document_block.phpt \
b/tests/034.solr_update_document_block.phpt new file mode 100644
index 0000000..0caa934
--- /dev/null
+++ b/tests/034.solr_update_document_block.phpt
@@ -0,0 +1,82 @@
+--TEST--
+SolrResponse - Fetch and Update nested documents
+--SKIPIF--
+<?php
+include 'skip.if.server_not_configured.inc';
+?>
+--FILE--
+<?php
+
+require_once "bootstrap.inc";
+
+$updateInventory = function ($document, $inventory) {
+	$children = $document->getChildDocuments();
+	$child = $children[0];
+	$child->deleteField('inventory_i');
+	$child->addField('inventory_i', $inventory);
+
+	$document->deleteField('_version_');
+};
+
+$getInventory = function ($response) {
+	return (int) current($response->response->docs[0]->getChildDocuments()[0]['inventory_i']->values);
 +};
+
+$options = array (
+		'hostname' => SOLR_SERVER_HOSTNAME,
+		'login' => SOLR_SERVER_USERNAME,
+		'password' => SOLR_SERVER_PASSWORD,
+		'port' => SOLR_SERVER_PORT,
+		'path' => SOLR_SERVER_STORE_PATH,
+		'wt' => 'xml' 
+);
+
+$client = new SolrClient ( $options );
+
+$query = new SolrQuery ('id:1 AND {!parent which=$parentFilter}');
+
+$query->setParam ( 'parentFilter', 'content_type_s:product' );
+$query->addFilterQuery('{!parent which=$parentFilter}');
+
+$query->addField ( '*' );
+$query->addField ( '[child parentFilter=$parentFilter]' );
+
+$query->setStart ( 0 );
+$query->setRows ( 1 );
+
+// query existing inventory
+$queryResponse = $client->query ( $query );
+$queryResponse->setParseMode(SolrResponse::PARSE_SOLR_DOC);
+$response = $queryResponse->getResponse();
+$existingInventory = $getInventory($response);
+
+// update inventory to 300
+$document = $response->response->docs[0]->getInputDocument();
+$updateInventory($document, 300);
+$client->addDocument($document);
+$client->commit();
+
+// fetch the document again after the update
+$queryResponse = $client->query ( $query );
+$queryResponse->setParseMode(SolrResponse::PARSE_SOLR_DOC);
+$response = $queryResponse->getResponse();
+$newInventory = $getInventory($response);
+assert($newInventory == 300);
+
+
+echo "------EXISTING------" . PHP_EOL;
+var_dump($existingInventory);
+echo "----AFTER UPDATE----" . PHP_EOL;
+var_dump($newInventory);
+
+// cleanup: restore document's original state
+$document = $response->response->docs[0]->getInputDocument();
+$updateInventory($document, $existingInventory);
+$client->addDocument($document);
+$client->commit();
+?>
+--EXPECT--
+------EXISTING------
+int(200)
+----AFTER UPDATE----
+int(300)
\ No newline at end of file


--
PECL CVS Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic