Commit ddd69e3f authored by Bas de Nooijer's avatar Bas de Nooijer

Updated plugin testcases for new events

parent 9a0a166f
...@@ -43,7 +43,18 @@ use Solarium\QueryType\Terms\Query as TermsQuery; ...@@ -43,7 +43,18 @@ use Solarium\QueryType\Terms\Query as TermsQuery;
use Solarium\QueryType\Suggester\Query as SuggesterQuery; use Solarium\QueryType\Suggester\Query as SuggesterQuery;
use Solarium\QueryType\Extract\Query as ExtractQuery; use Solarium\QueryType\Extract\Query as ExtractQuery;
use Solarium\Core\Client\Adapter\Http as ClientAdapterHttp; use Solarium\Core\Client\Adapter\Http as ClientAdapterHttp;
use Solarium\Core\Plugin; use Solarium\Core\Plugin\Plugin;
use Solarium\Core\Event\Events;
use Solarium\Core\Event\PreCreateRequest as PreCreateRequestEvent;
use Solarium\Core\Event\PostCreateRequest as PostCreateRequestEvent;
use Solarium\Core\Event\PreCreateQuery as PreCreateQueryEvent;
use Solarium\Core\Event\PostCreateQuery as PostCreateQueryEvent;
use Solarium\Core\Event\PreCreateResult as PreCreateResultEvent;
use Solarium\Core\Event\PostCreateResult as PostCreateResultEvent;
use Solarium\Core\Event\PreExecute as PreExecuteEvent;
use Solarium\Core\Event\PostExecute as PostExecuteEvent;
use Solarium\Core\Event\PreExecuteRequest as PreExecuteRequestEvent;
use Solarium\Core\Event\PostExecuteRequest as PostExecuteRequestEvent;
class ClientTest extends \PHPUnit_Framework_TestCase class ClientTest extends \PHPUnit_Framework_TestCase
{ {
...@@ -482,11 +493,9 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -482,11 +493,9 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$observer = $this->getMock('Solarium\Core\Query\RequestBuilder', array('build')); $observer = $this->getMock('Solarium\Core\Query\RequestBuilder', array('build'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('build') ->method('build')
->with($this->equalTo($queryStub)); ->with($this->equalTo($queryStub))
->will($this->returnValue(new Request()));
$queryStub->expects($this->any())
->method('getType')
->will($this->returnValue('testquerytype'));
$queryStub->expects($this->any()) $queryStub->expects($this->any())
->method('getType') ->method('getType')
->will($this->returnValue('testquerytype')); ->will($this->returnValue('testquerytype'));
...@@ -512,13 +521,19 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -512,13 +521,19 @@ class ClientTest extends \PHPUnit_Framework_TestCase
public function testCreateRequestPrePlugin() public function testCreateRequestPrePlugin()
{ {
$query = new SelectQuery(); $query = new SelectQuery();
$expectedEvent = new PreCreateRequestEvent($query);
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('preCreateRequest'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('preCreateRequest') ->method('preCreateRequest')
->with($this->equalTo($query)); ->with($this->equalTo($expectedEvent));
$this->client->registerPlugin('testplugin', $observer); $this->client->registerPlugin('testplugin', $observer);
$this->client->getEventDispatcher()->addListener(
Events::PRE_CREATE_REQUEST,
array($observer, 'preCreateRequest')
);
$this->client->createRequest($query); $this->client->createRequest($query);
} }
...@@ -526,33 +541,44 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -526,33 +541,44 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{ {
$query = new SelectQuery(); $query = new SelectQuery();
$request = $this->client->createRequest($query); $request = $this->client->createRequest($query);
$expectedEvent = new PostCreateRequestEvent($query, $request);
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('postCreateRequest'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('postCreateRequest') ->method('postCreateRequest')
->with($this->equalTo($query),$this->equalTo($request)); ->with($this->equalTo($expectedEvent));
$this->client->registerPlugin('testplugin', $observer); $this->client->registerPlugin('testplugin', $observer);
$this->client->getEventDispatcher()->addListener(
Events::POST_CREATE_REQUEST,
array($observer, 'postCreateRequest')
);
$this->client->createRequest($query); $this->client->createRequest($query);
} }
public function testCreateRequestWithOverridingPlugin() public function testCreateRequestWithOverridingPlugin()
{ {
$overrideValue = 'dummyvalue'; $expectedRequest = new Request();
$expectedRequest->setHandler('something-unique-345978');
$query = new SelectQuery(); $query = new SelectQuery();
$expectedEvent = new PreCreateRequestEvent($query);
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $test = $this;
$observer->expects($this->once()) $this->client->getEventDispatcher()->addListener(
->method('preCreateRequest') Events::PRE_CREATE_REQUEST,
->with($this->equalTo($query)) function (PreCreateRequestEvent $event) use ($test, $expectedRequest, $expectedEvent) {
->will($this->returnValue($overrideValue)); $test->assertEquals($expectedEvent, $event);
$event->setRequest($expectedRequest);
}
);
$this->client->registerPlugin('testplugin', $observer); $returnedRequest = $this->client->createRequest($query);
$request = $this->client->createRequest($query);
$this->assertEquals( $this->assertEquals(
$overrideValue, $expectedRequest,
$request $returnedRequest
); );
} }
...@@ -572,13 +598,19 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -572,13 +598,19 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{ {
$query = new SelectQuery(); $query = new SelectQuery();
$response = new Response('',array('HTTP 1.0 200 OK')); $response = new Response('',array('HTTP 1.0 200 OK'));
$expectedEvent = new PreCreateResultEvent($query, $response);
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('preCreateResult'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('preCreateResult') ->method('preCreateResult')
->with($this->equalTo($query),$this->equalTo($response)); ->with($this->equalTo($expectedEvent));
$this->client->registerPlugin('testplugin', $observer); $this->client->registerPlugin('testplugin', $observer);
$this->client->getEventDispatcher()->addListener(
Events::PRE_CREATE_RESULT,
array($observer, 'preCreateResult')
);
$this->client->createResult($query, $response); $this->client->createResult($query, $response);
} }
...@@ -587,34 +619,43 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -587,34 +619,43 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$query = new SelectQuery(); $query = new SelectQuery();
$response = new Response('',array('HTTP 1.0 200 OK')); $response = new Response('',array('HTTP 1.0 200 OK'));
$result = $this->client->createResult($query, $response); $result = $this->client->createResult($query, $response);
$expectedEvent = new PostCreateResultEvent($query, $response, $result);
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('postCreateResult'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('postCreateResult') ->method('postCreateResult')
->with($this->equalTo($query), $this->equalTo($response), $this->equalTo($result)); ->with($this->equalTo($expectedEvent));
$this->client->registerPlugin('testplugin', $observer); $this->client->registerPlugin('testplugin', $observer);
$this->client->getEventDispatcher()->addListener(
Events::POST_CREATE_RESULT,
array($observer, 'postCreateResult')
);
$this->client->createResult($query, $response); $this->client->createResult($query, $response);
} }
public function testCreateResultWithOverridingPlugin() public function testCreateResultWithOverridingPlugin()
{ {
$overrideValue = 'dummyvalue';
$query = new SelectQuery(); $query = new SelectQuery();
$response = new Response('',array('HTTP 1.0 200 OK')); $response = new Response('test 1234',array('HTTP 1.0 200 OK'));
$expectedEvent = new PreCreateResultEvent($query, $response);
$expectedResult = new Result($this->client, $query, $response);
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $test = $this;
$observer->expects($this->once()) $this->client->getEventDispatcher()->addListener(
->method('preCreateResult') Events::PRE_CREATE_RESULT,
->with($this->equalTo($query), $this->equalTo($response)) function (PreCreateResultEvent $event) use ($test, $expectedResult, $expectedEvent) {
->will($this->returnValue($overrideValue)); $test->assertEquals($expectedEvent, $event);
$event->setResult($expectedResult);
}
);
$this->client->registerPlugin('testplugin', $observer); $returnedResult = $this->client->createResult($query, $response);
$result = $this->client->createResult($query, $response);
$this->assertEquals( $this->assertEquals(
$overrideValue, $expectedResult,
$result $returnedResult
); );
} }
...@@ -635,6 +676,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -635,6 +676,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
public function testExecute() public function testExecute()
{ {
$query = new PingQuery(); $query = new PingQuery();
$response = new Response('',array('HTTP 1.0 200 OK'));
$result = new Result($this->client, $query, $response);
$observer = $this->getMock('Solarium\Core\Client\Client', array('createRequest','executeRequest','createResult')); $observer = $this->getMock('Solarium\Core\Client\Client', array('createRequest','executeRequest','createResult'));
...@@ -650,7 +693,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -650,7 +693,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$observer->expects($this->once()) $observer->expects($this->once())
->method('createResult') ->method('createResult')
->with($this->equalTo($query),$this->equalTo('dummyresponse')); ->with($this->equalTo($query),$this->equalTo('dummyresponse'))
->will($this->returnValue($result));
$observer->execute($query); $observer->execute($query);
} }
...@@ -658,6 +702,9 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -658,6 +702,9 @@ class ClientTest extends \PHPUnit_Framework_TestCase
public function testExecutePrePlugin() public function testExecutePrePlugin()
{ {
$query = new PingQuery(); $query = new PingQuery();
$response = new Response('',array('HTTP 1.0 200 OK'));
$result = new Result($this->client, $query, $response);
$expectedEvent = new PreExecuteEvent($query);
$mock = $this->getMock('Solarium\Core\Client\Client', array('createRequest','executeRequest','createResult')); $mock = $this->getMock('Solarium\Core\Client\Client', array('createRequest','executeRequest','createResult'));
...@@ -671,20 +718,23 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -671,20 +718,23 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('createResult') ->method('createResult')
->will($this->returnValue('dummyresult')); ->will($this->returnValue($result));
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('preExecute'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('preExecute') ->method('preExecute')
->with($this->equalTo($query)); ->with($this->equalTo($expectedEvent));
$mock->registerPlugin('testplugin', $observer); $mock->getEventDispatcher()->addListener(Events::PRE_EXECUTE, array($observer, 'preExecute'));
$mock->execute($query); $mock->execute($query);
} }
public function testExecutePostPlugin() public function testExecutePostPlugin()
{ {
$query = new PingQuery(); $query = new PingQuery();
$response = new Response('',array('HTTP 1.0 200 OK'));
$result = new Result($this->client, $query, $response);
$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'));
...@@ -698,117 +748,128 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -698,117 +748,128 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$mock->expects($this->once()) $mock->expects($this->once())
->method('createResult') ->method('createResult')
->will($this->returnValue('dummyresult')); ->will($this->returnValue($result));
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('postExecute'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('postExecute') ->method('postExecute')
->with($this->equalTo($query), $this->equalTo('dummyresult')); ->with($this->equalTo($expectedEvent));
$mock->registerPlugin('testplugin', $observer); $mock->getEventDispatcher()->addListener(Events::POST_EXECUTE, array($observer, 'postExecute'));
$mock->execute($query); $mock->execute($query);
} }
public function testExecuteWithOverridingPlugin() public function testExecuteWithOverridingPlugin()
{ {
$query = new PingQuery(); $query = new PingQuery();
$response = new Response('',array('HTTP 1.0 200 OK'));
$expectedResult = new Result($this->client, $query, $response);
$expectedEvent = new PreExecuteEvent($query);
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $test = $this;
$observer->expects($this->once()) $this->client->getEventDispatcher()->addListener(
->method('preExecute') Events::PRE_EXECUTE,
->with($this->equalTo($query)) function (PreExecuteEvent $event) use ($test, $expectedResult, $expectedEvent) {
->will($this->returnValue('dummyoverride')); $test->assertEquals($expectedEvent, $event);
$event->setResult($expectedResult);
}
);
$this->client->registerPlugin('testplugin', $observer); $returnedResult = $this->client->execute($query);
$result = $this->client->execute($query);
$this->assertEquals( $this->assertEquals(
'dummyoverride', $expectedResult,
$result $returnedResult
); );
} }
public function testExecuteRequest() public function testExecuteRequest()
{ {
$request = new Request(); $request = new Request();
$dummyResponse = 'dummyresponse'; $response = new Response('',array('HTTP 1.0 200 OK'));
$observer = $this->getMock('Solarium\Core\Client\Adapter\Http', array('execute')); $observer = $this->getMock('Solarium\Core\Client\Adapter\Http', array('execute'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('execute') ->method('execute')
->with($this->equalTo($request)) ->with($this->equalTo($request))
->will($this->returnValue($dummyResponse)); ->will($this->returnValue($response));
$this->client->setAdapter($observer); $this->client->setAdapter($observer);
$response = $this->client->executeRequest($request); $returnedResponse = $this->client->executeRequest($request);
$this->assertEquals( $this->assertEquals(
$dummyResponse, $response,
$response $returnedResponse
); );
} }
public function testExecuteRequestPrePlugin() public function testExecuteRequestPrePlugin()
{ {
$request = new Request(); $request = new Request();
$dummyResponse = 'dummyresponse'; $endpoint = $this->client->createEndpoint('s1');
$response = new Response('',array('HTTP 1.0 200 OK'));
$expectedEvent = new PreExecuteRequestEvent($request, $endpoint);
$mockAdapter = $this->getMock('Solarium\Core\Client\Adapter\Http', array('execute')); $mockAdapter = $this->getMock('Solarium\Core\Client\Adapter\Http', array('execute'));
$mockAdapter->expects($this->once()) $mockAdapter->expects($this->once())
->method('execute') ->method('execute')
->with($this->equalTo($request)) ->with($this->equalTo($request))
->will($this->returnValue($dummyResponse)); ->will($this->returnValue($response));
$this->client->setAdapter($mockAdapter); $this->client->setAdapter($mockAdapter);
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('preExecuteRequest'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('preExecuteRequest') ->method('preExecuteRequest')
->with($this->equalTo($request)); ->with($this->equalTo($expectedEvent));
$this->client->registerPlugin('testplugin', $observer); $this->client->getEventDispatcher()->addListener(Events::PRE_EXECUTE_REQUEST, array($observer, 'preExecuteRequest'));
$this->client->executeRequest($request); $this->client->executeRequest($request, $endpoint);
} }
public function testExecuteRequestPostPlugin() public function testExecuteRequestPostPlugin()
{ {
$request = new Request(); $request = new Request();
$dummyResponse = 'dummyresponse'; $endpoint = $this->client->createEndpoint('s1');
$response = new Response('',array('HTTP 1.0 200 OK'));
$expectedEvent = new PostExecuteRequestEvent($request, $endpoint, $response);
$mockAdapter = $this->getMock('Solarium\Core\Client\Adapter\Http', array('execute')); $mockAdapter = $this->getMock('Solarium\Core\Client\Adapter\Http', array('execute'));
$mockAdapter->expects($this->any()) $mockAdapter->expects($this->any())
->method('execute') ->method('execute')
->with($this->equalTo($request)) ->with($this->equalTo($request))
->will($this->returnValue($dummyResponse)); ->will($this->returnValue($response));
$this->client->setAdapter($mockAdapter); $this->client->setAdapter($mockAdapter);
$response = $this->client->executeRequest($request); $observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('postExecuteRequest'));
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array()));
$observer->expects($this->once()) $observer->expects($this->once())
->method('postExecuteRequest') ->method('postExecuteRequest')
->with($this->equalTo($request), $this->equalTo($response)); ->with($this->equalTo($expectedEvent));
$this->client->registerPlugin('testplugin', $observer); $this->client->getEventDispatcher()->addListener(Events::POST_EXECUTE_REQUEST, array($observer, 'postExecuteRequest'));
$this->client->executeRequest($request); $this->client->executeRequest($request, $endpoint);
} }
public function testExecuteRequestWithOverridingPlugin() public function testExecuteRequestWithOverridingPlugin()
{ {
$request = new Request(); $request = new Request();
$dummyOverride = 'dummyoverride'; $response = new Response('',array('HTTP 1.0 200 OK'));
$endpoint = $this->client->createEndpoint('s1');
$expectedEvent = new PreExecuteRequestEvent($request, $endpoint);
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $test = $this;
$observer->expects($this->once()) $this->client->getEventDispatcher()->addListener(
->method('preExecuteRequest') Events::PRE_EXECUTE_REQUEST,
->with($this->equalTo($request)) function (PreExecuteRequestEvent $event) use ($test, $response, $expectedEvent) {
->will($this->returnValue($dummyOverride)); $test->assertEquals($expectedEvent, $event);
$event->setResponse($response);
}
);
$this->client->registerPlugin('testplugin', $observer); $returnedResponse = $this->client->executeRequest($request, $endpoint);
$response = $this->client->executeRequest($request);
$this->assertEquals( $this->assertEquals(
$dummyOverride, $response,
$response $returnedResponse
); );
} }
...@@ -941,34 +1002,39 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -941,34 +1002,39 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{ {
$type = Client::QUERY_SELECT; $type = Client::QUERY_SELECT;
$options = array('optionA' => 1, 'optionB' => 2); $options = array('optionA' => 1, 'optionB' => 2);
$expectedEvent = new PreCreateQueryEvent($type, $options);
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('preCreateQuery'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('preCreateQuery') ->method('preCreateQuery')
->with($this->equalTo($type), $this->equalTo($options)); ->with($this->equalTo($expectedEvent));
$this->client->registerPlugin('testplugin', $observer); $this->client->getEventDispatcher()->addListener(Events::PRE_CREATE_QUERY, array($observer, 'preCreateQuery'));
$this->client->createQuery($type, $options); $this->client->createQuery($type, $options);
} }
public function testCreateQueryWithOverridingPlugin() public function testCreateQueryWithOverridingPlugin()
{ {
$type = Client::QUERY_SELECT; $type = Client::QUERY_SELECT;
$options = array('optionA' => 1, 'optionB' => 2); $options = array('query' => 'test789');
$dummyvalue = 'test123'; $expectedQuery = new SelectQuery();
$expectedQuery->setQuery('test789');
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $expectedEvent = new PreCreateQueryEvent($type, $options);
$observer->expects($this->once())
->method('preCreateQuery') $test = $this;
->with($this->equalTo($type), $this->equalTo($options)) $this->client->getEventDispatcher()->addListener(
->will($this->returnValue($dummyvalue)); Events::PRE_CREATE_QUERY,
function (PreCreateQueryEvent $event) use ($test, $expectedQuery, $expectedEvent) {
$test->assertEquals($expectedEvent, $event);
$event->setQuery($expectedQuery);
}
);
$this->client->registerPlugin('testplugin', $observer); $returnedQuery = $this->client->createQuery($type, $options);
$query = $this->client->createQuery($type, $options);
$this->assertEquals( $this->assertEquals(
$dummyvalue, $expectedQuery,
$query $returnedQuery
); );
} }
...@@ -977,13 +1043,18 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -977,13 +1043,18 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$type = Client::QUERY_SELECT; $type = Client::QUERY_SELECT;
$options = array('optionA' => 1, 'optionB' => 2); $options = array('optionA' => 1, 'optionB' => 2);
$query = $this->client->createQuery($type, $options); $query = $this->client->createQuery($type, $options);
$expectedEvent = new PostCreateQueryEvent($type, $options, $query);
$observer = $this->getMock('Solarium\Core\Plugin', array(), array($this->client,array())); $observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('postCreateQuery'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('postCreateQuery') ->method('postCreateQuery')
->with($this->equalTo($type), $this->equalTo($options), $this->equalTo($query)); ->with($this->equalTo($expectedEvent));
$this->client->getEventDispatcher()->addListener(
Events::POST_CREATE_QUERY,
array($observer, 'postCreateQuery')
);
$this->client->registerPlugin('testplugin', $observer);
$this->client->createQuery($type, $options); $this->client->createQuery($type, $options);
} }
...@@ -1095,20 +1166,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -1095,20 +1166,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$observer->createExtract($options); $observer->createExtract($options);
} }
public function testTriggerEvent()
{
$eventName = 'Test';
$params = array('a', 'b');
$override = true;
$clientMock = $this->getMock('Solarium\Core\Client\Client', array('callPlugins'));
$clientMock->expects($this->once())
->method('callPlugins')
->with($this->equalTo('event'.$eventName), $this->equalTo($params), $override);
$clientMock->triggerEvent($eventName, $params, $override);
}
} }
class MyAdapter extends ClientAdapterHttp class MyAdapter extends ClientAdapterHttp
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\Core; namespace Solarium\Tests\Core\Plugin;
use Solarium\Core\Plugin; use Solarium\Core\Plugin\Plugin;
class PluginTest extends \PHPUnit_Framework_TestCase class PluginTest extends \PHPUnit_Framework_TestCase
{ {
...@@ -65,6 +65,8 @@ class PluginTest extends \PHPUnit_Framework_TestCase ...@@ -65,6 +65,8 @@ class PluginTest extends \PHPUnit_Framework_TestCase
public function testEventHooksEmpty() public function testEventHooksEmpty()
{ {
/*
*
$this->assertEquals(null, $this->plugin->preCreateRequest(null)); $this->assertEquals(null, $this->plugin->preCreateRequest(null));
$this->assertEquals(null, $this->plugin->postCreateRequest(null,null)); $this->assertEquals(null, $this->plugin->postCreateRequest(null,null));
$this->assertEquals(null, $this->plugin->preExecuteRequest(null)); $this->assertEquals(null, $this->plugin->preExecuteRequest(null));
...@@ -75,6 +77,7 @@ class PluginTest extends \PHPUnit_Framework_TestCase ...@@ -75,6 +77,7 @@ class PluginTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(null, $this->plugin->postCreateResult(null,null,null)); $this->assertEquals(null, $this->plugin->postCreateResult(null,null,null));
$this->assertEquals(null, $this->plugin->preCreateQuery(null,null)); $this->assertEquals(null, $this->plugin->preCreateQuery(null,null));
$this->assertEquals(null, $this->plugin->postCreateQuery(null,null,null)); $this->assertEquals(null, $this->plugin->postCreateQuery(null,null,null));
*/
} }
} }
......
...@@ -29,9 +29,9 @@ ...@@ -29,9 +29,9 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\Plugin; namespace Solarium\Tests\Plugin\BufferedAdd;
use Solarium\QueryType\Update\Query\Document; use Solarium\QueryType\Update\Query\Document;
use Solarium\Plugin\BufferedAdd; use Solarium\Plugin\BufferedAdd\BufferedAdd;
use Solarium\Core\Client\Client; use Solarium\Core\Client\Client;
class BufferedAddTest extends \PHPUnit_Framework_TestCase class BufferedAddTest extends \PHPUnit_Framework_TestCase
...@@ -93,7 +93,7 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase ...@@ -93,7 +93,7 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
public function testAddDocumentAutoFlush() public function testAddDocumentAutoFlush()
{ {
$observer = $this->getMock('Solarium\Plugin\BufferedAdd', array('flush')); $observer = $this->getMock('Solarium\Plugin\BufferedAdd\BufferedAdd', array('flush'));
$observer->expects($this->once())->method('flush'); $observer->expects($this->once())->method('flush');
$observer->setBufferSize(1); $observer->setBufferSize(1);
...@@ -138,7 +138,6 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase ...@@ -138,7 +138,6 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$mockClient = $this->getMock('Solarium\Core\Client\Client', array('createUpdate', 'update', 'triggerEvent')); $mockClient = $this->getMock('Solarium\Core\Client\Client', array('createUpdate', 'update', 'triggerEvent'));
$mockClient->expects($this->exactly(2))->method('createUpdate')->will($this->returnValue($mockUpdate)); $mockClient->expects($this->exactly(2))->method('createUpdate')->will($this->returnValue($mockUpdate));
$mockClient->expects($this->once())->method('update')->will($this->returnValue('dummyResult')); $mockClient->expects($this->once())->method('update')->will($this->returnValue('dummyResult'));
$mockClient->expects($this->exactly(2))->method('triggerEvent');
$plugin = new BufferedAdd(); $plugin = new BufferedAdd();
$plugin->initPlugin($mockClient, array()); $plugin->initPlugin($mockClient, array());
...@@ -159,7 +158,6 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase ...@@ -159,7 +158,6 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$mockClient = $this->getMock('Solarium\Core\Client\Client', array('createUpdate', 'update', 'triggerEvent')); $mockClient = $this->getMock('Solarium\Core\Client\Client', array('createUpdate', 'update', 'triggerEvent'));
$mockClient->expects($this->exactly(2))->method('createUpdate')->will($this->returnValue($mockUpdate)); $mockClient->expects($this->exactly(2))->method('createUpdate')->will($this->returnValue($mockUpdate));
$mockClient->expects($this->once())->method('update')->will($this->returnValue('dummyResult')); $mockClient->expects($this->once())->method('update')->will($this->returnValue('dummyResult'));
$mockClient->expects($this->exactly(2))->method('triggerEvent');
$plugin = new BufferedAdd(); $plugin = new BufferedAdd();
$plugin->initPlugin($mockClient, array()); $plugin->initPlugin($mockClient, array());
......
...@@ -33,6 +33,8 @@ namespace Solarium\Tests\Plugin\CustomizeRequest; ...@@ -33,6 +33,8 @@ namespace Solarium\Tests\Plugin\CustomizeRequest;
use Solarium\Plugin\CustomizeRequest\CustomizeRequest; use Solarium\Plugin\CustomizeRequest\CustomizeRequest;
use Solarium\Plugin\CustomizeRequest\Customization; use Solarium\Plugin\CustomizeRequest\Customization;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Client\Endpoint;
use Solarium\Core\Event\PreExecuteRequest as PreExecuteRequestEvent;
class CustomizeRequestTest extends \PHPUnit_Framework_TestCase class CustomizeRequestTest extends \PHPUnit_Framework_TestCase
{ {
...@@ -326,7 +328,8 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase ...@@ -326,7 +328,8 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase
$this->plugin->addCustomization($input); $this->plugin->addCustomization($input);
$request = new Request(); $request = new Request();
$this->plugin->postCreateRequest(null, $request); $event = new PreExecuteRequestEvent($request, new Endpoint);
$this->plugin->preExecuteRequest($event);
$this->assertEquals( $this->assertEquals(
123, 123,
...@@ -339,7 +342,7 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase ...@@ -339,7 +342,7 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase
); );
} }
public function testPostCreateRequestWithInvalidCustomization() public function testPreExecuteRequestWithInvalidCustomization()
{ {
$input = array( $input = array(
'key' => 'xid', 'key' => 'xid',
...@@ -350,17 +353,19 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase ...@@ -350,17 +353,19 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase
$this->plugin->addCustomization($input); $this->plugin->addCustomization($input);
$request = new Request(); $request = new Request();
$event = new PreExecuteRequestEvent($request, new Endpoint);
$this->setExpectedException('Solarium\Exception\RuntimeException'); $this->setExpectedException('Solarium\Exception\RuntimeException');
$this->plugin->postCreateRequest(null, $request); $this->plugin->preExecuteRequest($event);
} }
public function testPostCreateRequestWithoutCustomizations() public function testPreExecuteRequestWithoutCustomizations()
{ {
$request = new Request(); $request = new Request();
$originalRequest = clone $request; $originalRequest = clone $request;
$this->plugin->postCreateRequest(null, $request); $event = new PreExecuteRequestEvent($request, new Endpoint);
$this->plugin->preExecuteRequest($event);
$this->assertEquals( $this->assertEquals(
$originalRequest, $originalRequest,
...@@ -368,7 +373,7 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase ...@@ -368,7 +373,7 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase
); );
} }
public function testPostCreateRequestWithPersistentAndNonPersistentCustomizations() public function testPreExecuteRequestWithPersistentAndNonPersistentCustomizations()
{ {
$input = array( $input = array(
'key' => 'xid', 'key' => 'xid',
...@@ -388,7 +393,8 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase ...@@ -388,7 +393,8 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase
$this->plugin->addCustomization($input); $this->plugin->addCustomization($input);
$request = new Request(); $request = new Request();
$this->plugin->postCreateRequest(null, $request); $event = new PreExecuteRequestEvent($request, new Endpoint);
$this->plugin->preExecuteRequest($event);
$this->assertEquals( $this->assertEquals(
123, 123,
...@@ -402,7 +408,8 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase ...@@ -402,7 +408,8 @@ class CustomizeRequestTest extends \PHPUnit_Framework_TestCase
// second use, only the header should be persistent // second use, only the header should be persistent
$request = new Request(); $request = new Request();
$this->plugin->postCreateRequest(null, $request); $event = new PreExecuteRequestEvent($request, new Endpoint);
$this->plugin->preExecuteRequest($event);
$this->assertEquals( $this->assertEquals(
null, null,
......
...@@ -35,8 +35,11 @@ use Solarium\Plugin\Loadbalancer\Loadbalancer; ...@@ -35,8 +35,11 @@ use Solarium\Plugin\Loadbalancer\Loadbalancer;
use Solarium\QueryType\Select\Query\Query as SelectQuery; use Solarium\QueryType\Select\Query\Query as SelectQuery;
use Solarium\QueryType\Update\Query\Query as UpdateQuery; use Solarium\QueryType\Update\Query\Query as UpdateQuery;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Client\Endpoint;
use Solarium\Core\Client\Adapter\Http as HttpAdapter; use Solarium\Core\Client\Adapter\Http as HttpAdapter;
use Solarium\Exception\HttpException; use Solarium\Exception\HttpException;
use Solarium\Core\Event\PreCreateRequest as PreCreateRequestEvent;
use Solarium\Core\Event\PreExecuteRequest as PreExecuteRequestEvent;
class LoadbalancerTest extends \PHPUnit_Framework_TestCase class LoadbalancerTest extends \PHPUnit_Framework_TestCase
{ {
...@@ -309,8 +312,12 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase ...@@ -309,8 +312,12 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase
$this->plugin->setEndpoints($endpoints); $this->plugin->setEndpoints($endpoints);
$this->plugin->setForcedEndpointForNextQuery('server2'); $this->plugin->setForcedEndpointForNextQuery('server2');
$this->plugin->preCreateRequest($query);
$this->plugin->preExecuteRequest($request); $event = new PreCreateRequestEvent($query);
$this->plugin->preCreateRequest($event);
$event = new PreExecuteRequestEvent($request, new Endpoint);
$this->plugin->preExecuteRequest($event);
$this->assertEquals( $this->assertEquals(
'server2', 'server2',
...@@ -331,8 +338,11 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase ...@@ -331,8 +338,11 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase
$this->plugin->setForcedEndpointForNextQuery('server2'); $this->plugin->setForcedEndpointForNextQuery('server2');
$query = new SelectQuery(); $query = new SelectQuery();
$this->plugin->preCreateRequest($query); $event = new PreCreateRequestEvent($query);
$this->plugin->preExecuteRequest($request); $this->plugin->preCreateRequest($event);
$event = new PreExecuteRequestEvent($request, new Endpoint);
$this->plugin->preExecuteRequest($event);
$this->assertEquals( $this->assertEquals(
'server2', 'server2',
...@@ -340,8 +350,11 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase ...@@ -340,8 +350,11 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase
); );
$query = new SelectQuery(); // this is a blocked querytype that should trigger a restore $query = new SelectQuery(); // this is a blocked querytype that should trigger a restore
$this->plugin->preCreateRequest($query); $event = new PreCreateRequestEvent($query);
$this->plugin->preExecuteRequest($request); $this->plugin->preCreateRequest($event);
$event = new PreExecuteRequestEvent($request, new Endpoint);
$this->plugin->preExecuteRequest($event);
$this->assertEquals( $this->assertEquals(
$originalHost, $originalHost,
...@@ -360,8 +373,11 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase ...@@ -360,8 +373,11 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase
$request = new Request(); $request = new Request();
$query = new UpdateQuery(); // this is a blocked querytype that should not be loadbalanced $query = new UpdateQuery(); // this is a blocked querytype that should not be loadbalanced
$this->plugin->preCreateRequest($query); $event = new PreCreateRequestEvent($query);
$this->plugin->preExecuteRequest($request); $this->plugin->preCreateRequest($event);
$event = new PreExecuteRequestEvent($request, new Endpoint);
$this->plugin->preExecuteRequest($event);
$this->assertEquals( $this->assertEquals(
$originalHost, $originalHost,
...@@ -383,9 +399,12 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase ...@@ -383,9 +399,12 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase
$this->plugin->setEndpoints($endpoints); $this->plugin->setEndpoints($endpoints);
$request = new Request(); $request = new Request();
$query = new SelectQuery(); // $query = new SelectQuery();
$this->plugin->preCreateRequest($query); $event = new PreCreateRequestEvent($query);
$this->plugin->preExecuteRequest($request); $this->plugin->preCreateRequest($event);
$event = new PreExecuteRequestEvent($request, new Endpoint);
$this->plugin->preExecuteRequest($event);
$this->assertTrue( $this->assertTrue(
in_array($this->plugin->getLastEndpoint(), array('server1','server2')) in_array($this->plugin->getLastEndpoint(), array('server1','server2'))
...@@ -407,8 +426,11 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase ...@@ -407,8 +426,11 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase
$this->plugin->setFailoverEnabled(true); $this->plugin->setFailoverEnabled(true);
$query = new SelectQuery(); $query = new SelectQuery();
$this->plugin->preCreateRequest($query); $event = new PreCreateRequestEvent($query);
$this->plugin->preExecuteRequest($request); $this->plugin->preCreateRequest($event);
$event = new PreExecuteRequestEvent($request, new Endpoint);
$this->plugin->preExecuteRequest($event);
$this->assertEquals( $this->assertEquals(
'server2', 'server2',
...@@ -434,11 +456,13 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase ...@@ -434,11 +456,13 @@ class LoadbalancerTest extends \PHPUnit_Framework_TestCase
$this->plugin->setFailoverEnabled(true); $this->plugin->setFailoverEnabled(true);
$query = new SelectQuery(); $query = new SelectQuery();
$this->plugin->preCreateRequest($query); $event = new PreCreateRequestEvent($query);
$this->plugin->preCreateRequest($event);
$this->setExpectedException('Solarium\Exception\RuntimeException', 'Maximum number of loadbalancer retries reached'); $this->setExpectedException('Solarium\Exception\RuntimeException', 'Maximum number of loadbalancer retries reached');
$this->plugin->preExecuteRequest($request); $event = new PreExecuteRequestEvent($request, new Endpoint);
$this->plugin->preExecuteRequest($event);
} }
} }
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* policies, either expressed or implied, of the copyright holder. * policies, either expressed or implied, of the copyright holder.
*/ */
namespace Solarium\Tests\Plugin; namespace Solarium\Tests\Plugin\ParallelExecution;
use Solarium\Plugin\ParallelExecution; use Solarium\Plugin\ParallelExecution\ParallelExecution;
use Solarium\Core\Client\Client; use Solarium\Core\Client\Client;
class ParallelExecutionTest extends \PHPUnit_Framework_TestCase class ParallelExecutionTest extends \PHPUnit_Framework_TestCase
......
...@@ -34,6 +34,7 @@ use Solarium\Plugin\PostBigRequest; ...@@ -34,6 +34,7 @@ use Solarium\Plugin\PostBigRequest;
use Solarium\Core\Client\Client; use Solarium\Core\Client\Client;
use Solarium\QueryType\Select\Query\Query; use Solarium\QueryType\Select\Query\Query;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Event\PostCreateRequest as PostCreateRequestEvent;
class PostBigRequestTest extends \PHPUnit_Framework_TestCase class PostBigRequestTest extends \PHPUnit_Framework_TestCase
{ {
...@@ -79,7 +80,8 @@ class PostBigRequestTest extends \PHPUnit_Framework_TestCase ...@@ -79,7 +80,8 @@ class PostBigRequestTest extends \PHPUnit_Framework_TestCase
$requestOutput = $this->client->createRequest($this->query); $requestOutput = $this->client->createRequest($this->query);
$requestInput = clone $requestOutput; $requestInput = clone $requestOutput;
$this->plugin->postCreateRequest($this->query, $requestOutput); $event = new PostCreateRequestEvent($this->query, $requestOutput);
$this->plugin->postCreateRequest($event);
$this->assertEquals(Request::METHOD_GET, $requestInput->getMethod()); $this->assertEquals(Request::METHOD_GET, $requestInput->getMethod());
$this->assertEquals(Request::METHOD_POST, $requestOutput->getMethod()); $this->assertEquals(Request::METHOD_POST, $requestOutput->getMethod());
...@@ -91,7 +93,8 @@ class PostBigRequestTest extends \PHPUnit_Framework_TestCase ...@@ -91,7 +93,8 @@ class PostBigRequestTest extends \PHPUnit_Framework_TestCase
{ {
$requestOutput = $this->client->createRequest($this->query); $requestOutput = $this->client->createRequest($this->query);
$requestInput = clone $requestOutput; $requestInput = clone $requestOutput;
$this->plugin->postCreateRequest($this->query, $requestOutput); $event = new PostCreateRequestEvent($this->query, $requestOutput);
$this->plugin->postCreateRequest($event);
$this->assertEquals($requestInput, $requestOutput); $this->assertEquals($requestInput, $requestOutput);
} }
...@@ -103,7 +106,8 @@ class PostBigRequestTest extends \PHPUnit_Framework_TestCase ...@@ -103,7 +106,8 @@ class PostBigRequestTest extends \PHPUnit_Framework_TestCase
$requestOutput = $this->client->createRequest($query); $requestOutput = $this->client->createRequest($query);
$requestInput = clone $requestOutput; $requestInput = clone $requestOutput;
$this->plugin->postCreateRequest($query, $requestOutput); $event = new PostCreateRequestEvent($this->query, $requestOutput);
$this->plugin->postCreateRequest($event);
$this->assertEquals($requestInput, $requestOutput); $this->assertEquals($requestInput, $requestOutput);
} }
......
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