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