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

Updated plugin testcases for new events

parent 9a0a166f
...@@ -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,7 +65,9 @@ class PluginTest extends \PHPUnit_Framework_TestCase ...@@ -65,7 +65,9 @@ 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));
$this->assertEquals(null, $this->plugin->postExecuteRequest(null,null)); $this->assertEquals(null, $this->plugin->postExecuteRequest(null,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