diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ff55bf10..6b2d01dbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Option `buildAll` for Suggesters +- NoWaitForResponseRequest Plugin + ### Fixed - PHP 8.2 deprecations for Solarium\QueryType\Server\Collections results diff --git a/docs/plugins.md b/docs/plugins.md index ce9ccffd8..dcba2a9bd 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -439,6 +439,36 @@ htmlFooter(); ``` +NoWaitForResponseRequest plugin +------------------------------- + +Long-running requests like suggest.buildAll might exceed timeouts. This plugin "tries" to convert the request in a kind of fire-and-forget and doesn't wait for Solr's response. Most reliable if the [cURL client adapter](client-and-adapters.md#curl-adapter) is used. + +```php +createSuggester(); +$suggester->setBuildAll(true); + +// don't wait until all suggesters have been built +$plugin = $client->getPlugin('nowaitforresponserequest'); + +// this executes the query without waiting for the response +$client->suggester($suggester); + +// don't forget to remove the plugin again if you do need the response from further requests +$client->removePlugin($plugin); + +htmlFooter(); +``` + ParallelExecution plugin ------------------------ diff --git a/examples/7.9-plugin-nowaitforresponserequest.php b/examples/7.9-plugin-nowaitforresponserequest.php new file mode 100644 index 000000000..3eb58a4a3 --- /dev/null +++ b/examples/7.9-plugin-nowaitforresponserequest.php @@ -0,0 +1,22 @@ +createSuggester(); +$suggester->setBuildAll(true); + +// don't wait until all suggesters have been built +$plugin = $client->getPlugin('nowaitforresponserequest'); + +// this executes the query without waiting for the response +$client->suggester($suggester); + +// don't forget to remove the plugin again if you do need the response from further requests +$client->removePlugin($plugin); + +htmlFooter(); diff --git a/examples/execute_all.php b/examples/execute_all.php index 025b57325..b6f04275d 100644 --- a/examples/execute_all.php +++ b/examples/execute_all.php @@ -163,6 +163,7 @@ '7.5.3.2-plugin-bufferedupdate-lite-benchmarks-xml.php', // takes too long for a workflow, can be run manually '7.5.3.3-plugin-bufferedupdate-benchmarks-json.php', // takes too long for a workflow, can be run manually '7.5.3.4-plugin-bufferedupdate-lite-benchmarks-json.php', // takes too long for a workflow, can be run manually + '7.9-plugin-nowaitforresponserequest.php', // there is no default suggester included with techproducts ]; // examples that can't be run against this Solr version diff --git a/examples/index.html b/examples/index.html index 1528fdc86..daca913d6 100644 --- a/examples/index.html +++ b/examples/index.html @@ -213,6 +213,7 @@

Examples

  • 7.7.1 Minimum score filter for select queries using grouping
  • 7.8 Post Big Extract Requests
  • +
  • 7.9 No Wait For Response Request
  • diff --git a/src/Component/ComponentTraits/SuggesterTrait.php b/src/Component/ComponentTraits/SuggesterTrait.php index 773745c73..3a90e76f4 100644 --- a/src/Component/ComponentTraits/SuggesterTrait.php +++ b/src/Component/ComponentTraits/SuggesterTrait.php @@ -135,4 +135,26 @@ public function getReload(): ?bool { return $this->getOption('reload'); } + + /** + * Set buildAll option. + * + * @param bool $buildAll + * + * @return SuggesterInterface Provides fluent interface + */ + public function setBuildAll(bool $buildAll): SuggesterInterface + { + return $this->setOption('buildAll', $buildAll); + } + + /** + * Get buildAll option. + * + * @return bool|null + */ + public function getBuildAll(): ?bool + { + return $this->getOption('buildAll'); + } } diff --git a/src/Component/SuggesterInterface.php b/src/Component/SuggesterInterface.php index 0df0fd575..9e8b7db93 100644 --- a/src/Component/SuggesterInterface.php +++ b/src/Component/SuggesterInterface.php @@ -108,4 +108,20 @@ public function setReload(bool $reload): self; * @return bool|null */ public function getReload(): ?bool; + + /** + * Set buildAll option. + * + * @param bool $buildAll + * + * @return self Provides fluent interface + */ + public function setBuildAll(bool $buildAll): self; + + /** + * Get buildAll option. + * + * @return bool|null + */ + public function getBuildAll(): ?bool; } diff --git a/src/Core/Client/Adapter/Curl.php b/src/Core/Client/Adapter/Curl.php index c64106b17..c8b25addc 100644 --- a/src/Core/Client/Adapter/Curl.php +++ b/src/Core/Client/Adapter/Curl.php @@ -54,7 +54,10 @@ public function execute(Request $request, Endpoint $endpoint): Response public function getResponse(\CurlHandle $handle, $httpResponse): Response { if (CURLE_OK !== curl_errno($handle)) { - throw new HttpException(sprintf('HTTP request failed, %s', curl_error($handle))); + $errno = curl_errno($handle); + $error = curl_error($handle); + curl_close($handle); + throw new HttpException(sprintf('HTTP request failed, %s', $error), $errno); } $httpCode = curl_getinfo($handle, CURLINFO_RESPONSE_CODE); @@ -85,7 +88,7 @@ public function createHandle(Request $request, Endpoint $endpoint): \CurlHandle $handler = curl_init(); curl_setopt($handler, CURLOPT_URL, $uri); - curl_setopt($handler, CURLOPT_RETURNTRANSFER, true); + curl_setopt($handler, CURLOPT_RETURNTRANSFER, $options['return_transfer']); if (!(\function_exists('ini_get') && ini_get('open_basedir'))) { curl_setopt($handler, CURLOPT_FOLLOWLOCATION, true); } @@ -211,10 +214,11 @@ protected function init() */ protected function createOptions(Request $request, Endpoint $endpoint): array { - $options = [ + $options = $this->options + [ 'timeout' => $this->timeout, 'connection_timeout' => $this->connectionTimeout ?? $this->timeout, 'proxy' => $this->proxy, + 'return_transfer' => true, ]; foreach ($request->getHeaders() as $headerLine) { list($header, $value) = explode(':', $headerLine); diff --git a/src/Core/Client/Adapter/TimeoutAwareInterface.php b/src/Core/Client/Adapter/TimeoutAwareInterface.php index 510ade592..9402cfee1 100644 --- a/src/Core/Client/Adapter/TimeoutAwareInterface.php +++ b/src/Core/Client/Adapter/TimeoutAwareInterface.php @@ -21,6 +21,13 @@ interface TimeoutAwareInterface */ public const DEFAULT_TIMEOUT = 5; + /** + * Fast timeout that should be used if the client should not wait for the result. + * + * @see \Solarium\Plugin\NoWaitForResponseRequest + */ + public const FAST_TIMEOUT = 1; + /** * @param int $timeoutInSeconds * diff --git a/src/Core/Client/Client.php b/src/Core/Client/Client.php index 254a4c671..b982f186f 100755 --- a/src/Core/Client/Client.php +++ b/src/Core/Client/Client.php @@ -36,6 +36,7 @@ use Solarium\Plugin\CustomizeRequest\CustomizeRequest; use Solarium\Plugin\Loadbalancer\Loadbalancer; use Solarium\Plugin\MinimumScoreFilter\MinimumScoreFilter; +use Solarium\Plugin\NoWaitForResponseRequest; use Solarium\Plugin\ParallelExecution\ParallelExecution; use Solarium\Plugin\PostBigExtractRequest; use Solarium\Plugin\PostBigRequest; @@ -243,6 +244,7 @@ class Client extends Configurable implements ClientInterface */ protected $pluginTypes = [ 'loadbalancer' => Loadbalancer::class, + 'nowaitforresponserequest' => NoWaitForResponseRequest::class, 'postbigrequest' => PostBigRequest::class, 'postbigextractrequest' => PostBigExtractRequest::class, 'customizerequest' => CustomizeRequest::class, diff --git a/src/Plugin/NoWaitForResponseRequest.php b/src/Plugin/NoWaitForResponseRequest.php new file mode 100644 index 000000000..bbd33391c --- /dev/null +++ b/src/Plugin/NoWaitForResponseRequest.php @@ -0,0 +1,145 @@ +getRequest(); + $queryString = $request->getQueryString(); + + if (Request::METHOD_GET === $request->getMethod()) { + // GET requests usually expect a result. Since the purpose of this + // plugin is to trigger a long-running command and to not wait for + // its result, POST is the correct method. + // Depending on the HTTP configuration, GET requests could be + // cached. If this plugin is used, someone usually wants to build a + // dictionary or suggester and caching has to be avoided. Even if + // Solr accepts GET requests for these tasks, POST is the correct + // method. + $charset = $request->getParam('ie') ?? 'utf-8'; + $request->setMethod(Request::METHOD_POST); + $request->setContentType(Request::CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED, ['charset' => $charset]); + $request->setRawData($queryString); + $request->clearParams(); + } + + $timeout = TimeoutAwareInterface::DEFAULT_TIMEOUT; + if ($this->client->getAdapter() instanceof TimeoutAwareInterface) { + $timeout = $this->client->getAdapter()->getTimeout(); + if (($this->client->getAdapter() instanceof ConnectionTimeoutAwareInterface) && ($this->client->getAdapter()->getConnectionTimeout() > 0)) { + $this->client->getAdapter()->setTimeout($this->client->getAdapter()->getConnectionTimeout() + TimeoutAwareInterface::FAST_TIMEOUT); + } else { + $this->client->getAdapter()->setTimeout(TimeoutAwareInterface::FAST_TIMEOUT); + } + } + + if ($this->client->getAdapter() instanceof Curl) { + $this->client->getAdapter()->setOption('return_transfer', false); + } + + $exception = null; + $microtime1 = microtime(true); + try { + $this->client->getAdapter()->execute($request, $event->getEndpoint()); + } catch (HttpException $e) { + // We expect to run into a timeout. + $microtime2 = microtime(true); + + if (($this->client->getAdapter() instanceof Curl) && (CURLE_OPERATION_TIMEDOUT != $e->getCode())) { + // An unexpected exception occurred. + $exception = $e; + } else { + $time_passed = $microtime2 - $microtime1; + if (($this->client->getAdapter() instanceof ConnectionTimeoutAwareInterface) && ($time_passed > $this->client->getAdapter()->getConnectionTimeout()) && ($time_passed < ($this->client->getAdapter()->getConnectionTimeout() + TimeoutAwareInterface::FAST_TIMEOUT))) { + // A connection timeout occurred, so the POST request has not been sent. + $exception = $e; + } + } + } catch (\Exception $exception) { + // Throw this exception after resetting the adapter. + } + + if ($this->client->getAdapter() instanceof TimeoutAwareInterface) { + // Restore the previous timeout. + $this->client->getAdapter()->setTimeout($timeout); + } + + if ($this->client->getAdapter() instanceof Curl) { + $this->client->getAdapter()->setOption('return_transfer', true); + } + + if ($exception) { + throw $exception; + } + + $response = new Response('', ['HTTP/1.0 200 OK']); + $event->setResponse($response); + + return $this; + } + + /** + * Plugin init function. + * + * Register event listeners. + */ + protected function initPluginType() + { + $dispatcher = $this->client->getEventDispatcher(); + if (is_subclass_of($dispatcher, '\Symfony\Component\EventDispatcher\EventDispatcherInterface')) { + // NoWaitForResponseRequest has to act on PRE_EXECUTE_REQUEST before Loadbalancer (priority 0) + // and after PostBigRequest (priority 10). Set priority to 5. + $dispatcher->addListener(Events::PRE_EXECUTE_REQUEST, [$this, 'preExecuteRequest'], 5); + } + } + + /** + * Plugin cleanup function. + * + * Unregister event listeners. + */ + public function deinitPlugin() + { + $dispatcher = $this->client->getEventDispatcher(); + if (is_subclass_of($dispatcher, '\Symfony\Component\EventDispatcher\EventDispatcherInterface')) { + $dispatcher->removeListener(Events::PRE_EXECUTE_REQUEST, [$this, 'preExecuteRequest']); + } + } +} diff --git a/src/QueryType/Suggester/Query.php b/src/QueryType/Suggester/Query.php index 7f159ddad..8b2778edf 100644 --- a/src/QueryType/Suggester/Query.php +++ b/src/QueryType/Suggester/Query.php @@ -46,6 +46,7 @@ class Query extends BaseQuery implements SuggesterInterface, QueryInterface 'omitheader' => true, 'build' => false, 'reload' => false, + 'buildAll' => false, ]; /** diff --git a/tests/Core/Client/Adapter/HttpTest.php b/tests/Core/Client/Adapter/HttpTest.php index ada5341df..9b31052dd 100644 --- a/tests/Core/Client/Adapter/HttpTest.php +++ b/tests/Core/Client/Adapter/HttpTest.php @@ -41,7 +41,7 @@ public function testExecute() $mock->expects($this->once()) ->method('getData') ->with($this->equalTo('http://127.0.0.1:8983/solr/'), $this->isType('resource')) - ->willReturn([$data, ['HTTP 1.1 200 OK']]); + ->willReturn([$data, ['HTTP/1.1 200 OK']]); $mock->execute($request, $endpoint); } diff --git a/tests/Core/Client/ClientTest.php b/tests/Core/Client/ClientTest.php index 2cff6470c..d44a360e8 100644 --- a/tests/Core/Client/ClientTest.php +++ b/tests/Core/Client/ClientTest.php @@ -595,7 +595,7 @@ function (PreCreateRequestEvent $event) use ($test, $expectedRequest, $expectedE public function testCreateResult() { $query = new SelectQuery(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = $this->client->createResult($query, $response); $this->assertThat( @@ -607,7 +607,7 @@ public function testCreateResult() public function testCreateResultPrePlugin() { $query = new SelectQuery(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $expectedEvent = new PreCreateResultEvent($query, $response); if (method_exists($expectedEvent, 'setDispatcher')) { $expectedEvent->setDispatcher($this->client->getEventDispatcher()); @@ -634,7 +634,7 @@ public function testCreateResultPrePlugin() public function testCreateResultPostPlugin() { $query = new SelectQuery(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = $this->client->createResult($query, $response); $expectedEvent = new PostCreateResultEvent($query, $response, $result); if (method_exists($expectedEvent, 'setDispatcher')) { @@ -661,7 +661,7 @@ public function testCreateResultPostPlugin() public function testCreateResultWithOverridingPlugin() { $query = new SelectQuery(); - $response = new Response('test 1234', ['HTTP 1.0 200 OK']); + $response = new Response('test 1234', ['HTTP/1.0 200 OK']); $expectedEvent = new PreCreateResultEvent($query, $response); if (method_exists($expectedEvent, 'setDispatcher')) { $expectedEvent->setDispatcher($this->client->getEventDispatcher()); @@ -690,7 +690,7 @@ public function testCreateResultWithInvalidResultClass() { $query = new SelectQuery(); $query->setResultClass(\stdClass::class); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('Result class must implement the ResultInterface'); @@ -701,7 +701,7 @@ public function testExecute() { $query = new PingQuery(); $request = new Request(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = new Result($query, $response); $observer = $this->getMockBuilder(Client::class) @@ -730,7 +730,7 @@ public function testExecute() public function testExecutePrePlugin() { $query = new PingQuery(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = new Result($query, $response); $expectedEvent = new PreExecuteEvent($query); @@ -772,7 +772,7 @@ public function testExecutePrePlugin() public function testExecutePostPlugin() { $query = new PingQuery(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = new Result($query, $response); $expectedEvent = new PostExecuteEvent($query, $result); @@ -814,7 +814,7 @@ public function testExecutePostPlugin() public function testExecuteWithOverridingPlugin() { $query = new PingQuery(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $expectedResult = new Result($query, $response); $expectedEvent = new PreExecuteEvent($query); if (method_exists($expectedEvent, 'setDispatcher')) { @@ -842,7 +842,7 @@ function (PreExecuteEvent $event) use ($test, $expectedResult, $expectedEvent) { public function testExecuteRequest() { $request = new Request(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $observer = $this->getMockBuilder(Http::class) ->onlyMethods(['execute']) @@ -865,7 +865,7 @@ public function testExecuteRequestPrePlugin() { $request = new Request(); $endpoint = $this->client->createEndpoint('s1'); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $expectedEvent = new PreExecuteRequestEvent($request, $endpoint); if (method_exists($expectedEvent, 'setDispatcher')) { $expectedEvent->setDispatcher($this->client->getEventDispatcher()); @@ -900,7 +900,7 @@ public function testExecuteRequestPostPlugin() { $request = new Request(); $endpoint = $this->client->createEndpoint('s1'); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $expectedEvent = new PostExecuteRequestEvent($request, $endpoint, $response); if (method_exists($expectedEvent, 'setDispatcher')) { $expectedEvent->setDispatcher($this->client->getEventDispatcher()); @@ -934,7 +934,7 @@ public function testExecuteRequestPostPlugin() public function testExecuteRequestWithOverridingPlugin() { $request = new Request(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $endpoint = $this->client->createEndpoint('s1'); $expectedEvent = new PreExecuteRequestEvent($request, $endpoint); if (method_exists($expectedEvent, 'setDispatcher')) { @@ -970,7 +970,7 @@ public function testPing() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\Ping\Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\Ping\Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->ping($query); } @@ -986,7 +986,7 @@ public function testSelect() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\Select\Result\Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\Select\Result\Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->select($query); } @@ -1002,7 +1002,7 @@ public function testUpdate() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\Update\Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\Update\Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->update($query); } @@ -1018,7 +1018,7 @@ public function testMoreLikeThis() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\MoreLikeThis\Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\MoreLikeThis\Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->moreLikeThis($query); } @@ -1034,7 +1034,7 @@ public function testAnalyze() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->analyze($query); } @@ -1050,7 +1050,7 @@ public function testTerms() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\Terms\Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\Terms\Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->terms($query); } @@ -1066,7 +1066,7 @@ public function testSpellcheck() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\Spellcheck\Result\Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\Spellcheck\Result\Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->spellcheck($query); } @@ -1082,7 +1082,7 @@ public function testSuggester() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\Suggester\Result\Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\Suggester\Result\Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->suggester($query); } @@ -1098,7 +1098,7 @@ public function testExtract() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\Extract\Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\Extract\Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->extract($query); } @@ -1114,7 +1114,7 @@ public function testRealtimeGet() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\RealtimeGet\Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\RealtimeGet\Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->realtimeGet($query); } @@ -1130,7 +1130,7 @@ public function testLuke() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\Luke\Result\Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\Luke\Result\Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->luke($query); } @@ -1146,7 +1146,7 @@ public function testCoreAdmin() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\Server\CoreAdmin\Result\Result($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\Server\CoreAdmin\Result\Result($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->coreAdmin($query); } @@ -1162,7 +1162,7 @@ public function testCollections() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\Server\Collections\Result\ClusterStatusResult($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\Server\Collections\Result\ClusterStatusResult($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->collections($query); } @@ -1178,7 +1178,7 @@ public function testConfigsets() $observer->expects($this->once()) ->method('execute') ->with($this->equalTo($query)) - ->willReturn(new \Solarium\QueryType\Server\Configsets\Result\ConfigsetsResult($query, new Response('dummyresponse', ['HTTP 1.0 200 OK']))); + ->willReturn(new \Solarium\QueryType\Server\Configsets\Result\ConfigsetsResult($query, new Response('dummyresponse', ['HTTP/1.0 200 OK']))); $observer->configsets($query); } diff --git a/tests/Core/Event/PostCreateResultTest.php b/tests/Core/Event/PostCreateResultTest.php index a20c3eafc..89eccebdc 100644 --- a/tests/Core/Event/PostCreateResultTest.php +++ b/tests/Core/Event/PostCreateResultTest.php @@ -15,7 +15,7 @@ public function testConstructorAndGetters() $client = TestClientFactory::createWithCurlAdapter(); $query = $client->createSelect(); $query->setQuery('test123'); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = new Result($query, $response); $event = new PostCreateResult($query, $response, $result); diff --git a/tests/Core/Event/PostExecuteRequestTest.php b/tests/Core/Event/PostExecuteRequestTest.php index ac805827e..82520ccf8 100644 --- a/tests/Core/Event/PostExecuteRequestTest.php +++ b/tests/Core/Event/PostExecuteRequestTest.php @@ -16,7 +16,7 @@ public function testConstructorAndGetters() $request = new Request(); $request->addParam('testparam', 'test value'); $endpoint = $client->getEndpoint(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $event = new PostExecuteRequest($request, $endpoint, $response); diff --git a/tests/Core/Event/PostExecuteTest.php b/tests/Core/Event/PostExecuteTest.php index 9cd4e8193..f3581589d 100644 --- a/tests/Core/Event/PostExecuteTest.php +++ b/tests/Core/Event/PostExecuteTest.php @@ -15,7 +15,7 @@ public function testConstructorAndGetters() $client = TestClientFactory::createWithCurlAdapter(); $query = $client->createSelect(); $query->setQuery('test123'); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = new Result($query, $response); $event = new PostExecute($query, $result); diff --git a/tests/Core/Event/PreCreateResultTest.php b/tests/Core/Event/PreCreateResultTest.php index 3a9081746..41e98302a 100644 --- a/tests/Core/Event/PreCreateResultTest.php +++ b/tests/Core/Event/PreCreateResultTest.php @@ -15,7 +15,7 @@ public function testConstructorAndGetters() $client = TestClientFactory::createWithCurlAdapter(); $query = $client->createSelect(); $query->setQuery('test123'); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $event = new PreCreateResult($query, $response); @@ -35,7 +35,7 @@ public function testSetAndGetResult($event) $client = TestClientFactory::createWithCurlAdapter(); $query = $client->createSelect(); $query->setQuery('test123'); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = new Result($query, $response); $event->setResult($result); diff --git a/tests/Core/Event/PreExecuteRequestTest.php b/tests/Core/Event/PreExecuteRequestTest.php index 4626b5468..06a632f5b 100644 --- a/tests/Core/Event/PreExecuteRequestTest.php +++ b/tests/Core/Event/PreExecuteRequestTest.php @@ -46,7 +46,7 @@ public function testSetAndGetRequest($event) */ public function testSetAndGetResponse($event) { - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $event->setResponse($response); $this->assertSame($response, $event->getResponse()); } diff --git a/tests/Core/Event/PreExecuteTest.php b/tests/Core/Event/PreExecuteTest.php index 05c681f8e..ce1da4136 100644 --- a/tests/Core/Event/PreExecuteTest.php +++ b/tests/Core/Event/PreExecuteTest.php @@ -33,7 +33,7 @@ public function testSetAndGetResult($event) $client = TestClientFactory::createWithCurlAdapter(); $query = $client->createSelect(); $query->setQuery('test123'); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = new Result($query, $response); $event->setResult($result); diff --git a/tests/Core/Query/Result/QueryTypeTest.php b/tests/Core/Query/Result/QueryTypeTest.php index 8e4cb36cb..f382b3aa2 100644 --- a/tests/Core/Query/Result/QueryTypeTest.php +++ b/tests/Core/Query/Result/QueryTypeTest.php @@ -20,7 +20,7 @@ class QueryTypeTest extends TestCase public function setUp(): void { $query = new UpdateQuery(); - $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP 1.1 200 OK']); + $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP/1.1 200 OK']); $this->result = new TestStubResult($query, $response); } @@ -37,7 +37,7 @@ public function testGetQueryTime() public function testParseResponse() { $query = new TestStubQuery(); - $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP 1.1 200 OK']); + $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP/1.1 200 OK']); $result = new TestStubResult($query, $response); $this->expectException(UnexpectedValueException::class); @@ -52,7 +52,7 @@ public function testParseResponseInvalidQuerytype() public function testParseResponseResponseHeaderFallback() { $query = new SelectQuery(); - $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP 1.1 200 OK']); + $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP/1.1 200 OK']); $result = new TestNonDataMappingStubResult($query, $response); $this->assertSame(1, $result->getStatus()); diff --git a/tests/Integration/AbstractTechproductsTestCase.php b/tests/Integration/AbstractTechproductsTestCase.php index 5a3bb29aa..86d3f93e2 100644 --- a/tests/Integration/AbstractTechproductsTestCase.php +++ b/tests/Integration/AbstractTechproductsTestCase.php @@ -14,7 +14,9 @@ use Solarium\Component\Result\Grouping\Result as GroupingResult; use Solarium\Component\Result\Grouping\ValueGroup; use Solarium\Component\Result\Terms\Result as TermsResult; +use Solarium\Core\Client\Adapter\ConnectionTimeoutAwareInterface; use Solarium\Core\Client\Adapter\Curl; +use Solarium\Core\Client\Adapter\TimeoutAwareInterface; use Solarium\Core\Client\ClientInterface; use Solarium\Core\Client\Request; use Solarium\Core\Client\Response; @@ -1398,6 +1400,35 @@ public function testSuggester(string $responseWriter) $this->assertContains('electronics and stuff2', $phrases); } + public function testSuggesterBuildAll() + { + $adapter = self::$client->getAdapter(); + $timeout = $adapter instanceof TimeoutAwareInterface ? $adapter->getTimeout() : 0; + $connection_timeout = $adapter instanceof ConnectionTimeoutAwareInterface ? $adapter->getConnectionTimeout() : 0; + $suggester = self::$client->createSuggester(); + // The techproducts example doesn't provide a default suggester, but 'mySuggester'. + $suggester->setDictionary('mySuggester'); + $suggester->setBuildAll(true); + $plugin = self::$client->getPlugin('nowaitforresponserequest'); + $time = time(); + $result = self::$client->suggester($suggester); + if ($adapter instanceof TimeoutAwareInterface) { + $this->assertTrue((time() - $time) < (TimeoutAwareInterface::FAST_TIMEOUT + $connection_timeout + 1)); + } + $this->assertSame(200, $result->getResponse()->getStatusCode()); + + self::$client->removePlugin($plugin); + + // The client should be configured with previous settings again, after + // these settings have been changed within the plugin. + if ($adapter instanceof TimeoutAwareInterface) { + $this->assertSame($timeout, $adapter->getTimeout()); + if ($adapter instanceof Curl) { + $this->assertTrue(self::$client->getAdapter()->getOption('return_transfer')); + } + } + } + /** * @dataProvider responseWriterProvider */ @@ -3879,7 +3910,7 @@ public function testParallelExecution() 'maxScore' => 1.00, ], ]; - $responseOverrideResult = new Response(json_encode($dataOverrideResult), ['HTTP 1.0 200 OK']); + $responseOverrideResult = new Response(json_encode($dataOverrideResult), ['HTTP/1.0 200 OK']); $dataOverrideResponse = [ 'response' => [ @@ -3890,7 +3921,7 @@ public function testParallelExecution() 'maxScore' => 1.00, ], ]; - $responseOverrideResponse = new Response(json_encode($dataOverrideResponse), ['HTTP 1.0 200 OK']); + $responseOverrideResponse = new Response(json_encode($dataOverrideResponse), ['HTTP/1.0 200 OK']); $resultInStock = self::$client->select($queryInStock); $resultLowPrice = self::$client->select($queryLowPrice); diff --git a/tests/Plugin/BufferedAdd/Event/PostCommitTest.php b/tests/Plugin/BufferedAdd/Event/PostCommitTest.php index 8b8421384..5b156371e 100644 --- a/tests/Plugin/BufferedAdd/Event/PostCommitTest.php +++ b/tests/Plugin/BufferedAdd/Event/PostCommitTest.php @@ -14,7 +14,7 @@ public function testConstructorAndGetter() { $client = TestClientFactory::createWithCurlAdapter(); $query = $client->createUpdate(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = new Result($query, $response); $event = new PostCommit($result); diff --git a/tests/Plugin/BufferedAdd/Event/PostFlushTest.php b/tests/Plugin/BufferedAdd/Event/PostFlushTest.php index 6684ef35e..5ba54c759 100644 --- a/tests/Plugin/BufferedAdd/Event/PostFlushTest.php +++ b/tests/Plugin/BufferedAdd/Event/PostFlushTest.php @@ -14,7 +14,7 @@ public function testConstructorAndGetter() { $client = TestClientFactory::createWithCurlAdapter(); $query = $client->createUpdate(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = new Result($query, $response); $event = new PostFlush($result); diff --git a/tests/Plugin/BufferedDelete/Event/PostCommitTest.php b/tests/Plugin/BufferedDelete/Event/PostCommitTest.php index 982f5dbcc..f74380417 100644 --- a/tests/Plugin/BufferedDelete/Event/PostCommitTest.php +++ b/tests/Plugin/BufferedDelete/Event/PostCommitTest.php @@ -14,7 +14,7 @@ public function testConstructorAndGetter() { $client = TestClientFactory::createWithCurlAdapter(); $query = $client->createUpdate(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = new Result($query, $response); $event = new PostCommit($result); diff --git a/tests/Plugin/BufferedDelete/Event/PostFlushTest.php b/tests/Plugin/BufferedDelete/Event/PostFlushTest.php index 5b90c632d..51e7c4f39 100644 --- a/tests/Plugin/BufferedDelete/Event/PostFlushTest.php +++ b/tests/Plugin/BufferedDelete/Event/PostFlushTest.php @@ -14,7 +14,7 @@ public function testConstructorAndGetter() { $client = TestClientFactory::createWithCurlAdapter(); $query = $client->createUpdate(); - $response = new Response('', ['HTTP 1.0 200 OK']); + $response = new Response('', ['HTTP/1.0 200 OK']); $result = new Result($query, $response); $event = new PostFlush($result); diff --git a/tests/Plugin/NoWaitForResponseRequestTest.php b/tests/Plugin/NoWaitForResponseRequestTest.php new file mode 100644 index 000000000..8247d48a8 --- /dev/null +++ b/tests/Plugin/NoWaitForResponseRequestTest.php @@ -0,0 +1,198 @@ +client = TestClientFactory::createWithCurlAdapter(); + $this->plugin = $this->client->getPlugin('nowaitforresponserequest'); + $this->query = $this->client->createSuggester(['buildAll' => true]); + } + + public function testInitPlugin(): Client + { + $client = TestClientFactory::createWithCurlAdapter(); + $plugin = $client->getPlugin('nowaitforresponserequest'); + + $this->assertInstanceOf(NoWaitForResponseRequest::class, $plugin); + + $expectedListeners = [ + Events::PRE_EXECUTE_REQUEST => [ + [ + $plugin, + 'preExecuteRequest', + ], + ], + ]; + + $this->assertSame( + $expectedListeners, + $client->getEventDispatcher()->getListeners() + ); + + return $client; + } + + /** + * @depends testInitPlugin + */ + public function testDeinitPlugin(Client $client) + { + $client->removePlugin('nowaitforresponserequest'); + + $this->assertSame( + [], + $client->getEventDispatcher()->getListeners() + ); + } + + public function testExecuteRequest() + { + $requestOutput = $this->client->createRequest($this->query); + $requestInput = clone $requestOutput; + $endpoint = $this->client->getEndpoint(); + $endpoint->setCore('my_core'); + $event = new PreExecuteRequestEvent($requestOutput, $endpoint); + $this->plugin->preExecuteRequest($event); + $response = $event->getResponse(); + + $this->assertSame(Request::METHOD_GET, $requestInput->getMethod()); + $this->assertSame(Request::METHOD_POST, $requestOutput->getMethod()); + $this->assertSame(Request::CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED, $requestOutput->getContentType()); + $this->assertSame($requestInput->getQueryString(), $requestOutput->getRawData()); + $this->assertSame('', $requestOutput->getQueryString()); + $this->assertSame(200, $response->getStatusCode()); + + // The client should be configured with defaults again, after these + // settings changed within the event subscriber. + $this->assertSame(TimeoutAwareInterface::DEFAULT_TIMEOUT, $this->client->getAdapter()->getTimeout()); + $this->assertTrue($this->client->getAdapter()->getOption('return_transfer')); + } + + public function testSetFastTimeout() + { + $observer = new class() extends Http { + public $newTimeout; + + public function setTimeout(int $timeoutInSeconds): self + { + if (!isset($this->newTimeout)) { + $this->newTimeout = $timeoutInSeconds; + } + + return parent::setTimeout($timeoutInSeconds); + } + }; + $this->client->setAdapter($observer); + + $requestOutput = $this->client->createRequest($this->query); + $endpoint = $this->client->getEndpoint(); + $endpoint->setCore('my_core'); + $event = new PreExecuteRequestEvent($requestOutput, $endpoint); + $this->plugin->preExecuteRequest($event); + + $this->assertSame(TimeoutAwareInterface::FAST_TIMEOUT, $observer->newTimeout); + } + + public function testSetFastTimeoutWithConnectionTimeout() + { + $observer = new class() extends Curl { + public $newTimeout; + + public function setTimeout(int $timeoutInSeconds): self + { + if (!isset($this->newTimeout)) { + $this->newTimeout = $timeoutInSeconds; + } + + return parent::setTimeout($timeoutInSeconds); + } + }; + $observer->setConnectionTimeout(1); + $this->client->setAdapter($observer); + + $requestOutput = $this->client->createRequest($this->query); + $endpoint = $this->client->getEndpoint(); + $endpoint->setCore('my_core'); + $event = new PreExecuteRequestEvent($requestOutput, $endpoint); + $this->plugin->preExecuteRequest($event); + + $this->assertSame(1 + TimeoutAwareInterface::FAST_TIMEOUT, $observer->newTimeout); + } + + public function testUnrelatedHttpExceptionIsRethrown() + { + $requestOutput = $this->client->createRequest($this->query); + $endpoint = $this->client->getEndpoint(); + $event = new PreExecuteRequestEvent($requestOutput, $endpoint); + + // thrown by AdapterHelper::buildUri() because we didn't set a core or collection on the endpoint + $this->expectException(HttpException::class); + $this->expectExceptionCode(404); + $this->plugin->preExecuteRequest($event); + } + + public function testUnrelatedExceptionIsRethrown() + { + $requestOutput = $this->client->createRequest($this->query); + $endpoint = $this->client->getEndpoint(); + $event = new class($requestOutput, $endpoint) extends PreExecuteRequestEvent { + public function getEndpoint(): Endpoint + { + throw new \RuntimeException('', 42); + } + }; + + $this->expectException(\RuntimeException::class); + $this->expectExceptionCode(42); + $this->plugin->preExecuteRequest($event); + } + + public function testPluginIntegration() + { + $client = TestClientFactory::createWithCurlAdapter(); + $plugin = new NoWaitForResponseRequest(); + $client->registerPlugin('testplugin', $plugin); + + $query = $client->createSelect(); + $request = $client->createRequest($query); + $adapter = $this->createMock(AdapterInterface::class); + $client->setAdapter($adapter); + $response = $client->executeRequest($request); + + // default method is GET, the plugin should have changed this to POST + $this->assertSame(Request::METHOD_POST, $request->getMethod()); + } +} diff --git a/tests/QueryType/Luke/Result/ResultTest.php b/tests/QueryType/Luke/Result/ResultTest.php index 56df61e0a..a62e471e5 100644 --- a/tests/QueryType/Luke/Result/ResultTest.php +++ b/tests/QueryType/Luke/Result/ResultTest.php @@ -40,7 +40,7 @@ public function testWithShowAll() 'info' => $this->getInfoData(), ]; - $response = new Response(json_encode($data), ['HTTP 1.1 200 OK']); + $response = new Response(json_encode($data), ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->assertInstanceOf(Index::class, $result->getIndex()); @@ -63,7 +63,7 @@ public function testWithShowIndex() 'index' => $this->getIndexData(), ]; - $response = new Response(json_encode($data), ['HTTP 1.1 200 OK']); + $response = new Response(json_encode($data), ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->assertInstanceOf(Index::class, $result->getIndex()); @@ -88,7 +88,7 @@ public function testWithShowSchema() 'info' => $this->getInfoData(), ]; - $response = new Response(json_encode($data), ['HTTP 1.1 200 OK']); + $response = new Response(json_encode($data), ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->assertInstanceOf(Index::class, $result->getIndex()); @@ -113,7 +113,7 @@ public function testWithShowDocWithoutIdOrDocId() 'info' => $this->getInfoData(), ]; - $response = new Response(json_encode($data), ['HTTP 1.1 200 OK']); + $response = new Response(json_encode($data), ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->assertInstanceOf(Index::class, $result->getIndex()); @@ -139,7 +139,7 @@ public function testWithShowDocWithId() 'info' => $this->getInfoData(), ]; - $response = new Response(json_encode($data), ['HTTP 1.1 200 OK']); + $response = new Response(json_encode($data), ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->assertInstanceOf(Index::class, $result->getIndex()); @@ -165,7 +165,7 @@ public function testWithShowDocWithDocId() 'info' => $this->getInfoData(), ]; - $response = new Response(json_encode($data), ['HTTP 1.1 200 OK']); + $response = new Response(json_encode($data), ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->assertInstanceOf(Index::class, $result->getIndex()); @@ -189,7 +189,7 @@ public function testWithoutShowWithoutIdOrDocId() 'info' => $this->getInfoData(), ]; - $response = new Response(json_encode($data), ['HTTP 1.1 200 OK']); + $response = new Response(json_encode($data), ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->assertInstanceOf(Index::class, $result->getIndex()); @@ -214,7 +214,7 @@ public function testWithoutShowDocWithId() 'info' => $this->getInfoData(), ]; - $response = new Response(json_encode($data), ['HTTP 1.1 200 OK']); + $response = new Response(json_encode($data), ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->assertInstanceOf(Index::class, $result->getIndex()); @@ -239,7 +239,7 @@ public function testWithoutShowDocWithDocId() 'info' => $this->getInfoData(), ]; - $response = new Response(json_encode($data), ['HTTP 1.1 200 OK']); + $response = new Response(json_encode($data), ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->assertInstanceOf(Index::class, $result->getIndex()); @@ -267,7 +267,7 @@ public function testWithUnknownShow() ], ]; - $response = new Response(json_encode($data), ['HTTP 1.1 200 OK']); + $response = new Response(json_encode($data), ['HTTP/1.1 200 OK']); // get around deprecation for creation of dynamic property $result = new class($query, $response) extends Result { /** diff --git a/tests/QueryType/MoreLikeThis/ResultTest.php b/tests/QueryType/MoreLikeThis/ResultTest.php index f7958085f..567edab8c 100644 --- a/tests/QueryType/MoreLikeThis/ResultTest.php +++ b/tests/QueryType/MoreLikeThis/ResultTest.php @@ -15,7 +15,7 @@ public function testGetInterestingTerms() $query = new Query(); $query->setInterestingTerms('list'); - $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP 1.1 200 OK']); + $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->assertEmpty($result->getInterestingTerms()); } @@ -24,7 +24,7 @@ public function testGetInterestingTermsException() { $query = new Query(); $query->setInterestingTerms('none'); - $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP 1.1 200 OK']); + $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->expectException(UnexpectedValueException::class); @@ -36,7 +36,7 @@ public function testGetMatch() { $query = new Query(); $query->setMatchInclude(true); - $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP 1.1 200 OK']); + $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->assertEmpty($result->getMatch()); } @@ -45,7 +45,7 @@ public function testGetMatchException() { $query = new Query(); $query->setMatchInclude(false); - $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP 1.1 200 OK']); + $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP/1.1 200 OK']); $result = new Result($query, $response); $this->expectException(UnexpectedValueException::class); @@ -55,7 +55,7 @@ public function testGetMatchException() public function testGetQuery() { $query = new Query(); - $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP 1.1 200 OK']); + $response = new Response('{"responseHeader":{"status":1,"QTime":12}}', ['HTTP/1.1 200 OK']); $ping = new Result($query, $response); $this->assertSame($query, $ping->getQuery()); } diff --git a/tests/QueryType/Ping/ResponseParserTest.php b/tests/QueryType/Ping/ResponseParserTest.php index d0998efa8..0605b2332 100644 --- a/tests/QueryType/Ping/ResponseParserTest.php +++ b/tests/QueryType/Ping/ResponseParserTest.php @@ -14,7 +14,7 @@ public function testParse() { $data = '{"status":"OK"}'; - $response = new Response($data, ['HTTP 1.1 200 OK']); + $response = new Response($data, ['HTTP/1.1 200 OK']); $result = new Result(new Query(), $response); $parser = new ResponseParser(); $parsed = $parser->parse($result); diff --git a/tests/QueryType/Server/Api/ResponseParserTest.php b/tests/QueryType/Server/Api/ResponseParserTest.php index c080fc2cf..2a7e65627 100644 --- a/tests/QueryType/Server/Api/ResponseParserTest.php +++ b/tests/QueryType/Server/Api/ResponseParserTest.php @@ -25,7 +25,7 @@ public function testParse() } EOT; - $response = new Response($data, ['HTTP 1.1 200 OK']); + $response = new Response($data, ['HTTP/1.1 200 OK']); $result = new Result(new Query(), $response); $parser = new ResponseParser(); $parsed = $parser->parse($result); diff --git a/tests/QueryType/Suggester/QueryTest.php b/tests/QueryType/Suggester/QueryTest.php index 9dd20a448..5640d3f1f 100644 --- a/tests/QueryType/Suggester/QueryTest.php +++ b/tests/QueryType/Suggester/QueryTest.php @@ -101,4 +101,11 @@ public function testSetAndReload() $this->query->setReload(true); $this->assertTrue($this->query->getReload()); } + + public function testSetAndBuildAll() + { + $this->assertFalse($this->query->getBuildAll()); + $this->query->setBuildAll(true); + $this->assertTrue($this->query->getBuildAll()); + } } diff --git a/tests/QueryType/Update/ResponseParserTest.php b/tests/QueryType/Update/ResponseParserTest.php index 93ac03412..48c70439b 100644 --- a/tests/QueryType/Update/ResponseParserTest.php +++ b/tests/QueryType/Update/ResponseParserTest.php @@ -14,7 +14,7 @@ public function testParse() { $data = '{}'; - $response = new Response($data, ['HTTP 1.1 200 OK']); + $response = new Response($data, ['HTTP/1.1 200 OK']); $result = new Result(new Query(), $response); $parser = new ResponseParser(); $parsed = $parser->parse($result);