Commit 0766401c authored by Bas de Nooijer's avatar Bas de Nooijer

Merge branch 'release/3.1.2'

parents 224cb529 c3791415
......@@ -13,9 +13,9 @@
],
"require": {
"php": ">=5.3.2",
"symfony/event-dispatcher": ">=2.1.0,<2.3-dev"
"symfony/event-dispatcher": "~2.1"
},
"autoload": {
"psr-0": { "Solarium": "library/" }
"psr-0": { "Solarium\\": "library/" }
}
}
......@@ -70,7 +70,7 @@ class Client extends CoreClient
*
* @var string
*/
const VERSION = '3.0.0';
const VERSION = '3.2.0';
/**
* Check for an exact version
......
......@@ -194,7 +194,7 @@ class ZendHttp extends Configurable implements AdapterInterface
break;
}
$client->setUri($endpoint->getBaseUri() . $request->getUri());
$client->setUri($endpoint->getBaseUri() . $request->getHandler());
$client->setHeaders($request->getHeaders());
$this->timeout = $endpoint->getTimeout();
......
......@@ -81,6 +81,13 @@ class BufferedAdd extends Plugin
*/
protected $buffer = array();
/**
* End point to execute updates against.
*
* @var string
*/
protected $endpoint;
/**
* Plugin init function
*
......@@ -94,6 +101,29 @@ class BufferedAdd extends Plugin
$this->updateQuery = $this->client->createUpdate();
}
/**
* Set the endpoint for the documents
*
* @param string $endpoint The endpoint to set
*
* @return self
*/
public function setEndpoint($endpoint)
{
$this->endpoint = $endpoint;
return $this;
}
/**
* Return the endpoint
*
* @return string
*/
public function getEndPoint()
{
return $this->endpoint;
}
/**
* Set buffer size option
*
......@@ -208,7 +238,7 @@ class BufferedAdd extends Plugin
$this->client->getEventDispatcher()->dispatch(Events::PRE_FLUSH, $event);
$this->updateQuery->addDocuments($event->getBuffer(), $event->getOverwrite(), $event->getCommitWithin());
$result = $this->client->update($this->updateQuery);
$result = $this->client->update($this->updateQuery, $this->getEndpoint());
$this->clear();
$event = new PostFlushEvent($result);
......@@ -235,7 +265,7 @@ class BufferedAdd extends Plugin
$this->updateQuery->addDocuments($this->buffer, $event->getOverwrite());
$this->updateQuery->addCommit($event->getSoftCommit(), $event->getWaitSearcher(), $event->getExpungeDeletes());
$result = $this->client->update($this->updateQuery);
$result = $this->client->update($this->updateQuery, $this->getEndpoint());
$this->clear();
$event = new PostCommitEvent($result);
......
......@@ -101,6 +101,7 @@ class RequestBuilder extends BaseRequestBuilder
// add file to request
$request->setFileUpload($query->getFile());
$request->addParam('resource.name', basename($query->getFile()));
$request->addHeader('Content-Type: multipart/form-data');
return $request;
}
......
......@@ -43,7 +43,7 @@ use Solarium\QueryType\Select\RequestBuilder\RequestBuilder;
use Solarium\QueryType\Select\ResponseParser\ResponseParser;
use Solarium\Exception\InvalidArgumentException;
use Solarium\Exception\OutOfBoundsException;
use Solarium\QueryType\Select\Query\Component\Component;
use Solarium\QueryType\Select\Query\Component\Component as AbstractComponent;
/**
* Select Query
......@@ -787,7 +787,7 @@ class Query extends BaseQuery
/**
* Get all registered components
*
* @return Component[]
* @return AbstractComponent[]
*/
public function getComponents()
{
......@@ -835,7 +835,7 @@ class Query extends BaseQuery
* This overwrites any existing component registered with the same key.
*
* @param string $key
* @param Component $component
* @param AbstractComponent $component
* @return self Provides fluent interface
*/
public function setComponent($key, $component)
......@@ -851,7 +851,7 @@ class Query extends BaseQuery
*
* You can remove a component by passing its key or the component instance.
*
* @param string|Component\Component $component
* @param string|AbstractComponent $component
* @return self Provides fluent interface
*/
public function removeComponent($component)
......
......@@ -49,6 +49,7 @@ use Solarium\QueryType\Update\Query\Command\Commit as CommitCommand;
use Solarium\QueryType\Update\Query\Command\Delete as DeleteCommand;
use Solarium\QueryType\Update\Query\Command\Optimize as OptimizeCommand;
use Solarium\QueryType\Update\Query\Command\Rollback as RollbackCommand;
use Solarium\QueryType\Update\Query\Document\DocumentInterface;
/**
* Update query
......@@ -485,13 +486,13 @@ class Query extends BaseQuery
*
* @param array $fields
* @param array $boosts
* @return Document
* @param array $modifiers
* @return DocumentInterface
*/
public function createDocument($fields = array(), $boosts = array())
public function createDocument($fields = array(), $boosts = array(), $modifiers = array())
{
$class = $this->getDocumentClass();
return new $class($fields, $boosts);
return new $class($fields, $boosts, $modifiers);
}
}
......@@ -87,7 +87,57 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
$this->assertThat($zendHttp, $this->isInstanceOf('Zend_Http_Client'));
}
public function testExecute()
public function testExecuteGet()
{
$method = Request::METHOD_GET;
$rawData = 'xyz';
$responseData = 'abc';
$handler = 'myhandler';
$headers = array(
'X-test: 123'
);
$params = array('a' => 1, 'b' => 2);
$request = new Request();
$request->setMethod($method);
$request->setHandler($handler);
$request->setHeaders($headers);
$request->setRawData($rawData);
$request->setParams($params);
$endpoint = new Endpoint();
$response = new \Zend_Http_Response(200, array('status' => 'HTTP 1.1 200 OK'), $responseData);
$mock = $this->getMock('Zend_Http_Client');
$mock->expects($this->once())
->method('setMethod')
->with($this->equalTo($method));
$mock->expects($this->once())
->method('setUri')
->with($this->equalTo('http://127.0.0.1:8983/solr/myhandler'));
$mock->expects($this->once())
->method('setHeaders')
->with($this->equalTo(array(
'X-test: 123',
)));
$mock->expects($this->once())
->method('setParameterGet')
->with($this->equalTo($params));
$mock->expects($this->once())
->method('request')
->will($this->returnValue($response));
$this->adapter->setZendHttp($mock);
$adapterResponse = $this->adapter->execute($request, $endpoint);
$this->assertEquals(
$responseData,
$adapterResponse->getBody()
);
}
public function testExecutePost()
{
$method = Request::METHOD_POST;
$rawData = 'xyz';
......@@ -96,12 +146,14 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
$headers = array(
'X-test: 123'
);
$params = array('a' => 1, 'b' => 2);
$request = new Request();
$request->setMethod($method);
$request->setHandler($handler);
$request->setHeaders($headers);
$request->setRawData($rawData);
$request->setParams($params);
$endpoint = new Endpoint();
......@@ -113,7 +165,7 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo($method));
$mock->expects($this->once())
->method('setUri')
->with($this->equalTo('http://127.0.0.1:8983/solr/myhandler?'));
->with($this->equalTo('http://127.0.0.1:8983/solr/myhandler'));
$mock->expects($this->once())
->method('setHeaders')
->with($this->equalTo(array(
......@@ -123,6 +175,9 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
$mock->expects($this->once())
->method('setRawData')
->with($this->equalTo($rawData));
$mock->expects($this->once())
->method('setParameterGet')
->with($this->equalTo($params));
$mock->expects($this->once())
->method('request')
->will($this->returnValue($response));
......
......@@ -34,6 +34,7 @@ use Solarium\QueryType\Update\Query\Document\Document;
use Solarium\Plugin\BufferedAdd\Event\AddDocument;
use Solarium\Plugin\BufferedAdd\BufferedAdd;
use Solarium\Core\Client\Client;
use Solarium\Core\Client\Endpoint;
use Solarium\Plugin\BufferedAdd\Event\Events;
class BufferedAddTest extends \PHPUnit_Framework_TestCase
......@@ -195,4 +196,12 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$plugin->addDocument($doc);
}
public function testSetAndGetEndpoint()
{
$endpoint = new Endpoint();
$endpoint->setKey('master');
$this->assertEquals($this->plugin, $this->plugin->setEndpoint($endpoint));
$this->assertEquals($endpoint, $this->plugin->getEndPoint());
}
}
......@@ -471,12 +471,14 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$this->assertThat($doc, $this->isInstanceOf(__NAMESPACE__.'\\MyCustomDoc'));
}
public function testCreateDocumentWithFieldsAndBoosts()
public function testCreateDocumentWithFieldsAndBoostsAndModifiers()
{
$fields = array('id' => 1, 'name' => 'testname');
$boosts = array('name' => 2.7);
$modifiers = array('name' => 'set');
$doc = $this->query->createDocument($fields, $boosts);
$doc = $this->query->createDocument($fields, $boosts, $modifiers);
$doc->setKey('id');
$this->assertThat($doc, $this->isInstanceOf($this->query->getDocumentClass()));
......@@ -489,6 +491,11 @@ class QueryTest extends \PHPUnit_Framework_TestCase
2.7,
$doc->getFieldBoost('name')
);
$this->assertEquals(
$modifiers['name'],
$doc->getFieldModifier('name')
);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment