public function testPluginIntegration() { $client = new Client(); $client->registerPlugin('testplugin', $this->plugin); $input = array('key' => 'xid', 'type' => 'param', 'name' => 'xid', 'value' => 123); $this->plugin->addCustomization($input); $originalRequest = new Request(); $expectedRequest = new Request(); $expectedRequest->addParam('xid', 123); // this should be the effect of the customization $observer = $this->getMock('Solarium\\Core\\Client\\Adapter\\Http', array('execute')); $observer->expects($this->once())->method('execute')->with($this->equalTo($expectedRequest))->will($this->returnValue(new Response('', array('HTTP 1.0 200 OK')))); $client->setAdapter($observer); $client->executeRequest($originalRequest); }
public function testExecuteRequestPostPlugin() { $request = new Request(); $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())->method('execute')->with($this->equalTo($request))->will($this->returnValue($response)); $this->client->setAdapter($mockAdapter); $observer = $this->getMock('Solarium\\Core\\Plugin\\Plugin', array('postExecuteRequest')); $observer->expects($this->once())->method('postExecuteRequest')->with($this->equalTo($expectedEvent)); $this->client->getEventDispatcher()->addListener(Events::POST_EXECUTE_REQUEST, array($observer, 'postExecuteRequest')); $this->client->executeRequest($request, $endpoint); }
public function testFailoverMaxRetries() { $this->plugin = new TestLoadbalancer(); // special loadbalancer that returns endpoints in fixed order $adapter = new TestAdapterForFailover(); $adapter->setFailCount(10); $this->client->setAdapter($adapter); // set special mock that fails for all endpoints $this->plugin->initPlugin($this->client, array()); $request = new Request(); $endpoints = array('server1' => 1, 'server2' => 1); $this->plugin->setEndpoints($endpoints); $this->plugin->setFailoverEnabled(true); $query = new SelectQuery(); $event = new PreCreateRequestEvent($query); $this->plugin->preCreateRequest($event); $this->setExpectedException('Solarium\\Exception\\RuntimeException', 'Maximum number of loadbalancer retries reached'); $event = new PreExecuteRequestEvent($request, new Endpoint()); $this->plugin->preExecuteRequest($event); }