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

Unittest fixes for the event dispatcher. Updated event dispatcher to allow for unittest fixes.

parent fb0eec29
......@@ -13,7 +13,7 @@
],
"require": {
"php": ">=5.3.2",
"symfony/event-dispatcher": "2.*"
"symfony/event-dispatcher": "2.1.4"
},
"autoload": {
"psr-0": { "Solarium": "library/" }
......
......@@ -539,6 +539,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{
$query = new SelectQuery();
$expectedEvent = new PreCreateRequestEvent($query);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::PRE_CREATE_REQUEST);
$observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('preCreateRequest'));
$observer->expects($this->once())
......@@ -559,6 +561,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$query = new SelectQuery();
$request = $this->client->createRequest($query);
$expectedEvent = new PostCreateRequestEvent($query, $request);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::POST_CREATE_REQUEST);
$observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('postCreateRequest'));
$observer->expects($this->once())
......@@ -581,6 +585,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$query = new SelectQuery();
$expectedEvent = new PreCreateRequestEvent($query);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::PRE_CREATE_REQUEST);
$test = $this;
$this->client->getEventDispatcher()->addListener(
......@@ -616,6 +622,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$query = new SelectQuery();
$response = new Response('',array('HTTP 1.0 200 OK'));
$expectedEvent = new PreCreateResultEvent($query, $response);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::PRE_CREATE_RESULT);
$observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('preCreateResult'));
$observer->expects($this->once())
......@@ -637,6 +645,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$response = new Response('',array('HTTP 1.0 200 OK'));
$result = $this->client->createResult($query, $response);
$expectedEvent = new PostCreateResultEvent($query, $response, $result);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::POST_CREATE_RESULT);
$observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('postCreateResult'));
$observer->expects($this->once())
......@@ -657,6 +667,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$query = new SelectQuery();
$response = new Response('test 1234',array('HTTP 1.0 200 OK'));
$expectedEvent = new PreCreateResultEvent($query, $response);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::PRE_CREATE_RESULT);
$expectedResult = new Result($this->client, $query, $response);
$test = $this;
......@@ -722,6 +734,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$response = new Response('',array('HTTP 1.0 200 OK'));
$result = new Result($this->client, $query, $response);
$expectedEvent = new PreExecuteEvent($query);
$expectedEvent->setName(Events::PRE_EXECUTE);
$mock = $this->getMock('Solarium\Core\Client\Client', array('createRequest','executeRequest','createResult'));
......@@ -743,6 +756,9 @@ class ClientTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo($expectedEvent));
$mock->getEventDispatcher()->addListener(Events::PRE_EXECUTE, array($observer, 'preExecute'));
$expectedEvent->setDispatcher($mock->getEventDispatcher());
$mock->execute($query);
}
......@@ -752,6 +768,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$response = new Response('',array('HTTP 1.0 200 OK'));
$result = new Result($this->client, $query, $response);
$expectedEvent = new PostExecuteEvent($query, $result);
$expectedEvent->setName(Events::POST_EXECUTE);
$mock = $this->getMock('Solarium\Core\Client\Client', array('createRequest','executeRequest','createResult'));
......@@ -773,6 +790,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo($expectedEvent));
$mock->getEventDispatcher()->addListener(Events::POST_EXECUTE, array($observer, 'postExecute'));
$expectedEvent->setDispatcher($mock->getEventDispatcher());
$mock->execute($query);
}
......@@ -782,6 +803,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$response = new Response('',array('HTTP 1.0 200 OK'));
$expectedResult = new Result($this->client, $query, $response);
$expectedEvent = new PreExecuteEvent($query);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::PRE_EXECUTE);
$test = $this;
$this->client->getEventDispatcher()->addListener(
......@@ -826,6 +849,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$endpoint = $this->client->createEndpoint('s1');
$response = new Response('',array('HTTP 1.0 200 OK'));
$expectedEvent = new PreExecuteRequestEvent($request, $endpoint);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::PRE_EXECUTE_REQUEST);
$mockAdapter = $this->getMock('Solarium\Core\Client\Adapter\Http', array('execute'));
$mockAdapter->expects($this->once())
......@@ -849,6 +874,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$endpoint = $this->client->createEndpoint('s1');
$response = new Response('',array('HTTP 1.0 200 OK'));
$expectedEvent = new PostExecuteRequestEvent($request, $endpoint, $response);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::POST_EXECUTE_REQUEST);
$mockAdapter = $this->getMock('Solarium\Core\Client\Adapter\Http', array('execute'));
$mockAdapter->expects($this->any())
......@@ -872,6 +899,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$response = new Response('',array('HTTP 1.0 200 OK'));
$endpoint = $this->client->createEndpoint('s1');
$expectedEvent = new PreExecuteRequestEvent($request, $endpoint);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::PRE_EXECUTE_REQUEST);
$test = $this;
$this->client->getEventDispatcher()->addListener(
......@@ -1020,6 +1049,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$type = Client::QUERY_SELECT;
$options = array('optionA' => 1, 'optionB' => 2);
$expectedEvent = new PreCreateQueryEvent($type, $options);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::PRE_CREATE_QUERY);
$observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('preCreateQuery'));
$observer->expects($this->once())
......@@ -1037,6 +1068,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$expectedQuery = new SelectQuery();
$expectedQuery->setQuery('test789');
$expectedEvent = new PreCreateQueryEvent($type, $options);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::PRE_CREATE_QUERY);
$test = $this;
$this->client->getEventDispatcher()->addListener(
......@@ -1061,6 +1094,8 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$options = array('optionA' => 1, 'optionB' => 2);
$query = $this->client->createQuery($type, $options);
$expectedEvent = new PostCreateQueryEvent($type, $options, $query);
$expectedEvent->setDispatcher($this->client->getEventDispatcher());
$expectedEvent->setName(Events::POST_CREATE_QUERY);
$observer = $this->getMock('Solarium\Core\Plugin\Plugin', array('postCreateQuery'));
$observer->expects($this->once())
......
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