Commit 2a3206ad authored by Plinio Ribeiro's avatar Plinio Ribeiro Committed by Markus Kalkbrenner

Remove client dependency from Result (#424)

parent 44e420db
......@@ -739,7 +739,7 @@ class Client extends Configurable implements ClientInterface
}
$resultClass = $query->getResultClass();
$result = new $resultClass($this, $query, $response);
$result = new $resultClass($query, $response);
if (!($result instanceof ResultInterface)) {
throw new UnexpectedValueException('Result class must implement the ResultInterface');
......
......@@ -78,25 +78,16 @@ class Result implements ResultInterface
*/
protected $query;
/**
* Solarium client instance.
*
* @var Client
*/
protected $client;
/**
* Constructor.
*
* @throws HttpException
*
* @param Client $client
* @param AbstractQuery $query
* @param Response $response
*/
public function __construct($client, $query, $response)
public function __construct($query, $response)
{
$this->client = $client;
$this->query = $query;
$this->response = $response;
......
......@@ -712,7 +712,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::PRE_CREATE_RESULT);
}
$expectedResult = new Result($this->client, $query, $response);
$expectedResult = new Result($query, $response);
$test = $this;
$this->client->getEventDispatcher()->addListener(
......@@ -749,7 +749,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{
$query = new PingQuery();
$response = new Response('', array('HTTP 1.0 200 OK'));
$result = new Result($this->client, $query, $response);
$result = new Result($query, $response);
$observer = $this->getMock(
'Solarium\Core\Client\Client',
......@@ -778,7 +778,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{
$query = new PingQuery();
$response = new Response('', array('HTTP 1.0 200 OK'));
$result = new Result($this->client, $query, $response);
$result = new Result($query, $response);
$expectedEvent = new PreExecuteEvent($query);
......@@ -815,7 +815,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{
$query = new PingQuery();
$response = new Response('', array('HTTP 1.0 200 OK'));
$result = new Result($this->client, $query, $response);
$result = new Result($query, $response);
$expectedEvent = new PostExecuteEvent($query, $result);
$mock = $this->getMock('Solarium\Core\Client\Client', array('createRequest', 'executeRequest', 'createResult'));
......@@ -851,7 +851,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{
$query = new PingQuery();
$response = new Response('', array('HTTP 1.0 200 OK'));
$expectedResult = new Result($this->client, $query, $response);
$expectedResult = new Result($query, $response);
$expectedEvent = new PreExecuteEvent($query);
if (method_exists($expectedEvent, 'setDispatcher')) {
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
......
......@@ -44,7 +44,7 @@ class PostCreateResultTest extends \PHPUnit_Framework_TestCase
$query = $client->createSelect();
$query->setQuery('test123');
$response = new Response('', array('HTTP 1.0 200 OK'));
$result = new Result($client, $query, $response);
$result = new Result($query, $response);
$event = new PostCreateResult($query, $response, $result);
......
......@@ -44,7 +44,7 @@ class PostExecuteTest extends \PHPUnit_Framework_TestCase
$query = $client->createSelect();
$query->setQuery('test123');
$response = new Response('', array('HTTP 1.0 200 OK'));
$result = new Result($client, $query, $response);
$result = new Result($query, $response);
$event = new PostExecute($query, $result);
......
......@@ -65,7 +65,7 @@ class PreCreateResultTest extends \PHPUnit_Framework_TestCase
$query->setQuery('test123');
$response = new Response('', array('HTTP 1.0 200 OK'));
$result = new Result($client, $query, $response);
$result = new Result($query, $response);
$event->setResult($result);
$this->assertEquals($result, $event->getResult());
......
......@@ -62,7 +62,7 @@ class PreExecuteTest extends \PHPUnit_Framework_TestCase
$query = $client->createSelect();
$query->setQuery('test123');
$response = new Response('', array('HTTP 1.0 200 OK'));
$result = new Result($client, $query, $response);
$result = new Result($query, $response);
$event->setResult($result);
$this->assertEquals($result, $event->getResult());
......
......@@ -49,7 +49,7 @@ class QueryTypeTest extends \PHPUnit_Framework_TestCase
$client = new Client;
$query = new UpdateQuery;
$response = new Response('{"responseHeader":{"status":1,"QTime":12}}', array('HTTP 1.1 200 OK'));
$this->result = new QueryTypeDummy($client, $query, $response);
$this->result = new QueryTypeDummy($query, $response);
}
public function testParseResponse()
......@@ -57,7 +57,7 @@ class QueryTypeTest extends \PHPUnit_Framework_TestCase
$client = new Client;
$query = new QueryDummyTest;
$response = new Response('{"responseHeader":{"status":1,"QTime":12}}', array('HTTP 1.1 200 OK'));
$result = new QueryTypeDummy($client, $query, $response);
$result = new QueryTypeDummy($query, $response);
$this->setExpectedException('Solarium\Exception\UnexpectedValueException');
$result->parse();
......
......@@ -58,7 +58,7 @@ class ResultTest extends \PHPUnit_Framework_TestCase
'"response":{"numFound":0,"start":0,"docs":[]}}';
$this->response = new Response($data, $this->headers);
$this->result = new Result($this->client, $this->query, $this->response);
$this->result = new Result($this->query, $this->response);
}
public function testResultWithErrorResponse()
......@@ -67,7 +67,7 @@ class ResultTest extends \PHPUnit_Framework_TestCase
$response = new Response('Error message', $headers);
$this->setExpectedException('Solarium\Exception\HttpException');
new Result($this->client, $this->query, $response);
new Result($this->query, $response);
}
public function testExceptionGetBody()
......@@ -76,7 +76,7 @@ class ResultTest extends \PHPUnit_Framework_TestCase
$response = new Response('Error message', $headers);
try {
new Result($this->client, $this->query, $response);
new Result($this->query, $response);
} catch (HttpException $e) {
$this->assertEquals('Error message', $e->getBody());
}
......@@ -126,7 +126,7 @@ class ResultTest extends \PHPUnit_Framework_TestCase
);
$response = new Response($phpsData, $this->headers);
$result = new Result($this->client, $this->query, $response);
$result = new Result($this->query, $response);
$this->assertEquals($resultData, $result->getData());
}
......@@ -134,7 +134,7 @@ class ResultTest extends \PHPUnit_Framework_TestCase
public function testGetDataWithUnkownResponseWriter()
{
$this->query->setResponseWriter('asdf');
$result = new Result($this->client, $this->query, $this->response);
$result = new Result($this->query, $this->response);
$this->setExpectedException('Solarium\Exception\RuntimeException');
$result->getData();
......@@ -144,9 +144,10 @@ class ResultTest extends \PHPUnit_Framework_TestCase
{
$data = 'invalid';
$this->response = new Response($data, $this->headers);
$this->result = new Result($this->client, $this->query, $this->response);
$this->result = new Result($this->query, $this->response);
$this->setExpectedException('Solarium\Exception\UnexpectedValueException');
$this->result->getData();
}
}
......@@ -44,7 +44,7 @@ class PostCommitTest extends \PHPUnit_Framework_TestCase
$query = $client->createSelect();
$query->setQuery('test123');
$response = new Response('', array('HTTP 1.0 200 OK'));
$result = new Result($client, $query, $response);
$result = new Result($query, $response);
$event = new PostCommit($result);
......
......@@ -44,7 +44,7 @@ class PostFlushTest extends \PHPUnit_Framework_TestCase
$query = $client->createSelect();
$query->setQuery('test123');
$response = new Response('', array('HTTP 1.0 200 OK'));
$result = new Result($client, $query, $response);
$result = new Result($query, $response);
$event = new PostFlush($result);
......
......@@ -102,7 +102,7 @@ class ResultTest extends \PHPUnit_Framework_TestCase
$query = new Query;
$response = new Response('{"responseHeader":{"status":1,"QTime":12}}', array('HTTP 1.1 200 OK'));
$ping = new Result($client, $query, $response);
$ping = new Result($query, $response);
$this->assertEquals(
$query,
$ping->getQuery()
......
......@@ -44,7 +44,7 @@ class ResultTest extends \PHPUnit_Framework_TestCase
$query = new Query;
$response = new Response('{"responseHeader":{"status":1,"QTime":12}}', array('HTTP 1.1 200 OK'));
$ping = new Result($client, $query, $response);
$ping = new Result($query, $response);
$this->assertEquals(
0,
$ping->getStatus()
......
......@@ -43,7 +43,7 @@ class ResponseParserTest extends \PHPUnit_Framework_TestCase
$data = '{"responseHeader" : {"status":1,"QTime":15}}';
$response = new Response($data, array('HTTP 1.1 200 OK'));
$result = new Result(null, new SelectQuery, $response);
$result = new Result(new SelectQuery, $response);
$parser = new ResponseParser;
$parsed = $parser->parse($result);
......
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