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