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

Updated plugin testcases for new events

parent 9a0a166f
......@@ -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,6 +65,8 @@ class PluginTest extends \PHPUnit_Framework_TestCase
public function testEventHooksEmpty()
{
/*
*
$this->assertEquals(null, $this->plugin->preCreateRequest(null));
$this->assertEquals(null, $this->plugin->postCreateRequest(null,null));
$this->assertEquals(null, $this->plugin->preExecuteRequest(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