From 163dfd4e00f92874fcd15c79cefd70661c68d059 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Thu, 23 Aug 2018 14:36:42 +0200 Subject: [PATCH 01/22] PUT request --- src/Core/Client/Adapter/Curl.php | 2 ++ src/Core/Client/Adapter/PeclHttp.php | 3 +++ src/Core/Client/Adapter/Zend2Http.php | 4 ++++ src/Core/Client/Adapter/ZendHttp.php | 4 ++++ src/Core/Client/Request.php | 5 +++++ 5 files changed, 18 insertions(+) diff --git a/src/Core/Client/Adapter/Curl.php b/src/Core/Client/Adapter/Curl.php index a2bb7370f..1f68296b7 100644 --- a/src/Core/Client/Adapter/Curl.php +++ b/src/Core/Client/Adapter/Curl.php @@ -132,6 +132,8 @@ public function createHandle($request, $endpoint) curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'HEAD'); } elseif (Request::METHOD_DELETE == $method) { curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'DELETE'); + } elseif (Request::METHOD_PUT == $method) { + curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'PUT'); } else { throw new InvalidArgumentException("unsupported method: $method"); } diff --git a/src/Core/Client/Adapter/PeclHttp.php b/src/Core/Client/Adapter/PeclHttp.php index c0c01beb6..5ee772b32 100644 --- a/src/Core/Client/Adapter/PeclHttp.php +++ b/src/Core/Client/Adapter/PeclHttp.php @@ -109,6 +109,9 @@ public function toHttpRequest($request, $endpoint) case Request::METHOD_DELETE: $method = HTTP_METH_DELETE; break; + case Request::METHOD_PUT: + $method = HTTP_METH_PUT; + break; default: throw new InvalidArgumentException( 'Unsupported method: '.$request->getMethod() diff --git a/src/Core/Client/Adapter/Zend2Http.php b/src/Core/Client/Adapter/Zend2Http.php index b516ce6da..2ec5736bb 100644 --- a/src/Core/Client/Adapter/Zend2Http.php +++ b/src/Core/Client/Adapter/Zend2Http.php @@ -158,6 +158,10 @@ public function execute($request, $endpoint) $client->setMethod('DELETE'); $client->setParameterGet($request->getParams()); break; + case Request::METHOD_PUT: + $client->setMethod('PUT'); + $client->setParameterGet($request->getParams()); + break; default: throw new OutOfBoundsException('Unsupported method: '.$request->getMethod()); break; diff --git a/src/Core/Client/Adapter/ZendHttp.php b/src/Core/Client/Adapter/ZendHttp.php index 7ccdf1aa4..d828a12b6 100644 --- a/src/Core/Client/Adapter/ZendHttp.php +++ b/src/Core/Client/Adapter/ZendHttp.php @@ -159,6 +159,10 @@ public function execute($request, $endpoint) $client->setMethod(\Zend_Http_Client::DELETE); $client->setParameterGet($request->getParams()); break; + case Request::METHOD_PUT: + $client->setMethod(\Zend_Http_Client::PUT); + $client->setParameterGet($request->getParams()); + break; default: throw new OutOfBoundsException('Unsupported method: '.$request->getMethod()); break; diff --git a/src/Core/Client/Request.php b/src/Core/Client/Request.php index 1131dc801..77f182da1 100644 --- a/src/Core/Client/Request.php +++ b/src/Core/Client/Request.php @@ -34,6 +34,11 @@ class Request extends Configurable implements RequestParamsInterface */ const METHOD_DELETE = 'DELETE'; + /** + * Request PUT method. + */ + const METHOD_PUT = 'PUT'; + /** * Default options. * From b9149eb1a5fc09f0b1c0bf6f635c9c1f91ed2183 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Thu, 23 Aug 2018 14:47:03 +0200 Subject: [PATCH 02/22] Updated CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9e9c6df8..8abdc26c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [master] ### Added +- Basic support for PUT requests in the HttpAdapter layer ### Changed @@ -22,7 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [4.1.0] ### Added - Method AbstractQuery::removeParam() to remove a custom parameter or to reset a required but modified parameter -- Basic support for DELETE requests in the HttpAdapter layer +- Basic support for DELETE and PUT requests in the HttpAdapter layer - Introduced an AdapterHelper class to start unifying implementations across all HTTP adapters From 4c069fdc6522476f0c7918e9b46fee18db98c2ba Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Thu, 23 Aug 2018 14:49:13 +0200 Subject: [PATCH 03/22] Revert "Updated CHANGELOG.md" This reverts commit b9149eb1a5fc09f0b1c0bf6f635c9c1f91ed2183. --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8abdc26c3..b9e9c6df8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [master] ### Added -- Basic support for PUT requests in the HttpAdapter layer ### Changed @@ -23,7 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [4.1.0] ### Added - Method AbstractQuery::removeParam() to remove a custom parameter or to reset a required but modified parameter -- Basic support for DELETE and PUT requests in the HttpAdapter layer +- Basic support for DELETE requests in the HttpAdapter layer - Introduced an AdapterHelper class to start unifying implementations across all HTTP adapters From fd774a9c1b9f7f8412e0e687dc6dec21d3686db3 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Thu, 23 Aug 2018 14:49:55 +0200 Subject: [PATCH 04/22] Updated CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9e9c6df8..070e19541 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [master] ### Added +- Basic support for PUT requests in the HttpAdapter layer ### Changed From 6efe411ca2d6db83c6315810eb08763ff04e2eaa Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Wed, 5 Sep 2018 18:27:04 +0200 Subject: [PATCH 05/22] ManagedResources api for managing stopwords and synonyms. --- src/Core/Client/Client.php | 18 ++ .../ManagedResources/Query/Resources.php | 49 +++++ .../ManagedResources/Query/Stopwords.php | 165 +++++++++++++++ .../Stopwords/Command/AbstractCommand.php | 39 ++++ .../Query/Stopwords/Command/Add.php | 78 ++++++++ .../Query/Stopwords/Command/Delete.php | 69 +++++++ .../Query/Stopwords/Command/Exists.php | 69 +++++++ .../Query/Stopwords/Stopword.php | 31 +++ .../ManagedResources/Query/Synonyms.php | 188 ++++++++++++++++++ .../Synonyms/Command/AbstractCommand.php | 39 ++++ .../Query/Synonyms/Command/Add.php | 84 ++++++++ .../Query/Synonyms/Command/Delete.php | 69 +++++++ .../Query/Synonyms/Command/Exists.php | 69 +++++++ .../Query/Synonyms/Synonyms.php | 57 ++++++ .../RequestBuilder/Resources.php | 9 + .../RequestBuilder/Stopwords.php | 62 ++++++ .../RequestBuilder/Synonyms.php | 63 ++++++ .../ResponseParser/Resources.php | 31 +++ .../ResponseParser/Stopwords.php | 31 +++ .../ResponseParser/Synonyms.php | 31 +++ .../ManagedResources/Result/Resources.php | 10 + .../Result/Resources/Resource.php | 69 +++++++ .../Result/Resources/ResourcesList.php | 71 +++++++ .../ManagedResources/Result/Stopwords.php | 10 + .../Result/Stopwords/ManagedList.php | 29 +++ .../Result/Stopwords/Stopword.php | 9 + .../Result/Stopwords/WordSet.php | 111 +++++++++++ .../ManagedResources/Result/Synonyms.php | 10 + .../Result/Synonyms/ManagedMap.php | 50 +++++ .../Result/Synonyms/SynonymMappings.php | 115 +++++++++++ .../ManagedResources/Query/ResourcesTest.php | 21 ++ .../ManagedResources/Query/StopwordsTest.php | 43 ++++ .../ManagedResources/Query/SynonymsTest.php | 49 +++++ .../QueryType/ManagedResources/QueryTest.php | 44 ++++ .../RequestBuilder/ResourcesTest.php | 45 +++++ .../RequestBuilder/StopwordsTest.php | 103 ++++++++++ .../RequestBuilder/SynonymsTest.php | 115 +++++++++++ .../ResponseParser/ResourcesTest.php | 47 +++++ .../ResponseParser/StopwordsTest.php | 28 +++ .../ResponseParser/SynonymsTest.php | 29 +++ 40 files changed, 2259 insertions(+) create mode 100644 src/QueryType/ManagedResources/Query/Resources.php create mode 100644 src/QueryType/ManagedResources/Query/Stopwords.php create mode 100644 src/QueryType/ManagedResources/Query/Stopwords/Command/AbstractCommand.php create mode 100644 src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php create mode 100644 src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php create mode 100644 src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php create mode 100644 src/QueryType/ManagedResources/Query/Stopwords/Stopword.php create mode 100644 src/QueryType/ManagedResources/Query/Synonyms.php create mode 100644 src/QueryType/ManagedResources/Query/Synonyms/Command/AbstractCommand.php create mode 100644 src/QueryType/ManagedResources/Query/Synonyms/Command/Add.php create mode 100644 src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php create mode 100644 src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php create mode 100644 src/QueryType/ManagedResources/Query/Synonyms/Synonyms.php create mode 100644 src/QueryType/ManagedResources/RequestBuilder/Resources.php create mode 100644 src/QueryType/ManagedResources/RequestBuilder/Stopwords.php create mode 100644 src/QueryType/ManagedResources/RequestBuilder/Synonyms.php create mode 100644 src/QueryType/ManagedResources/ResponseParser/Resources.php create mode 100644 src/QueryType/ManagedResources/ResponseParser/Stopwords.php create mode 100644 src/QueryType/ManagedResources/ResponseParser/Synonyms.php create mode 100644 src/QueryType/ManagedResources/Result/Resources.php create mode 100644 src/QueryType/ManagedResources/Result/Resources/Resource.php create mode 100644 src/QueryType/ManagedResources/Result/Resources/ResourcesList.php create mode 100644 src/QueryType/ManagedResources/Result/Stopwords.php create mode 100644 src/QueryType/ManagedResources/Result/Stopwords/ManagedList.php create mode 100644 src/QueryType/ManagedResources/Result/Stopwords/Stopword.php create mode 100644 src/QueryType/ManagedResources/Result/Stopwords/WordSet.php create mode 100644 src/QueryType/ManagedResources/Result/Synonyms.php create mode 100644 src/QueryType/ManagedResources/Result/Synonyms/ManagedMap.php create mode 100644 src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php create mode 100644 tests/QueryType/ManagedResources/Query/ResourcesTest.php create mode 100644 tests/QueryType/ManagedResources/Query/StopwordsTest.php create mode 100644 tests/QueryType/ManagedResources/Query/SynonymsTest.php create mode 100644 tests/QueryType/ManagedResources/QueryTest.php create mode 100644 tests/QueryType/ManagedResources/RequestBuilder/ResourcesTest.php create mode 100644 tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php create mode 100644 tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php create mode 100644 tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php create mode 100644 tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php create mode 100644 tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php diff --git a/src/Core/Client/Client.php b/src/Core/Client/Client.php index e7ec464e5..fdbd92bee 100644 --- a/src/Core/Client/Client.php +++ b/src/Core/Client/Client.php @@ -107,6 +107,21 @@ class Client extends Configurable implements ClientInterface */ const QUERY_REALTIME_GET = 'get'; + /** + * Querytype managed resource. + */ + const QUERY_MANAGED_RESOURCES = 'resources'; + + /** + * Querytype managed stopwords. + */ + const QUERY_MANAGED_STOPWORDS = 'stopwords'; + + /** + * Querytype managed synonyms. + */ + const QUERY_MANAGED_SYNONYMS = 'synonyms'; + /** * Default options. * @@ -138,6 +153,9 @@ class Client extends Configurable implements ClientInterface self::QUERY_GRAPH => 'Solarium\QueryType\Graph\Query', self::QUERY_EXTRACT => 'Solarium\QueryType\Extract\Query', self::QUERY_REALTIME_GET => 'Solarium\QueryType\RealtimeGet\Query', + self::QUERY_MANAGED_RESOURCES => 'Solarium\QueryType\ManagedResources\Query\Resources', + self::QUERY_MANAGED_STOPWORDS => 'Solarium\QueryType\ManagedResources\Query\Stopwords', + self::QUERY_MANAGED_SYNONYMS => 'Solarium\QueryType\ManagedResources\Query\Synonyms', ]; /** diff --git a/src/QueryType/ManagedResources/Query/Resources.php b/src/QueryType/ManagedResources/Query/Resources.php new file mode 100644 index 000000000..e3d6d9ebc --- /dev/null +++ b/src/QueryType/ManagedResources/Query/Resources.php @@ -0,0 +1,49 @@ + 'schema/managed', + 'resultclass' => 'Solarium\QueryType\ManagedResources\Result\Resources', + 'omitheader' => true, + ]; + + /** + * Get query type. + * + * @return string + */ + public function getType() { + return Client::QUERY_MANAGED_RESOURCES; + } + + /** + * Get the request builder class for this query. + * + * @return RequestBuilder + */ + public function getRequestBuilder() { + return new RequestBuilder(); + } + + /** + * Get the response parser class for this query. + * + * @return ResponseParser + */ + public function getResponseParser() { + return new ResponseParser(); + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Query/Stopwords.php b/src/QueryType/ManagedResources/Query/Stopwords.php new file mode 100644 index 000000000..c9df17c68 --- /dev/null +++ b/src/QueryType/ManagedResources/Query/Stopwords.php @@ -0,0 +1,165 @@ + 'Solarium\QueryType\ManagedResources\Query\Stopwords\Command\Add', + self::COMMAND_DELETE => 'Solarium\QueryType\ManagedResources\Query\Stopwords\Command\Delete', + self::COMMAND_EXISTS => 'Solarium\QueryType\ManagedResources\Query\Stopwords\Command\Exists', + ]; + + /** + * Default options. + * + * @var array + */ + protected $options = [ + 'handler' => 'schema/analysis/stopwords/', + 'resultclass' => 'Solarium\QueryType\ManagedResources\Result\Stopwords', + 'omitheader' => true, + ]; + + /** + * Get query type. + * + * @return string + */ + public function getType() { + return Client::QUERY_MANAGED_STOPWORDS; + } + + /** + * Get the request builder class for this query. + * + * @return RequestBuilder + */ + public function getRequestBuilder() { + return new RequestBuilder(); + } + + /** + * Get the response parser class for this query. + * + * @return ResponseParser + */ + public function getResponseParser() { + return new ResponseParser(); + } + + /** + * Get the name of the stopwords resource. + * @return string + */ + public function getName(): string { + return $this->name; + } + + /** + * Set the name of the stopwords resource. + * @param string $name + */ + public function setName(string $name) { + $this->name = $name; + } + + /** + * Create a command instance. + * + * @param string $type + * @param mixed $options + * + * @throws InvalidArgumentException + * + * @return AbstractCommand + */ + public function createCommand($type, $options = null) + { + $type = strtolower($type); + + if (!isset($this->commandTypes[$type])) { + throw new InvalidArgumentException('Stopwords commandtype unknown: '.$type); + } + + $class = $this->commandTypes[$type]; + + return new $class($options); + } + + /** + * Get command for this stopwords query. + * + * @return AbstractCommand + */ + public function getCommand() + { + return $this->command; + } + + /** + * Add a command to this stopwords query. + * + * @param AbstractCommand $command + * + * @return self Provides fluent interface + */ + public function addCommand(AbstractCommand $command) + { + $this->command = $command; + + return $this; + } + + /** + * Remove command. + * + * @return self Provides fluent interface + */ + public function removeCommand() + { + $this->command = null; + + return $this; + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Command/AbstractCommand.php b/src/QueryType/ManagedResources/Query/Stopwords/Command/AbstractCommand.php new file mode 100644 index 000000000..42a6ff25c --- /dev/null +++ b/src/QueryType/ManagedResources/Query/Stopwords/Command/AbstractCommand.php @@ -0,0 +1,39 @@ +stopwords; + } + + /** + * Set stopwords. + * + * @param array $synonyms + */ + public function setStopwords(array $stopwords) + { + $this->stopwords = $stopwords; + } + + /** + * Returns the data to be send to Solr. + * + * @return string + */ + public function getRawData(): string + { + return json_encode($this->stopwords); + } + + /** + * Returns the term to be send to Solr. + * + * @return string + */ + public function getTerm(): string + { + return ''; + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php b/src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php new file mode 100644 index 000000000..5dd71d839 --- /dev/null +++ b/src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php @@ -0,0 +1,69 @@ +term; + } + + /** + * Set the term to be deleted. + * + * @param string $term + * @return string + */ + public function setTerm(string $term) + { + $this->term = $term; + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php b/src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php new file mode 100644 index 000000000..9ef9c8d79 --- /dev/null +++ b/src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php @@ -0,0 +1,69 @@ +term; + } + + /** + * Set the term to be checked if exists. + * + * @param string $term + * @return string + */ + public function setTerm(string $term) + { + $this->term = $term; + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Stopword.php b/src/QueryType/ManagedResources/Query/Stopwords/Stopword.php new file mode 100644 index 000000000..6fee5b01c --- /dev/null +++ b/src/QueryType/ManagedResources/Query/Stopwords/Stopword.php @@ -0,0 +1,31 @@ +term; + } + + /** + * @param string $term + */ + public function setTerm(string $term) + { + $this->term = $term; + } + + +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Query/Synonyms.php b/src/QueryType/ManagedResources/Query/Synonyms.php new file mode 100644 index 000000000..fe6d3bc25 --- /dev/null +++ b/src/QueryType/ManagedResources/Query/Synonyms.php @@ -0,0 +1,188 @@ + 'Solarium\QueryType\ManagedResources\Query\Synonyms\Command\Add', + self::COMMAND_DELETE => 'Solarium\QueryType\ManagedResources\Query\Synonyms\Command\Delete', + self::COMMAND_EXISTS => 'Solarium\QueryType\ManagedResources\Query\Synonyms\Command\Exists', + ]; + + /** + * Default options. + * + * @var array + */ + protected $options = [ + 'handler' => 'schema/analysis/synonyms/', + 'resultclass' => 'Solarium\QueryType\ManagedResources\Result\Synonyms', + 'omitheader' => true, + ]; + + /** + * Get query type. + * + * @return string + */ + public function getType() { + return Client::QUERY_MANAGED_SYNONYMS; + } + + /** + * Get the request builder class for this query. + * + * @return RequestBuilder + */ + public function getRequestBuilder() { + return new RequestBuilder(); + } + + /** + * Get the response parser class for this query. + * + * @return ResponseParser + */ + public function getResponseParser() { + return new ResponseParser(); + } + + /** + * Get the name of the synonym resource. + * @return string + */ + public function getName(): string { + return $this->name; + } + + /** + * Set the name of the synonym resource. + * @param string $name + */ + public function setName(string $name) { + $this->name = $name; + } + + /** + * Create a command instance. + * + * @param string $type + * @param mixed $options + * + * @throws InvalidArgumentException + * + * @return AbstractCommand + */ + public function createCommand($type, $options = null) + { + $type = strtolower($type); + + if (!isset($this->commandTypes[$type])) { + throw new InvalidArgumentException('Synonyms commandtype unknown: '.$type); + } + + $class = $this->commandTypes[$type]; + + return new $class($options); + } + + /** + * Get command for this synonyms query. + * + * @return AbstractCommand + */ + public function getCommand() + { + return $this->command; + } + + /** + * Add a command to this synonyms query. + * + * @param AbstractCommand $command + * + * @return self Provides fluent interface + */ + public function addCommand(AbstractCommand $command) + { + $this->command = $command; + + return $this; + } + + /** + * Remove command. + * + * @return self Provides fluent interface + */ + public function removeCommand() + { + $this->command = null; + + return $this; + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Query/Synonyms/Command/AbstractCommand.php b/src/QueryType/ManagedResources/Query/Synonyms/Command/AbstractCommand.php new file mode 100644 index 000000000..54d7e229e --- /dev/null +++ b/src/QueryType/ManagedResources/Query/Synonyms/Command/AbstractCommand.php @@ -0,0 +1,39 @@ +synonyms; + } + + /** + * Set synonyms. + * + * @param SynonymsData $synonyms + */ + public function setSynonyms(SynonymsData $synonyms) + { + $this->synonyms = $synonyms; + } + + /** + * Returns the raw data to be sent to Solr. + */ + public function getRawData(): string + { + if($this->getSynonyms() !== null && !empty($this->getSynonyms()->getSynonyms())) + { + if(strlen(trim($this->getSynonyms()->getTerm())) != 0) { + return json_encode(array($this->getSynonyms()->getTerm() => $this->getSynonyms()->getSynonyms())); + } + + return json_encode($this->getSynonyms()->getSynonyms()); + } + + return ''; + } + + /** + * Empty. + * + * @return string + */ + public function getTerm(): string + { + return ''; + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php b/src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php new file mode 100644 index 000000000..fabea3885 --- /dev/null +++ b/src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php @@ -0,0 +1,69 @@ +term; + } + + /** + * Set the term to be deleted. + * + * @param string $term + * @return string + */ + public function setTerm(string $term) + { + $this->term = $term; + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php b/src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php new file mode 100644 index 000000000..94f8bc0ce --- /dev/null +++ b/src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php @@ -0,0 +1,69 @@ +term; + } + + /** + * Set the term to be checked if exists. + * + * @param string $term + * @return string + */ + public function setTerm(string $term) + { + $this->term = $term; + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Query/Synonyms/Synonyms.php b/src/QueryType/ManagedResources/Query/Synonyms/Synonyms.php new file mode 100644 index 000000000..1ac29e93a --- /dev/null +++ b/src/QueryType/ManagedResources/Query/Synonyms/Synonyms.php @@ -0,0 +1,57 @@ +term; + } + + /** + * @param string $term + */ + public function setTerm(string $term) + { + $this->term = $term; + } + + /** + * @return array + */ + public function getSynonyms(): array + { + return $this->synonyms; + } + + /** + * Sets the synonyms. To set a list of symmetric synonyms leave the term empty. + * @param array $synonyms + */ + public function setSynonyms(array $synonyms) + { + $this->synonyms = $synonyms; + } + + +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/RequestBuilder/Resources.php b/src/QueryType/ManagedResources/RequestBuilder/Resources.php new file mode 100644 index 000000000..504c6817f --- /dev/null +++ b/src/QueryType/ManagedResources/RequestBuilder/Resources.php @@ -0,0 +1,9 @@ +getName())) { + throw new \Solarium\Exception\RuntimeException("Name of the resource is not set in the query."); + } + + $request = parent::build($query); + if ($query->getCommand() !== null) { + $request->setHandler($query->getHandler().$query->getName()); + $this->buildCommand($request, $query->getCommand()); + } + else { + // Lists all stopwords. + $request->setMethod(Request::METHOD_GET); + $request->setHandler($query->getHandler().$query->getName()); + } + + return $request; + } + + protected function buildCommand(Request $request, AbstractCommand $command) + { + $request->setMethod($command->getRequestMethod()); + + switch ($command->getType()) { + case StopwordsQuery::COMMAND_ADD: + $request->setRawData($command->getRawData()); + break; + case StopwordsQuery::COMMAND_DELETE: + $request->setHandler($request->getHandler().'/'.$command->getTerm()); + break; + case StopwordsQuery::COMMAND_EXISTS: + $request->setHandler($request->getHandler().'/'.$command->getTerm()); + break; + default: + throw new RuntimeException('Unsupported command type'); + break; + } + + $request->setMethod($command->getRequestMethod()); + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php b/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php new file mode 100644 index 000000000..35d5006e1 --- /dev/null +++ b/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php @@ -0,0 +1,63 @@ +getName())) { + throw new \Solarium\Exception\RuntimeException("Name of the resource is not set in the query."); + } + + $request = parent::build($query); + if ($query->getCommand() !== null) { + $request->setHandler($query->getHandler().$query->getName()); + $this->buildCommand($request, $query->getCommand()); + } + else { + // Lists all synonyms. + $request->setMethod(Request::METHOD_GET); + $request->setHandler($query->getHandler().$query->getName()); + } + + return $request; + } + + protected function buildCommand(Request $request, AbstractCommand $command) + { + $request->setMethod($command->getRequestMethod()); + + switch ($command->getType()) { + case SynonymsQuery::COMMAND_ADD: + $request->setRawData($command->getRawData()); + break; + case SynonymsQuery::COMMAND_DELETE: + $request->setHandler($request->getHandler().'/'.$command->getTerm()); + break; + case SynonymsQuery::COMMAND_EXISTS: + $request->setHandler($request->getHandler().'/'.$command->getTerm()); + break; + default: + throw new RuntimeException('Unsupported command type'); + break; + } + + $request->setMethod($command->getRequestMethod()); + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/ResponseParser/Resources.php b/src/QueryType/ManagedResources/ResponseParser/Resources.php new file mode 100644 index 000000000..8efa7da25 --- /dev/null +++ b/src/QueryType/ManagedResources/ResponseParser/Resources.php @@ -0,0 +1,31 @@ +getData(); + + $items = []; + + if (isset($data['managedResources']) && !empty($data['managedResources'])) { + $items = new ResourcesList($data['managedResources']); + } + + return $this->addHeaderInfo($data, ['items' => $items]); + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/ResponseParser/Stopwords.php b/src/QueryType/ManagedResources/ResponseParser/Stopwords.php new file mode 100644 index 000000000..ca8dedafb --- /dev/null +++ b/src/QueryType/ManagedResources/ResponseParser/Stopwords.php @@ -0,0 +1,31 @@ +getData(); + + $items = []; + + if (isset($data['wordSet']) && !empty($data['wordSet'])) { + $items = new WordSet($data['wordSet']); + } + + return $this->addHeaderInfo($data, ['items' => $items]); + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/ResponseParser/Synonyms.php b/src/QueryType/ManagedResources/ResponseParser/Synonyms.php new file mode 100644 index 000000000..1a09cbe4c --- /dev/null +++ b/src/QueryType/ManagedResources/ResponseParser/Synonyms.php @@ -0,0 +1,31 @@ +getData(); + + $items = []; + + if (isset($data['synonymMappings']) && !empty($data['synonymMappings'])) { + $items = new SynonymMappings($data['synonymMappings']); + } + + return $this->addHeaderInfo($data, ['items' => $items]); + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Result/Resources.php b/src/QueryType/ManagedResources/Result/Resources.php new file mode 100644 index 000000000..d3604ab7d --- /dev/null +++ b/src/QueryType/ManagedResources/Result/Resources.php @@ -0,0 +1,10 @@ +resourceId; + } + + /** + * @param string $resourceId + */ + public function setResourceId(string $resourceId) + { + $this->resourceId = $resourceId; + } + + /** + * @return int + */ + public function getNumObservers(): int + { + return $this->numObservers; + } + + /** + * @param int $numObservers + */ + public function setNumObservers(int $numObservers) + { + $this->numObservers = $numObservers; + } + + /** + * @return string + */ + public function getClass(): string + { + return $this->class; + } + + /** + * @param string $class + */ + public function setClass(string $class) + { + $this->class = $class; + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Result/Resources/ResourcesList.php b/src/QueryType/ManagedResources/Result/Resources/ResourcesList.php new file mode 100644 index 000000000..cd2a6198d --- /dev/null +++ b/src/QueryType/ManagedResources/Result/Resources/ResourcesList.php @@ -0,0 +1,71 @@ +items = $items; + } + + /** + * Get type value. + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * Get all items. + * + * @return Resource[] + */ + public function getItems(): array + { + return $this->items; + } + + /** + * IteratorAggregate implementation. + * + * @return \ArrayIterator + */ + public function getIterator(): \ArrayIterator + { + return new \ArrayIterator($this->items); + } + + /** + * Countable implementation. + * + * @return int + */ + public function count(): int + { + return \count($this->items); + } +} diff --git a/src/QueryType/ManagedResources/Result/Stopwords.php b/src/QueryType/ManagedResources/Result/Stopwords.php new file mode 100644 index 000000000..6e3e957cc --- /dev/null +++ b/src/QueryType/ManagedResources/Result/Stopwords.php @@ -0,0 +1,10 @@ +stopword; + } + + /** + * @param string $stopword + */ + public function setStopword(string $stopword) + { + $this->stopword = $stopword; + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Result/Stopwords/Stopword.php b/src/QueryType/ManagedResources/Result/Stopwords/Stopword.php new file mode 100644 index 000000000..bbbd87130 --- /dev/null +++ b/src/QueryType/ManagedResources/Result/Stopwords/Stopword.php @@ -0,0 +1,9 @@ +items = $result['managedList']; + $this->initializedOn = $result['initializedOn']; + $this->ignoreCase = (bool)$result['initArgs']['ignoreCase']; + } + + /** + * Get type value. + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * Get all items. + * + * @return array + */ + public function getItems(): array + { + return $this->items; + } + + /** + * IteratorAggregate implementation. + * + * @return \ArrayIterator + */ + public function getIterator(): \ArrayIterator + { + return new \ArrayIterator($this->items); + } + + /** + * Countable implementation. + * + * @return int + */ + public function count(): int + { + return count($this->items); + } + + /** + * @return string + */ + public function getResourceId(): string + { + return $this->resourceId; + } + + /** + * @return bool + */ + public function isIgnoreCase(): bool + { + return $this->ignoreCase; + } + + /** + * @return string + */ + public function getInitializedOn(): string + { + return $this->initializedOn; + } + + +} diff --git a/src/QueryType/ManagedResources/Result/Synonyms.php b/src/QueryType/ManagedResources/Result/Synonyms.php new file mode 100644 index 000000000..1ed821a77 --- /dev/null +++ b/src/QueryType/ManagedResources/Result/Synonyms.php @@ -0,0 +1,10 @@ +term; + } + + /** + * @param string $term + */ + public function setTerm(string $term) + { + $this->term = $term; + } + + /** + * @return array + */ + public function getSynonyms(): array + { + return $this->synonyms; + } + + /** + * @param array $synonyms + */ + public function setSynonyms(array $synonyms) + { + $this->synonyms = $synonyms; + } +} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php b/src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php new file mode 100644 index 000000000..44e913b74 --- /dev/null +++ b/src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php @@ -0,0 +1,115 @@ +items = $result['managedMap']; + $this->initializedOn = $result['initializedOn']; + $this->ignoreCase = (bool)$result['initArgs']['ignoreCase']; + } + + /** + * Get type value. + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * Get all items. + * + * @return array + */ + public function getItems(): array + { + return $this->items; + } + + /** + * IteratorAggregate implementation. + * + * @return \ArrayIterator + */ + public function getIterator(): \ArrayIterator + { + return new \ArrayIterator($this->items); + } + + /** + * Countable implementation. + * + * @return int + */ + public function count(): int + { + return count($this->items); + } + + /** + * @return string + */ + public function getResourceId(): string + { + return $this->resourceId; + } + + /** + * @return bool + */ + public function isIgnoreCase(): bool + { + return $this->ignoreCase; + } + + /** + * @return string + */ + public function getInitializedOn(): string + { + return $this->initializedOn; + } +} diff --git a/tests/QueryType/ManagedResources/Query/ResourcesTest.php b/tests/QueryType/ManagedResources/Query/ResourcesTest.php new file mode 100644 index 000000000..df259772c --- /dev/null +++ b/tests/QueryType/ManagedResources/Query/ResourcesTest.php @@ -0,0 +1,21 @@ +query = new Query(); + } + + public function testQuery() + { + $this->assertEquals('resources', $this->query->getType()); + } +} diff --git a/tests/QueryType/ManagedResources/Query/StopwordsTest.php b/tests/QueryType/ManagedResources/Query/StopwordsTest.php new file mode 100644 index 000000000..c83ae7bb4 --- /dev/null +++ b/tests/QueryType/ManagedResources/Query/StopwordsTest.php @@ -0,0 +1,43 @@ +query = new Stopwords(); + } + + public function testQuery() + { + $this->assertEquals('stopwords', $this->query->getType()); + } + + public function testAddCommand() + { + $command = $this->query->createCommand(Stopwords::COMMAND_ADD); + $this->assertInstanceOf(Add::class, $command); + } + + public function testDeleteCommand() + { + $command = $this->query->createCommand(Stopwords::COMMAND_DELETE); + $this->assertInstanceOf(Delete::class, $command); + } + + public function testExistsCommand() + { + $command = $this->query->createCommand(Stopwords::COMMAND_EXISTS); + + $this->assertInstanceOf(Exists::class, $command); + } +} diff --git a/tests/QueryType/ManagedResources/Query/SynonymsTest.php b/tests/QueryType/ManagedResources/Query/SynonymsTest.php new file mode 100644 index 000000000..cae9ef8a1 --- /dev/null +++ b/tests/QueryType/ManagedResources/Query/SynonymsTest.php @@ -0,0 +1,49 @@ +query = new Synonyms(); + } + + public function testQuery() + { + $this->assertEquals('synonyms', $this->query->getType()); + } + + public function testAddCommand() + { + $command = $this->query->createCommand(Synonyms::COMMAND_ADD); + $this->assertInstanceOf(Add::class, $command); + $synonyms = new Synonyms\Synonyms(); + $term = 'mad'; + $synonyms->setTerm($term); + $synonyms->setSynonyms(['angry', 'upset']); + $command->setSynonyms($synonyms); + $this->assertEquals('mad', $command->getSynonyms()->getTerm()); + $this->assertEquals(['angry', 'upset'], $command->getSynonyms()->getSynonyms()); + } + + public function testDeleteCommand() + { + $command = $this->query->createCommand(Synonyms::COMMAND_DELETE); + $this->assertInstanceOf(Delete::class, $command); + } + + public function testExistsCommand() + { + $command = $this->query->createCommand(Synonyms::COMMAND_EXISTS); + $this->assertInstanceOf(Exists::class, $command); + } +} diff --git a/tests/QueryType/ManagedResources/QueryTest.php b/tests/QueryType/ManagedResources/QueryTest.php new file mode 100644 index 000000000..b4856898e --- /dev/null +++ b/tests/QueryType/ManagedResources/QueryTest.php @@ -0,0 +1,44 @@ +query = new ResourcesQuery(); + } + + public function testGetType() + { + $this->assertSame(Client::QUERY_MANAGED_RESOURCES, $this->query->getType()); + } + + public function testGetResponseParser() + { + $this->assertInstanceOf( + 'Solarium\QueryType\ManagedResources\ResponseParser\Resources', + $this->query->getResponseParser() + ); + } + + public function testGetRequestBuilder() + { + $this->assertInstanceOf( + 'Solarium\QueryType\ManagedResources\RequestBuilder\Resources', + $this->query->getRequestBuilder() + ); + } + + public function testQuery() + { + // TODO implement + //$this->query-> + } +} diff --git a/tests/QueryType/ManagedResources/RequestBuilder/ResourcesTest.php b/tests/QueryType/ManagedResources/RequestBuilder/ResourcesTest.php new file mode 100644 index 000000000..43afad4d2 --- /dev/null +++ b/tests/QueryType/ManagedResources/RequestBuilder/ResourcesTest.php @@ -0,0 +1,45 @@ +query = new ResourcesQuery(); + $this->builder = new ResourcesRequestBuilder(); + } + + public function testBuild() + { + $handler = 'schema/managed'; + + $request = $this->builder->build($this->query); + + $this->assertEquals( + [ + 'wt' => 'json', + 'json.nl' => 'flat', + 'omitHeader' => 'true', + ], + $request->getParams() + ); + + $this->assertSame($handler, $request->getHandler()); + } +} diff --git a/tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php b/tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php new file mode 100644 index 000000000..af65a26b2 --- /dev/null +++ b/tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php @@ -0,0 +1,103 @@ +query = new StopwordsQuery(); + $this->builder = new StopwordsRequestBuilder(); + } + + public function testBuild() + { + $handler = 'schema/analysis/stopwords/dutch'; + + $this->query->setName("dutch"); + $request = $this->builder->build($this->query); + + $this->assertEquals( + [ + 'wt' => 'json', + 'json.nl' => 'flat', + 'omitHeader' => 'true', + ], + $request->getParams() + ); + + $this->assertSame($handler, $request->getHandler()); + } + + public function testNoName() + { + $this->expectException(\Solarium\Exception\RuntimeException::class); + $request = $this->builder->build($this->query); + } + + public function testQuery() + { + $this->query->setName("dutch"); + $request = $this->builder->build($this->query); + $this->assertSame(Request::METHOD_GET, $request->getMethod()); + } + + public function testAdd() + { + $stopwords = array('de'); + $command = new AddCommand(); + $command->setStopwords($stopwords); + $this->query->setName("dutch"); + $this->query->addCommand($command); + $request = $this->builder->build($this->query); + $this->assertSame(Request::METHOD_PUT, $request->getMethod()); + $this->assertEquals($stopwords, $command->getStopwords()); + $this->assertEquals('', $command->getTerm()); + $this->assertEquals('["de"]', $command->getRawData()); + } + + public function testDelete() + { + $term = 'de'; + $command = new DeleteCommand(); + $command->setTerm($term); + $this->query->setName("dutch"); + $this->query->addCommand($command); + $request = $this->builder->build($this->query); + $this->assertSame(Request::METHOD_DELETE, $request->getMethod()); + $this->assertEquals($term, $command->getTerm()); + $this->assertEquals('', $command->getRawData()); + } + + public function testExists() + { + $term = 'de'; + $command = new ExistsCommand(); + $command->setTerm('de'); + $this->query->setName("dutch"); + $this->query->addCommand($command); + $request = $this->builder->build($this->query); + $this->assertSame(Request::METHOD_GET, $request->getMethod()); + $this->assertEquals($term, $command->getTerm()); + $this->assertEquals('', $command->getRawData()); + } +} diff --git a/tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php b/tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php new file mode 100644 index 000000000..ca0579812 --- /dev/null +++ b/tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php @@ -0,0 +1,115 @@ +query = new SynonymsQuery(); + $this->builder = new SynonymsRequestBuilder(); + $this->client = new Client(); + } + + public function testBuild() + { + $handler = 'schema/analysis/synonyms/dutch'; + $this->query->setName("dutch"); + $request = $this->builder->build($this->query); + + $this->assertEquals( + [ + 'wt' => 'json', + 'json.nl' => 'flat', + 'omitHeader' => 'true', + ], + $request->getParams() + ); + + $this->assertSame($handler, $request->getHandler()); + } + + public function testNoName() + { + $this->expectException(\Solarium\Exception\RuntimeException::class); + $request = $this->builder->build($this->query); + } + + public function testAdd() + { + $synonyms = new SynonymsQuery\Synonyms(); + $synonyms->setTerm('mad'); + $synonyms->setSynonyms(array('angry', 'upset')); + $command = new AddCommand(); + $command->setSynonyms($synonyms); + $this->query->setName("dutch"); + $this->query->addCommand($command); + $request = $this->builder->build($this->query); + $this->assertSame(Request::METHOD_PUT, $request->getMethod()); + $this->assertEquals('{"mad":["angry","upset"]}', $request->getRawData()); + } + + public function testAddSymmytrical() + { + $synonyms = new SynonymsQuery\Synonyms(); + $synonyms->setSynonyms(array('funny', 'entertaining', 'whimsical', 'jocular')); + $command = new AddCommand(); + $command->setSynonyms($synonyms); + $this->query->setName("dutch"); + $this->query->addCommand($command); + $request = $this->builder->build($this->query); + $this->assertSame(Request::METHOD_PUT, $request->getMethod()); + $this->assertEquals('["funny","entertaining","whimsical","jocular"]', $request->getRawData()); + } + + public function testDelete() + { + $term = 'mad'; + $command = new DeleteCommand(); + $command->setTerm($term); + $this->query->setName("dutch"); + $this->query->addCommand($command); + $request = $this->builder->build($this->query); + $this->assertSame(Request::METHOD_DELETE, $request->getMethod()); + $this->assertEquals($term, $command->getTerm()); + $this->assertEquals('', $command->getRawData()); + } + + public function testExists() + { + $term = 'mad'; + $command = new ExistsCommand(); + $command->setTerm($term); + $this->query->setName("dutch"); + $this->query->addCommand($command); + $request = $this->builder->build($this->query); + $this->assertSame(Request::METHOD_GET, $request->getMethod()); + $this->assertEquals($term, $command->getTerm()); + $this->assertEquals('', $command->getRawData()); + } +} diff --git a/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php b/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php new file mode 100644 index 000000000..29a932147 --- /dev/null +++ b/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php @@ -0,0 +1,47 @@ + [ + [ + 'resourceId' => '/schema/analysis/stopwords/dutch', + 'numObservers' => '1', + 'class' => 'org.apache.solr.rest.schema.analysis.ManagedWordSetResource', + ], + [ + 'resourceId' => '/schema/analysis/synonyms/dutch', + 'numObservers' => '1', + 'class' => 'org.apache.solr.rest.schema.analysis.ManagedSynonymFilterFactory$SynonymManager', + ], + ], + 'responseHeader' => [ + 'status' => 1, + 'QTime' => 5, + ], + ]; + + $resultStub = $this->createMock(Result::class); + $resultStub->expects($this->once()) + ->method('getData') + ->will($this->returnValue($data)); + + $parser = new ResourcesResponseParser(); + + $result = $parser->parse($resultStub); + + $this->assertSame(count($data['managedResources']), count($result['items'])); + $this->assertSame('managedResources', $result['items']->getName()); + $this->assertSame('/schema/analysis/stopwords/dutch', $result['items']->getItems()[0]['resourceId']); + $this->assertSame('/schema/analysis/synonyms/dutch', $result['items']->getItems()[1]['resourceId']); + } + +} diff --git a/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php b/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php new file mode 100644 index 000000000..740f66b1b --- /dev/null +++ b/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php @@ -0,0 +1,28 @@ +parse($result); + + $this->assertSame('200 OK', $result->getResponse()->getStatusMessage()); + $this->assertSame(0, $parsed['status']); + $this->assertSame(1, $parsed['queryTime']); + $this->assertSame('2014-03-28T20:53:53.058Z', $parsed['items']->getInitializedOn()); + $this->assertSame(true, $parsed['items']->isIgnoreCase()); + } +} diff --git a/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php b/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php new file mode 100644 index 000000000..c323aa400 --- /dev/null +++ b/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php @@ -0,0 +1,29 @@ +parse($result); + + $this->assertSame('200 OK', $result->getResponse()->getStatusMessage()); + $this->assertSame(0, $parsed['status']); + $this->assertSame(3, $parsed['queryTime']); + $this->assertSame('2014-12-16T22:44:05.33Z', $parsed['items']->getInitializedOn()); + $this->assertSame(true, $parsed['items']->isIgnoreCase()); + } +} + From c8d177733103afd2b0e5b757644144ca774186aa Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 10 Sep 2018 12:56:04 +0200 Subject: [PATCH 06/22] Improved result parsing and added integration tests. --- .../ManagedResources/Query/Resources.php | 11 ++- .../ManagedResources/Query/Stopwords.php | 29 +++--- .../Query/Stopwords/Command/Add.php | 4 +- .../Query/Stopwords/Command/Delete.php | 7 +- .../Query/Stopwords/Command/Exists.php | 7 +- .../ManagedResources/Query/Synonyms.php | 29 +++--- .../Query/Synonyms/Command/Add.php | 4 +- .../Query/Synonyms/Command/Delete.php | 7 +- .../Query/Synonyms/Command/Exists.php | 7 +- .../RequestBuilder/Stopwords.php | 4 +- .../RequestBuilder/Synonyms.php | 6 +- .../ResponseParser/Resources.php | 7 +- .../ResponseParser/Stopwords.php | 18 +++- .../ResponseParser/Synonyms.php | 22 ++++- .../ManagedResources/Result/Resources.php | 10 -- .../Result/Resources/Resource.php | 13 +++ .../{ResourcesList.php => ResourceList.php} | 18 +++- .../ManagedResources/Result/Stopwords.php | 10 -- .../Result/Stopwords/ManagedList.php | 29 ------ .../Result/Stopwords/WordSet.php | 37 +++++-- .../ManagedResources/Result/Synonyms.php | 10 -- .../Result/Synonyms/SynonymMappings.php | 41 ++++++-- .../Synonyms/{ManagedMap.php => Synonyms.php} | 23 ++++- .../Integration/AbstractTechproductsTest.php | 99 +++++++++++++++++++ .../RequestBuilder/StopwordsTest.php | 6 +- .../RequestBuilder/SynonymsTest.php | 12 +-- 26 files changed, 314 insertions(+), 156 deletions(-) delete mode 100644 src/QueryType/ManagedResources/Result/Resources.php rename src/QueryType/ManagedResources/Result/Resources/{ResourcesList.php => ResourceList.php} (65%) delete mode 100644 src/QueryType/ManagedResources/Result/Stopwords.php delete mode 100644 src/QueryType/ManagedResources/Result/Stopwords/ManagedList.php delete mode 100644 src/QueryType/ManagedResources/Result/Synonyms.php rename src/QueryType/ManagedResources/Result/Synonyms/{ManagedMap.php => Synonyms.php} (62%) diff --git a/src/QueryType/ManagedResources/Query/Resources.php b/src/QueryType/ManagedResources/Query/Resources.php index e3d6d9ebc..305685bce 100644 --- a/src/QueryType/ManagedResources/Query/Resources.php +++ b/src/QueryType/ManagedResources/Query/Resources.php @@ -16,7 +16,7 @@ class Resources extends AbstractQuery { */ protected $options = [ 'handler' => 'schema/managed', - 'resultclass' => 'Solarium\QueryType\ManagedResources\Result\Resources', + 'resultclass' => 'Solarium\QueryType\ManagedResources\Result\Resources\ResourceList', 'omitheader' => true, ]; @@ -25,7 +25,8 @@ class Resources extends AbstractQuery { * * @return string */ - public function getType() { + public function getType(): string + { return Client::QUERY_MANAGED_RESOURCES; } @@ -34,7 +35,8 @@ public function getType() { * * @return RequestBuilder */ - public function getRequestBuilder() { + public function getRequestBuilder(): RequestBuilder + { return new RequestBuilder(); } @@ -43,7 +45,8 @@ public function getRequestBuilder() { * * @return ResponseParser */ - public function getResponseParser() { + public function getResponseParser(): ResponseParser + { return new ResponseParser(); } } \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Query/Stopwords.php b/src/QueryType/ManagedResources/Query/Stopwords.php index c9df17c68..0d926e09f 100644 --- a/src/QueryType/ManagedResources/Query/Stopwords.php +++ b/src/QueryType/ManagedResources/Query/Stopwords.php @@ -30,7 +30,7 @@ class Stopwords extends BaseQuery { * Name of the stopwords resource. * @var string */ - protected $name = ""; + protected $name = ''; /** * Command. @@ -57,7 +57,7 @@ class Stopwords extends BaseQuery { */ protected $options = [ 'handler' => 'schema/analysis/stopwords/', - 'resultclass' => 'Solarium\QueryType\ManagedResources\Result\Stopwords', + 'resultclass' => 'Solarium\QueryType\ManagedResources\Result\Stopwords\WordSet', 'omitheader' => true, ]; @@ -66,7 +66,8 @@ class Stopwords extends BaseQuery { * * @return string */ - public function getType() { + public function getType(): string + { return Client::QUERY_MANAGED_STOPWORDS; } @@ -75,7 +76,8 @@ public function getType() { * * @return RequestBuilder */ - public function getRequestBuilder() { + public function getRequestBuilder(): RequestBuilder + { return new RequestBuilder(); } @@ -84,7 +86,8 @@ public function getRequestBuilder() { * * @return ResponseParser */ - public function getResponseParser() { + public function getResponseParser(): ResponseParser + { return new ResponseParser(); } @@ -92,7 +95,8 @@ public function getResponseParser() { * Get the name of the stopwords resource. * @return string */ - public function getName(): string { + public function getName(): string + { return $this->name; } @@ -100,7 +104,8 @@ public function getName(): string { * Set the name of the stopwords resource. * @param string $name */ - public function setName(string $name) { + public function setName(string $name) + { $this->name = $name; } @@ -114,7 +119,7 @@ public function setName(string $name) { * * @return AbstractCommand */ - public function createCommand($type, $options = null) + public function createCommand($type, $options = null): AbstractCommand { $type = strtolower($type); @@ -130,7 +135,7 @@ public function createCommand($type, $options = null) /** * Get command for this stopwords query. * - * @return AbstractCommand + * @return AbstractCommand|null */ public function getCommand() { @@ -138,13 +143,13 @@ public function getCommand() } /** - * Add a command to this stopwords query. + * Set a command to the stopwords query. * * @param AbstractCommand $command * * @return self Provides fluent interface */ - public function addCommand(AbstractCommand $command) + public function setCommand(AbstractCommand $command): self { $this->command = $command; @@ -156,7 +161,7 @@ public function addCommand(AbstractCommand $command) * * @return self Provides fluent interface */ - public function removeCommand() + public function removeCommand(): self { $this->command = null; diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php b/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php index 34204dffb..b6c486fa8 100644 --- a/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php +++ b/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php @@ -21,7 +21,7 @@ class Add extends AbstractCommand * * @return string */ - public function getType() + public function getType(): string { return Stopwords::COMMAND_ADD; } @@ -31,7 +31,7 @@ public function getType() * * @return string */ - public function getRequestMethod() + public function getRequestMethod(): string { return Request::METHOD_PUT; } diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php b/src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php index 5dd71d839..051dd862b 100644 --- a/src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php +++ b/src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php @@ -14,14 +14,14 @@ class Delete extends AbstractCommand * * @var string */ - protected $term; + protected $term = ''; /** * Returns command type, for use in adapters. * * @return string */ - public function getType() + public function getType(): string { return Stopwords::COMMAND_DELETE; } @@ -31,7 +31,7 @@ public function getType() * * @return string */ - public function getRequestMethod() + public function getRequestMethod(): string { return Request::METHOD_DELETE; } @@ -60,7 +60,6 @@ public function getTerm(): string * Set the term to be deleted. * * @param string $term - * @return string */ public function setTerm(string $term) { diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php b/src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php index 9ef9c8d79..2386f3d38 100644 --- a/src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php +++ b/src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php @@ -14,14 +14,14 @@ class Exists extends AbstractCommand * * @var string */ - protected $term; + protected $term = ''; /** * Returns command type, for use in adapters. * * @return string */ - public function getType() + public function getType(): string { return Stopwords::COMMAND_EXISTS; } @@ -31,7 +31,7 @@ public function getType() * * @return string */ - public function getRequestMethod() + public function getRequestMethod(): string { return Request::METHOD_GET; } @@ -60,7 +60,6 @@ public function getTerm(): string * Set the term to be checked if exists. * * @param string $term - * @return string */ public function setTerm(string $term) { diff --git a/src/QueryType/ManagedResources/Query/Synonyms.php b/src/QueryType/ManagedResources/Query/Synonyms.php index fe6d3bc25..9eae40531 100644 --- a/src/QueryType/ManagedResources/Query/Synonyms.php +++ b/src/QueryType/ManagedResources/Query/Synonyms.php @@ -32,7 +32,7 @@ class Synonyms extends BaseQuery { * * @var string */ - protected $name = ""; + protected $name = ''; /** * ResourceId looked up using the managed resources component. @@ -80,7 +80,7 @@ class Synonyms extends BaseQuery { */ protected $options = [ 'handler' => 'schema/analysis/synonyms/', - 'resultclass' => 'Solarium\QueryType\ManagedResources\Result\Synonyms', + 'resultclass' => 'Solarium\QueryType\ManagedResources\Result\Synonyms\SynonymMappings', 'omitheader' => true, ]; @@ -89,7 +89,8 @@ class Synonyms extends BaseQuery { * * @return string */ - public function getType() { + public function getType() + { return Client::QUERY_MANAGED_SYNONYMS; } @@ -98,7 +99,8 @@ public function getType() { * * @return RequestBuilder */ - public function getRequestBuilder() { + public function getRequestBuilder(): RequestBuilder + { return new RequestBuilder(); } @@ -107,7 +109,8 @@ public function getRequestBuilder() { * * @return ResponseParser */ - public function getResponseParser() { + public function getResponseParser(): ResponseParser + { return new ResponseParser(); } @@ -115,7 +118,8 @@ public function getResponseParser() { * Get the name of the synonym resource. * @return string */ - public function getName(): string { + public function getName(): string + { return $this->name; } @@ -123,7 +127,8 @@ public function getName(): string { * Set the name of the synonym resource. * @param string $name */ - public function setName(string $name) { + public function setName(string $name) + { $this->name = $name; } @@ -137,7 +142,7 @@ public function setName(string $name) { * * @return AbstractCommand */ - public function createCommand($type, $options = null) + public function createCommand($type, $options = null): AbstractCommand { $type = strtolower($type); @@ -153,7 +158,7 @@ public function createCommand($type, $options = null) /** * Get command for this synonyms query. * - * @return AbstractCommand + * @return AbstractCommand|null */ public function getCommand() { @@ -161,13 +166,13 @@ public function getCommand() } /** - * Add a command to this synonyms query. + * Set a command for the synonyms query. * * @param AbstractCommand $command * * @return self Provides fluent interface */ - public function addCommand(AbstractCommand $command) + public function setCommand(AbstractCommand $command): self { $this->command = $command; @@ -179,7 +184,7 @@ public function addCommand(AbstractCommand $command) * * @return self Provides fluent interface */ - public function removeCommand() + public function removeCommand(): self { $this->command = null; diff --git a/src/QueryType/ManagedResources/Query/Synonyms/Command/Add.php b/src/QueryType/ManagedResources/Query/Synonyms/Command/Add.php index e7b3c4d78..5f859f307 100644 --- a/src/QueryType/ManagedResources/Query/Synonyms/Command/Add.php +++ b/src/QueryType/ManagedResources/Query/Synonyms/Command/Add.php @@ -22,7 +22,7 @@ class Add extends AbstractCommand * * @return string */ - public function getType() + public function getType(): string { return Synonyms::COMMAND_ADD; } @@ -32,7 +32,7 @@ public function getType() * * @return string */ - public function getRequestMethod() + public function getRequestMethod(): string { return Request::METHOD_PUT; } diff --git a/src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php b/src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php index fabea3885..e8cedf408 100644 --- a/src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php +++ b/src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php @@ -14,14 +14,14 @@ class Delete extends AbstractCommand * * @var string */ - protected $term; + protected $term = ''; /** * Returns command type, for use in adapters. * * @return string */ - public function getType() + public function getType(): string { return Synonyms::COMMAND_DELETE; } @@ -31,7 +31,7 @@ public function getType() * * @return string */ - public function getRequestMethod() + public function getRequestMethod(): string { return Request::METHOD_DELETE; } @@ -60,7 +60,6 @@ public function getTerm(): string * Set the term to be deleted. * * @param string $term - * @return string */ public function setTerm(string $term) { diff --git a/src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php b/src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php index 94f8bc0ce..cfdb5fcd0 100644 --- a/src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php +++ b/src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php @@ -14,14 +14,14 @@ class Exists extends AbstractCommand * * @var string */ - protected $term; + protected $term = ''; /** * Returns command type, for use in adapters. * * @return string */ - public function getType() + public function getType(): string { return Synonyms::COMMAND_EXISTS; } @@ -31,7 +31,7 @@ public function getType() * * @return string */ - public function getRequestMethod() + public function getRequestMethod(): string { return Request::METHOD_GET; } @@ -60,7 +60,6 @@ public function getTerm(): string * Set the term to be checked if exists. * * @param string $term - * @return string */ public function setTerm(string $term) { diff --git a/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php b/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php index e6a9be7cc..c7983dc2c 100644 --- a/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php +++ b/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php @@ -25,14 +25,14 @@ public function build(QueryInterface $query) } $request = parent::build($query); + $request->setHandler($query->getHandler().$query->getName()); if ($query->getCommand() !== null) { - $request->setHandler($query->getHandler().$query->getName()); + $request->addHeader('Content-Type: application/json; charset=utf-8'); $this->buildCommand($request, $query->getCommand()); } else { // Lists all stopwords. $request->setMethod(Request::METHOD_GET); - $request->setHandler($query->getHandler().$query->getName()); } return $request; diff --git a/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php b/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php index 35d5006e1..6bfdbe018 100644 --- a/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php +++ b/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php @@ -22,18 +22,18 @@ class Synonyms extends BaseRequestBuilder { public function build(QueryInterface $query) { if (empty($query->getName())) { - throw new \Solarium\Exception\RuntimeException("Name of the resource is not set in the query."); + throw new \Solarium\Exception\RuntimeException("Name of the synonym resource is not set in the query."); } $request = parent::build($query); + $request->setHandler($query->getHandler().$query->getName()); if ($query->getCommand() !== null) { - $request->setHandler($query->getHandler().$query->getName()); + $request->addHeader('Content-Type: application/json; charset=utf-8'); $this->buildCommand($request, $query->getCommand()); } else { // Lists all synonyms. $request->setMethod(Request::METHOD_GET); - $request->setHandler($query->getHandler().$query->getName()); } return $request; diff --git a/src/QueryType/ManagedResources/ResponseParser/Resources.php b/src/QueryType/ManagedResources/ResponseParser/Resources.php index 8efa7da25..9397a73c1 100644 --- a/src/QueryType/ManagedResources/ResponseParser/Resources.php +++ b/src/QueryType/ManagedResources/ResponseParser/Resources.php @@ -5,7 +5,8 @@ use Solarium\Core\Query\AbstractResponseParser as ResponseParserAbstract; use Solarium\Core\Query\ResponseParserInterface; use Solarium\Core\Query\Result\Result; -use Solarium\QueryType\ManagedResources\Result\Resources\ResourcesList; +use Solarium\QueryType\ManagedResources\Result\Resources\Resource; +use Solarium\QueryType\ManagedResources\Result\Resources\ResourceList; class Resources extends ResponseParserAbstract implements ResponseParserInterface { @@ -23,7 +24,9 @@ public function parse($result) $items = []; if (isset($data['managedResources']) && !empty($data['managedResources'])) { - $items = new ResourcesList($data['managedResources']); + foreach($data['managedResources'] as $resource) { + $items[] = new Resource($resource); + } } return $this->addHeaderInfo($data, ['items' => $items]); diff --git a/src/QueryType/ManagedResources/ResponseParser/Stopwords.php b/src/QueryType/ManagedResources/ResponseParser/Stopwords.php index ca8dedafb..5dfc6a6db 100644 --- a/src/QueryType/ManagedResources/ResponseParser/Stopwords.php +++ b/src/QueryType/ManagedResources/ResponseParser/Stopwords.php @@ -19,13 +19,25 @@ class Stopwords extends ResponseParserAbstract implements ResponseParserInterfac public function parse($result) { $data = $result->getData(); + $wordSet = null; + if(isset($data['wordSet'])) { + $wordSet = $data['wordSet']; + } + $parsed = []; $items = []; - if (isset($data['wordSet']) && !empty($data['wordSet'])) { - $items = new WordSet($data['wordSet']); + if ($wordSet !== null && !empty($wordSet)) { + $items = $wordSet['managedList']; + + $parsed['items'] = $items; + $parsed['ignoreCase'] = $wordSet['initArgs']['ignoreCase']; + $parsed['initializedOn'] = $wordSet['initializedOn']; + $parsed['updatedSinceInit'] = $wordSet['updatedSinceInit']; } - return $this->addHeaderInfo($data, ['items' => $items]); + $this->addHeaderInfo($data, $parsed); + + return $parsed; } } \ No newline at end of file diff --git a/src/QueryType/ManagedResources/ResponseParser/Synonyms.php b/src/QueryType/ManagedResources/ResponseParser/Synonyms.php index 1a09cbe4c..e316c3a92 100644 --- a/src/QueryType/ManagedResources/ResponseParser/Synonyms.php +++ b/src/QueryType/ManagedResources/ResponseParser/Synonyms.php @@ -5,7 +5,7 @@ use Solarium\Core\Query\AbstractResponseParser as ResponseParserAbstract; use Solarium\Core\Query\ResponseParserInterface; use Solarium\Core\Query\Result\Result; -use Solarium\QueryType\ManagedResources\Result\Synonyms\SynonymMappings; +use Solarium\QueryType\ManagedResources\Result\Synonyms\ManagedMap; class Synonyms extends ResponseParserAbstract implements ResponseParserInterface { @@ -19,13 +19,27 @@ class Synonyms extends ResponseParserAbstract implements ResponseParserInterface public function parse($result) { $data = $result->getData(); + $synonymMappings = null; + if(isset($data['synonymMappings'])) { + $synonymMappings = $data['synonymMappings']; + } + $parsed = []; $items = []; - if (isset($data['synonymMappings']) && !empty($data['synonymMappings'])) { - $items = new SynonymMappings($data['synonymMappings']); + if ($synonymMappings !== null && !empty($synonymMappings)) { + foreach ($synonymMappings['managedMap'] as $term => $synonyms) { + $items[] = new \Solarium\QueryType\ManagedResources\Result\Synonyms\Synonyms($term, $synonyms); + } + + $parsed['items'] = $items; + $parsed['ignoreCase'] = $synonymMappings['initArgs']['ignoreCase']; + $parsed['initializedOn'] = $synonymMappings['initializedOn']; + $parsed['updatedSinceInit'] = $synonymMappings['updatedSinceInit']; } - return $this->addHeaderInfo($data, ['items' => $items]); + $this->addHeaderInfo($data, $parsed); + + return $parsed; } } \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Result/Resources.php b/src/QueryType/ManagedResources/Result/Resources.php deleted file mode 100644 index d3604ab7d..000000000 --- a/src/QueryType/ManagedResources/Result/Resources.php +++ /dev/null @@ -1,10 +0,0 @@ -resourceId = $resource['resourceId']; + $this->numObservers = $resource['numObservers']; + $this->class = $resource['class']; + } + + /** * @return string */ diff --git a/src/QueryType/ManagedResources/Result/Resources/ResourcesList.php b/src/QueryType/ManagedResources/Result/Resources/ResourceList.php similarity index 65% rename from src/QueryType/ManagedResources/Result/Resources/ResourcesList.php rename to src/QueryType/ManagedResources/Result/Resources/ResourceList.php index cd2a6198d..0a8b68f07 100644 --- a/src/QueryType/ManagedResources/Result/Resources/ResourcesList.php +++ b/src/QueryType/ManagedResources/Result/Resources/ResourceList.php @@ -2,7 +2,12 @@ namespace Solarium\QueryType\ManagedResources\Result\Resources; -class ResourcesList implements \IteratorAggregate, \Countable +use Solarium\Core\Client\Response; +use Solarium\Core\Query\AbstractQuery; +use Solarium\Core\Query\Result\QueryType as BaseResult; +use Solarium\Core\Query\Result\Result; + +class ResourceList extends BaseResult implements \IteratorAggregate, \Countable { /** * List name. @@ -21,12 +26,12 @@ class ResourcesList implements \IteratorAggregate, \Countable /** * Constructor. * - * @param string $name - * @param array $items + * @param AbstractQuery $query + * @param Response $response */ - public function __construct($items) + public function __construct($query, $response) { - $this->items = $items; + Result::__construct($query, $response); } /** @@ -46,6 +51,7 @@ public function getName(): string */ public function getItems(): array { + $this->parseResponse(); return $this->items; } @@ -56,6 +62,7 @@ public function getItems(): array */ public function getIterator(): \ArrayIterator { + $this->parseResponse(); return new \ArrayIterator($this->items); } @@ -66,6 +73,7 @@ public function getIterator(): \ArrayIterator */ public function count(): int { + $this->parseResponse(); return \count($this->items); } } diff --git a/src/QueryType/ManagedResources/Result/Stopwords.php b/src/QueryType/ManagedResources/Result/Stopwords.php deleted file mode 100644 index 6e3e957cc..000000000 --- a/src/QueryType/ManagedResources/Result/Stopwords.php +++ /dev/null @@ -1,10 +0,0 @@ -stopword; - } - - /** - * @param string $stopword - */ - public function setStopword(string $stopword) - { - $this->stopword = $stopword; - } -} \ No newline at end of file diff --git a/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php b/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php index 8f8f9c218..647c3cb81 100644 --- a/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php +++ b/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php @@ -2,7 +2,11 @@ namespace Solarium\QueryType\ManagedResources\Result\Stopwords; -class WordSet implements \IteratorAggregate, \Countable +use Solarium\Core\Query\Result\Result; + +use Solarium\Core\Query\Result\QueryType as BaseResult; + +class WordSet extends BaseResult implements \IteratorAggregate, \Countable { /** * List name. @@ -18,11 +22,17 @@ class WordSet implements \IteratorAggregate, \Countable protected $ignoreCase; /** - * Datetime when the resource was initialized + * Datetime when the resource was initialized. * @var string */ protected $initializedOn; + /** + * Datetime when the resource was last updated. + * @var string + */ + protected $updatedSinceInit; + /** * List items. * @@ -33,14 +43,12 @@ class WordSet implements \IteratorAggregate, \Countable /** * Constructor. * - * @param string $name - * @param array $result + * @param $query + * @param $response */ - public function __construct($result) + public function __construct($query, $response) { - $this->items = $result['managedList']; - $this->initializedOn = $result['initializedOn']; - $this->ignoreCase = (bool)$result['initArgs']['ignoreCase']; + Result::__construct($query, $response); } /** @@ -60,6 +68,7 @@ public function getName(): string */ public function getItems(): array { + $this->parseResponse(); return $this->items; } @@ -70,6 +79,7 @@ public function getItems(): array */ public function getIterator(): \ArrayIterator { + $this->parseResponse(); return new \ArrayIterator($this->items); } @@ -80,6 +90,7 @@ public function getIterator(): \ArrayIterator */ public function count(): int { + $this->parseResponse(); return count($this->items); } @@ -88,6 +99,7 @@ public function count(): int */ public function getResourceId(): string { + $this->parseResponse(); return $this->resourceId; } @@ -96,6 +108,7 @@ public function getResourceId(): string */ public function isIgnoreCase(): bool { + $this->parseResponse(); return $this->ignoreCase; } @@ -104,8 +117,16 @@ public function isIgnoreCase(): bool */ public function getInitializedOn(): string { + $this->parseResponse(); return $this->initializedOn; } + /** + * @return string + */ + public function getUpdatedSinceInit(): string + { + return $this->updatedSinceInit; + } } diff --git a/src/QueryType/ManagedResources/Result/Synonyms.php b/src/QueryType/ManagedResources/Result/Synonyms.php deleted file mode 100644 index 1ed821a77..000000000 --- a/src/QueryType/ManagedResources/Result/Synonyms.php +++ /dev/null @@ -1,10 +0,0 @@ -items = $result['managedMap']; - $this->initializedOn = $result['initializedOn']; - $this->ignoreCase = (bool)$result['initArgs']['ignoreCase']; + Result::__construct($query, $response); } /** @@ -62,10 +69,11 @@ public function getName(): string /** * Get all items. * - * @return array + * @return Synonyms[] */ public function getItems(): array { + $this->parseResponse(); return $this->items; } @@ -76,6 +84,7 @@ public function getItems(): array */ public function getIterator(): \ArrayIterator { + $this->parseResponse(); return new \ArrayIterator($this->items); } @@ -86,7 +95,8 @@ public function getIterator(): \ArrayIterator */ public function count(): int { - return count($this->items); + $this->parseResponse(); + return \count($this->items); } /** @@ -94,6 +104,7 @@ public function count(): int */ public function getResourceId(): string { + $this->parseResponse(); return $this->resourceId; } @@ -102,6 +113,7 @@ public function getResourceId(): string */ public function isIgnoreCase(): bool { + $this->parseResponse(); return $this->ignoreCase; } @@ -110,6 +122,15 @@ public function isIgnoreCase(): bool */ public function getInitializedOn(): string { + $this->parseResponse(); return $this->initializedOn; } + + /** + * @return string + */ + public function getUpdatedSinceInit(): string + { + return $this->updatedSinceInit; + } } diff --git a/src/QueryType/ManagedResources/Result/Synonyms/ManagedMap.php b/src/QueryType/ManagedResources/Result/Synonyms/Synonyms.php similarity index 62% rename from src/QueryType/ManagedResources/Result/Synonyms/ManagedMap.php rename to src/QueryType/ManagedResources/Result/Synonyms/Synonyms.php index aeb723ada..e010035d6 100644 --- a/src/QueryType/ManagedResources/Result/Synonyms/ManagedMap.php +++ b/src/QueryType/ManagedResources/Result/Synonyms/Synonyms.php @@ -3,8 +3,10 @@ namespace Solarium\QueryType\ManagedResources\Result\Synonyms; - -class ManagedMap +/** + * Synonym result. + */ +class Synonyms { /** * @var string @@ -14,9 +16,21 @@ class ManagedMap /** * @var array */ - protected $synonyms; + protected $synonyms = []; /** + * Synonyms constructor. + * @param string $term + * @param $synonyms + */ + public function __construct($term, $synonyms) + { + $this->term = $term; + $this->synonyms = $synonyms; + } + + /** + * Set the term * @return string */ public function getTerm(): string @@ -41,10 +55,13 @@ public function getSynonyms(): array } /** + * Sets the synonyms. To set a list of symmetric synonyms leave the term empty. * @param array $synonyms */ public function setSynonyms(array $synonyms) { $this->synonyms = $synonyms; } + + } \ No newline at end of file diff --git a/tests/Integration/AbstractTechproductsTest.php b/tests/Integration/AbstractTechproductsTest.php index e879da0c9..fe5ca0a4a 100644 --- a/tests/Integration/AbstractTechproductsTest.php +++ b/tests/Integration/AbstractTechproductsTest.php @@ -7,6 +7,7 @@ use Solarium\Component\QueryTraits\TermsTrait; use Solarium\Component\Result\Terms\Result; use Solarium\Core\Client\ClientInterface; +use Solarium\QueryType\ManagedResources\Query\Stopwords\Command\Add; use Solarium\QueryType\Select\Query\Query as SelectQuery; use Solarium\QueryType\Select\Result\Document; @@ -492,6 +493,104 @@ public function testExtractTextOnly() $content = $json->{$fileName}; $this->assertSame('PDF Test', trim($content), 'Can not extract the plain content from the file'); } + + public function testManagedStopwords() + { + $query = $this->client->createManagedStopwords(); + $query->setName('english'); + $term = 'the'; + + // Add stopwords + $add = new AddStopwords(); + $add->setStopwords([$term]); + $query->setCommand($add); + $result = $this->client->execute($query); + $this->assertEquals(200, $result->getResponse()->getStatusCode()); + + // Check if single stopword exist + $exists = new ExistsStopwords(); + $exists->setTerm($term); + $query->setCommand($exists); + $result = $this->client->execute($query); + $this->assertEquals(200, $result->getResponse()->getStatusCode()); + + // List stopwords + $query->removeCommand(); + $result = $this->client->execute($query); + $this->assertEquals(200, $result->getResponse()->getStatusCode()); + $items = $result->getItems(); + $this->assertCount(1, $items); + $this->assertSame($term, $items[0]); + + // Delete stopword + $delete = new DeleteStopwords(); + $delete->setTerm($term); + $query->setCommand($delete); + $result = $this->client->execute($query); + $this->assertEquals(200, $result->getResponse()->getStatusCode()); + + // Check if stopword is gone + $this->expectExceptionCode(404); + $exists = new ExistsStopwords(); + $exists->setTerm($term); + $query->setCommand($exists); + $this->client->execute($query); + } + + public function testManagedSynonyms() + { + $query = $this->client->createManagedSynonyms(); + $query->setName('english'); + $term = 'mad'; + + // Add synonyms + $add = new AddSynonyms(); + $synonyms = new Synonyms(); + $synonyms->setTerm($term); + $synonyms->setSynonyms(['angry', 'upset']); + $add->setSynonyms($synonyms); + $query->setCommand($add); + $result = $this->client->execute($query); + $this->assertEquals(200, $result->getResponse()->getStatusCode()); + + // Check if single synonym exist + $exists = new ExistsSynonyms(); + $exists->setTerm($term); + $query->setCommand($exists); + $result = $this->client->execute($query); + $this->assertEquals(200, $result->getResponse()->getStatusCode()); + $this->assertSame(['mad' => ['angry', 'upset']], $result->getData()); + + // List synonyms + $query->removeCommand(); + $result = $this->client->execute($query); + $this->assertEquals(200, $result->getResponse()->getStatusCode()); + $items = $result->getItems(); + $this->assertCount(1, $items); + $this->assertSame($term, $items[0]->getTerm()); + + // Delete synonyms + $delete = new DeleteSynonyms(); + $delete->setTerm($term); + $query->setCommand($delete); + $result = $this->client->execute($query); + $this->assertEquals(200, $result->getResponse()->getStatusCode()); + + // Check if synonyms are gone + $this->expectExceptionCode(404); + $exists = new ExistsSynonyms(); + $exists->setTerm($term); + $query->setCommand($exists); + $this->client->execute($query); + } + + public function testManagedResources() + { + $query = $this->client->createManagedResources(); + $result = $this->client->execute($query); + $items = $result->getItems(); + $this->assertCount(2, $items); + } } class TestQuery extends SelectQuery diff --git a/tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php b/tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php index af65a26b2..396e93a94 100644 --- a/tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php +++ b/tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php @@ -67,7 +67,7 @@ public function testAdd() $command = new AddCommand(); $command->setStopwords($stopwords); $this->query->setName("dutch"); - $this->query->addCommand($command); + $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_PUT, $request->getMethod()); $this->assertEquals($stopwords, $command->getStopwords()); @@ -81,7 +81,7 @@ public function testDelete() $command = new DeleteCommand(); $command->setTerm($term); $this->query->setName("dutch"); - $this->query->addCommand($command); + $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_DELETE, $request->getMethod()); $this->assertEquals($term, $command->getTerm()); @@ -94,7 +94,7 @@ public function testExists() $command = new ExistsCommand(); $command->setTerm('de'); $this->query->setName("dutch"); - $this->query->addCommand($command); + $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_GET, $request->getMethod()); $this->assertEquals($term, $command->getTerm()); diff --git a/tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php b/tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php index ca0579812..e618d23f8 100644 --- a/tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php +++ b/tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php @@ -64,11 +64,11 @@ public function testAdd() { $synonyms = new SynonymsQuery\Synonyms(); $synonyms->setTerm('mad'); - $synonyms->setSynonyms(array('angry', 'upset')); + $synonyms->setSynonyms(['angry', 'upset']); $command = new AddCommand(); $command->setSynonyms($synonyms); $this->query->setName("dutch"); - $this->query->addCommand($command); + $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_PUT, $request->getMethod()); $this->assertEquals('{"mad":["angry","upset"]}', $request->getRawData()); @@ -77,11 +77,11 @@ public function testAdd() public function testAddSymmytrical() { $synonyms = new SynonymsQuery\Synonyms(); - $synonyms->setSynonyms(array('funny', 'entertaining', 'whimsical', 'jocular')); + $synonyms->setSynonyms(['funny', 'entertaining', 'whimsical', 'jocular']); $command = new AddCommand(); $command->setSynonyms($synonyms); $this->query->setName("dutch"); - $this->query->addCommand($command); + $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_PUT, $request->getMethod()); $this->assertEquals('["funny","entertaining","whimsical","jocular"]', $request->getRawData()); @@ -93,7 +93,7 @@ public function testDelete() $command = new DeleteCommand(); $command->setTerm($term); $this->query->setName("dutch"); - $this->query->addCommand($command); + $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_DELETE, $request->getMethod()); $this->assertEquals($term, $command->getTerm()); @@ -106,7 +106,7 @@ public function testExists() $command = new ExistsCommand(); $command->setTerm($term); $this->query->setName("dutch"); - $this->query->addCommand($command); + $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_GET, $request->getMethod()); $this->assertEquals($term, $command->getTerm()); From bd7f6bef82f4965c5a29e41235857dc1fbf8d5eb Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 10 Sep 2018 13:01:46 +0200 Subject: [PATCH 07/22] Added managed resources createQuery convenience methods to Client. --- src/Core/Client/Client.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Core/Client/Client.php b/src/Core/Client/Client.php index fdbd92bee..8d94934a2 100644 --- a/src/Core/Client/Client.php +++ b/src/Core/Client/Client.php @@ -1208,6 +1208,42 @@ public function createRealtimeGet($options = null) return $this->createQuery(self::QUERY_REALTIME_GET, $options); } + /** + * Create a managed resources query instance. + * + * @param mixed $options + * + * @return \Solarium\QueryType\ManagedResources\Query\Resources + */ + public function createManagedResources($options = null) + { + return $this->createQuery(self::QUERY_MANAGED_RESOURCES, $options); + } + + /** + * Create a managed resources query instance. + * + * @param mixed $options + * + * @return \Solarium\QueryType\ManagedResources\Query\Stopwords + */ + public function createManagedStopwords($options = null) + { + return $this->createQuery(self::QUERY_MANAGED_STOPWORDS, $options); + } + + /** + * Create a managed resources query instance. + * + * @param mixed $options + * + * @return \Solarium\QueryType\ManagedResources\Query\Synonyms + */ + public function createManagedSynonyms($options = null) + { + return $this->createQuery(self::QUERY_MANAGED_SYNONYMS, $options); + } + /** * Initialization hook. */ From 94b40071fbe99d83ea331d15ed4df0caecf8ece3 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 8 Oct 2018 10:29:47 +0200 Subject: [PATCH 08/22] Resource type --- .../Result/Resources/Resource.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/QueryType/ManagedResources/Result/Resources/Resource.php b/src/QueryType/ManagedResources/Result/Resources/Resource.php index 6ae806311..03d88626a 100644 --- a/src/QueryType/ManagedResources/Result/Resources/Resource.php +++ b/src/QueryType/ManagedResources/Result/Resources/Resource.php @@ -19,6 +19,16 @@ class Resource */ protected $class; + /** + * Resource type stopwords. + */ + const TYPE_STOPWORDS = 'stopwords'; + + /** + * Resource type synonyms. + */ + const TYPE_SYNONYMS = 'synonyms'; + /** * Resource constructor. * @@ -79,4 +89,23 @@ public function setClass(string $class) { $this->class = $class; } + + /* + * Returns the type: 'stopwords', 'synonyms' or '' if unknown. + * + * @return string + */ + public function getType(): string + { + if(strncmp($this->resourceId, '/schema/analysis/stopwords', strlen('/schema/analysis/stopwords')) === 0) + { + return self::TYPE_STOPWORDS; + } + elseif (strncmp($this->resourceId, '/schema/analysis/synonyms', strlen('/schema/analysis/synonyms')) === 0) + { + return self::TYPE_SYNONYMS; + } + + return ''; + } } \ No newline at end of file From 1e9e3c508cba220ce9f7f11ad5c1c7f7bcd9c087 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Tue, 9 Oct 2018 09:18:12 +0200 Subject: [PATCH 09/22] Added missing imports. --- tests/Integration/AbstractTechproductsTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Integration/AbstractTechproductsTest.php b/tests/Integration/AbstractTechproductsTest.php index b7a120ec5..ec573b71b 100644 --- a/tests/Integration/AbstractTechproductsTest.php +++ b/tests/Integration/AbstractTechproductsTest.php @@ -8,7 +8,13 @@ use Solarium\Component\Result\Terms\Result; use Solarium\Core\Client\ClientInterface; use Solarium\Exception\HttpException; -use Solarium\QueryType\ManagedResources\Query\Stopwords\Command\Add; +use Solarium\QueryType\ManagedResources\Query\Stopwords\Command\Add as AddStopwords; +use Solarium\QueryType\ManagedResources\Query\Stopwords\Command\Delete as DeleteStopwords; +use Solarium\QueryType\ManagedResources\Query\Stopwords\Command\Exists as ExistsStopwords; +use Solarium\QueryType\ManagedResources\Query\Synonyms\Command\Add as AddSynonyms; +use Solarium\QueryType\ManagedResources\Query\Synonyms\Command\Delete as DeleteSynonyms; +use Solarium\QueryType\ManagedResources\Query\Synonyms\Command\Exists as ExistsSynonyms; +use Solarium\QueryType\ManagedResources\Query\Synonyms\Synonyms; use Solarium\QueryType\Select\Query\Query as SelectQuery; use Solarium\QueryType\Select\Result\Document; From 065e032a47be8e5d95d4bcab164e4953c11d2db6 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Tue, 9 Oct 2018 09:28:30 +0200 Subject: [PATCH 10/22] Added and moved existing comments. --- tests/Integration/AbstractTechproductsTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Integration/AbstractTechproductsTest.php b/tests/Integration/AbstractTechproductsTest.php index ec573b71b..008239dd9 100644 --- a/tests/Integration/AbstractTechproductsTest.php +++ b/tests/Integration/AbstractTechproductsTest.php @@ -675,8 +675,10 @@ public function testManagedStopwords() $result = $this->client->execute($query); $this->assertEquals(200, $result->getResponse()->getStatusCode()); - // List stopwords + // We need to remove the current command in order to have no command. Having no command lists the items. $query->removeCommand(); + + // List stopwords $result = $this->client->execute($query); $this->assertEquals(200, $result->getResponse()->getStatusCode()); $items = $result->getItems(); @@ -722,8 +724,10 @@ public function testManagedSynonyms() $this->assertEquals(200, $result->getResponse()->getStatusCode()); $this->assertSame(['mad' => ['angry', 'upset']], $result->getData()); - // List synonyms + // We need to remove the current command in order to have no command. Having no command lists the items. $query->removeCommand(); + + // List synonyms $result = $this->client->execute($query); $this->assertEquals(200, $result->getResponse()->getStatusCode()); $items = $result->getItems(); From 276fad1af9411e5c75f988b2e39620a28afcb1c7 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Tue, 9 Oct 2018 09:28:51 +0200 Subject: [PATCH 11/22] Some cleanup. --- src/QueryType/ManagedResources/RequestBuilder/Stopwords.php | 2 +- src/QueryType/ManagedResources/RequestBuilder/Synonyms.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php b/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php index c7983dc2c..65f798c40 100644 --- a/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php +++ b/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php @@ -21,7 +21,7 @@ class Stopwords extends BaseRequestBuilder { public function build(QueryInterface $query) { if (empty($query->getName())) { - throw new \Solarium\Exception\RuntimeException("Name of the resource is not set in the query."); + throw new \Solarium\Exception\RuntimeException("Name of the stopwords resource is not set in the query."); } $request = parent::build($query); diff --git a/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php b/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php index 6bfdbe018..bf2461f17 100644 --- a/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php +++ b/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php @@ -9,7 +9,6 @@ use Solarium\QueryType\ManagedResources\Query\Synonyms as SynonymsQuery; use Solarium\QueryType\ManagedResources\Query\Synonyms\Command\AbstractCommand; - class Synonyms extends BaseRequestBuilder { /** From dc093e4e0fcfef4cd2b455fde3301831771733ea Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 22 Oct 2018 10:27:16 +0200 Subject: [PATCH 12/22] Cleaned up code. --- src/QueryType/ManagedResources/Query/Resources.php | 3 ++- src/QueryType/ManagedResources/Query/Stopwords.php | 3 ++- .../ManagedResources/Query/Stopwords/Command/Add.php | 2 -- src/QueryType/ManagedResources/Query/Synonyms.php | 3 ++- .../ManagedResources/RequestBuilder/Resources.php | 3 ++- .../ManagedResources/RequestBuilder/Stopwords.php | 3 ++- .../ManagedResources/RequestBuilder/Synonyms.php | 3 ++- .../ManagedResources/ResponseParser/Resources.php | 4 ++-- .../ManagedResources/ResponseParser/Stopwords.php | 5 ++--- .../ManagedResources/ResponseParser/Synonyms.php | 4 ++-- .../ManagedResources/Result/Stopwords/Stopword.php | 9 --------- .../ManagedResources/RequestBuilder/SynonymsTest.php | 2 +- .../ManagedResources/ResponseParser/StopwordsTest.php | 1 - .../ManagedResources/ResponseParser/SynonymsTest.php | 1 - 14 files changed, 19 insertions(+), 27 deletions(-) delete mode 100644 src/QueryType/ManagedResources/Result/Stopwords/Stopword.php diff --git a/src/QueryType/ManagedResources/Query/Resources.php b/src/QueryType/ManagedResources/Query/Resources.php index 305685bce..fc2311d77 100644 --- a/src/QueryType/ManagedResources/Query/Resources.php +++ b/src/QueryType/ManagedResources/Query/Resources.php @@ -7,7 +7,8 @@ use Solarium\QueryType\ManagedResources\ResponseParser\Resources as ResponseParser; use Solarium\Core\Query\AbstractQuery; -class Resources extends AbstractQuery { +class Resources extends AbstractQuery +{ /** * Default options. diff --git a/src/QueryType/ManagedResources/Query/Stopwords.php b/src/QueryType/ManagedResources/Query/Stopwords.php index 0d926e09f..38e055ca0 100644 --- a/src/QueryType/ManagedResources/Query/Stopwords.php +++ b/src/QueryType/ManagedResources/Query/Stopwords.php @@ -9,7 +9,8 @@ use Solarium\QueryType\ManagedResources\RequestBuilder\Stopwords as RequestBuilder; use Solarium\QueryType\ManagedResources\ResponseParser\Stopwords as ResponseParser; -class Stopwords extends BaseQuery { +class Stopwords extends BaseQuery +{ /** * Stopwords command add. diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php b/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php index b6c486fa8..07f781d1a 100644 --- a/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php +++ b/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php @@ -1,11 +1,9 @@ expectException(\Solarium\Exception\RuntimeException::class); - $request = $this->builder->build($this->query); + $this->builder->build($this->query); } public function testAdd() diff --git a/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php b/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php index 740f66b1b..458709a0b 100644 --- a/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php +++ b/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php @@ -6,7 +6,6 @@ use PHPUnit\Framework\TestCase; use Solarium\Core\Client\Response; use Solarium\QueryType\ManagedResources\Query\Stopwords as StopwordsQuery; -use Solarium\QueryType\ManagedResources\Result\Stopwords; class StopwordsTest extends TestCase { diff --git a/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php b/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php index c323aa400..c4d8820c7 100644 --- a/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php +++ b/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php @@ -6,7 +6,6 @@ use PHPUnit\Framework\TestCase; use Solarium\Core\Client\Response; use Solarium\QueryType\ManagedResources\Query\Synonyms as SynonymsQuery; -use Solarium\QueryType\ManagedResources\Result\Synonyms; class SynonymsTest extends TestCase { From 010be0f8b456ba332237e94678bacddc29f9721e Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 22 Oct 2018 11:01:51 +0200 Subject: [PATCH 13/22] Added phpdocs. --- .../ManagedResources/RequestBuilder/Resources.php | 10 ---------- .../ManagedResources/RequestBuilder/Stopwords.php | 4 ++++ .../ManagedResources/RequestBuilder/Synonyms.php | 4 ++++ 3 files changed, 8 insertions(+), 10 deletions(-) delete mode 100644 src/QueryType/ManagedResources/RequestBuilder/Resources.php diff --git a/src/QueryType/ManagedResources/RequestBuilder/Resources.php b/src/QueryType/ManagedResources/RequestBuilder/Resources.php deleted file mode 100644 index 828c1f2b2..000000000 --- a/src/QueryType/ManagedResources/RequestBuilder/Resources.php +++ /dev/null @@ -1,10 +0,0 @@ -setMethod($command->getRequestMethod()); diff --git a/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php b/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php index 543791fe3..169149df4 100644 --- a/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php +++ b/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php @@ -39,6 +39,10 @@ public function build(QueryInterface $query) return $request; } + /** + * @param Request $request + * @param AbstractCommand $command + */ protected function buildCommand(Request $request, AbstractCommand $command) { $request->setMethod($command->getRequestMethod()); From f19c76cf0ad55ce829e725362855d6ac74e2de3c Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 22 Oct 2018 12:45:02 +0200 Subject: [PATCH 14/22] Accidently deleted file, brought it back. --- .../ManagedResources/RequestBuilder/Resources.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/QueryType/ManagedResources/RequestBuilder/Resources.php diff --git a/src/QueryType/ManagedResources/RequestBuilder/Resources.php b/src/QueryType/ManagedResources/RequestBuilder/Resources.php new file mode 100644 index 000000000..4a5dff09b --- /dev/null +++ b/src/QueryType/ManagedResources/RequestBuilder/Resources.php @@ -0,0 +1,10 @@ + Date: Mon, 10 Sep 2018 12:59:31 +0200 Subject: [PATCH 15/22] Added missing PUT data and headers. --- src/Core/Client/Adapter/Curl.php | 8 ++++++++ src/Core/Client/Adapter/PeclHttp.php | 12 ++++++++++++ src/Core/Client/Adapter/Zend2Http.php | 8 +++++++- src/Core/Client/Adapter/ZendHttp.php | 7 +++++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Core/Client/Adapter/Curl.php b/src/Core/Client/Adapter/Curl.php index 55fc88a14..f44b0fa76 100644 --- a/src/Core/Client/Adapter/Curl.php +++ b/src/Core/Client/Adapter/Curl.php @@ -136,6 +136,14 @@ public function createHandle($request, $endpoint) curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'DELETE'); } elseif (Request::METHOD_PUT == $method) { curl_setopt($handler, CURLOPT_CUSTOMREQUEST, 'PUT'); + + if ($request->getFileUpload()) { + $helper = new AdapterHelper(); + $data = $helper->buildUploadBodyFromRequest($request); + curl_setopt($handler, CURLOPT_POSTFIELDS, $data); + } else { + curl_setopt($handler, CURLOPT_POSTFIELDS, $request->getRawData()); + } } else { throw new InvalidArgumentException("unsupported method: $method"); } diff --git a/src/Core/Client/Adapter/PeclHttp.php b/src/Core/Client/Adapter/PeclHttp.php index 5fef12a8f..fb509a09c 100644 --- a/src/Core/Client/Adapter/PeclHttp.php +++ b/src/Core/Client/Adapter/PeclHttp.php @@ -112,6 +112,18 @@ public function toHttpRequest($request, $endpoint) break; case Request::METHOD_PUT: $method = HTTP_METH_PUT; + if ($request->getFileUpload()) { + $httpRequest->addPostFile( + 'content', + $request->getFileUpload(), + 'application/octet-stream; charset=binary' + ); + } else { + $httpRequest->setBody($request->getRawData()); + if (!isset($headers['Content-Type'])) { + $headers['Content-Type'] = 'application/json; charset=utf-8'; + } + } break; default: throw new InvalidArgumentException( diff --git a/src/Core/Client/Adapter/Zend2Http.php b/src/Core/Client/Adapter/Zend2Http.php index 396c37a93..86c06e94a 100644 --- a/src/Core/Client/Adapter/Zend2Http.php +++ b/src/Core/Client/Adapter/Zend2Http.php @@ -160,7 +160,13 @@ public function execute($request, $endpoint) break; case Request::METHOD_PUT: $client->setMethod('PUT'); - $client->setParameterGet($request->getParams()); + if ($request->getFileUpload()) { + $this->prepareFileUpload($client, $request); + } else { + $client->setParameterGet($request->getParams()); + $client->setRawBody($request->getRawData()); + $request->addHeader('Content-Type: application/json; charset=UTF-8'); + } break; default: throw new OutOfBoundsException('Unsupported method: '.$request->getMethod()); diff --git a/src/Core/Client/Adapter/ZendHttp.php b/src/Core/Client/Adapter/ZendHttp.php index 94d92738b..b8f46a6f0 100644 --- a/src/Core/Client/Adapter/ZendHttp.php +++ b/src/Core/Client/Adapter/ZendHttp.php @@ -162,6 +162,13 @@ public function execute($request, $endpoint) case Request::METHOD_PUT: $client->setMethod(\Zend_Http_Client::PUT); $client->setParameterGet($request->getParams()); + if ($request->getFileUpload()) { + $this->prepareFileUpload($client, $request); + } else { + $client->setParameterGet($request->getParams()); + $client->setRawData($request->getRawData()); + $request->addHeader('Content-Type: application/json; charset=UTF-8'); + } break; default: throw new OutOfBoundsException('Unsupported method: '.$request->getMethod()); From 6be9968bd505a95e013d9b2ad46d628f376af9c6 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 22 Oct 2018 17:43:10 +0200 Subject: [PATCH 16/22] Added raw data for PUT requests to Guzzle adapters. --- src/Core/Client/Adapter/Guzzle.php | 4 ++++ src/Core/Client/Adapter/Guzzle3.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Core/Client/Adapter/Guzzle.php b/src/Core/Client/Adapter/Guzzle.php index ce316f0f3..1911f6764 100644 --- a/src/Core/Client/Adapter/Guzzle.php +++ b/src/Core/Client/Adapter/Guzzle.php @@ -103,6 +103,10 @@ public function getGuzzleClient() */ private function getRequestBody(Request $request) { + if (Request::METHOD_PUT == $request->getMethod()) { + return $request->getRawData(); + } + if (Request::METHOD_POST !== $request->getMethod()) { return null; } diff --git a/src/Core/Client/Adapter/Guzzle3.php b/src/Core/Client/Adapter/Guzzle3.php index 76e6f5340..69852baa6 100644 --- a/src/Core/Client/Adapter/Guzzle3.php +++ b/src/Core/Client/Adapter/Guzzle3.php @@ -98,6 +98,10 @@ public function getGuzzleClient() */ private function getRequestBody(Request $request) { + if (Request::METHOD_PUT == $request->getMethod()) { + return $request->getRawData(); + } + if (Request::METHOD_POST !== $request->getMethod()) { return null; } From 30a3c4327507a38f4c835b63baffceef2d88dc61 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 22 Oct 2018 17:44:17 +0200 Subject: [PATCH 17/22] Cleaned ManagedResources query type. --- .../ManagedResources/Query/Resources.php | 14 ++++++++++++++ .../RequestBuilder/Resources.php | 4 ++-- .../ResponseParser/Stopwords.php | 5 +---- .../ResponseParser/Synonyms.php | 9 ++++++--- .../Result/Stopwords/WordSet.php | 19 +------------------ .../Result/Synonyms/SynonymMappings.php | 8 -------- 6 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/QueryType/ManagedResources/Query/Resources.php b/src/QueryType/ManagedResources/Query/Resources.php index fc2311d77..08e2a7d1d 100644 --- a/src/QueryType/ManagedResources/Query/Resources.php +++ b/src/QueryType/ManagedResources/Query/Resources.php @@ -9,6 +9,11 @@ class Resources extends AbstractQuery { + /** + * Fixed name for resources. + * @var string + */ + private $name = 'resources'; /** * Default options. @@ -21,6 +26,15 @@ class Resources extends AbstractQuery 'omitheader' => true, ]; + /** + * Get the name of resources. + * @return string + */ + public function getName(): string + { + return $this->name; + } + /** * Get query type. * diff --git a/src/QueryType/ManagedResources/RequestBuilder/Resources.php b/src/QueryType/ManagedResources/RequestBuilder/Resources.php index 4a5dff09b..828c1f2b2 100644 --- a/src/QueryType/ManagedResources/RequestBuilder/Resources.php +++ b/src/QueryType/ManagedResources/RequestBuilder/Resources.php @@ -1,10 +1,10 @@ addHeaderInfo($data, $parsed); diff --git a/src/QueryType/ManagedResources/ResponseParser/Synonyms.php b/src/QueryType/ManagedResources/ResponseParser/Synonyms.php index e2937de7a..87aa65cf3 100644 --- a/src/QueryType/ManagedResources/ResponseParser/Synonyms.php +++ b/src/QueryType/ManagedResources/ResponseParser/Synonyms.php @@ -5,14 +5,18 @@ use Solarium\Core\Query\AbstractResponseParser as ResponseParserAbstract; use Solarium\Core\Query\ResponseParserInterface; use Solarium\Core\Query\Result\Result; +use Solarium\Core\Query\Result\ResultInterface; +use Solarium\Exception\RuntimeException; class Synonyms extends ResponseParserAbstract implements ResponseParserInterface { /** - * Parse response data. + * Get result data for the response. * - * @param Result $result + * @param ResultInterface $result + * + * @throws RuntimeException * * @return array */ @@ -35,7 +39,6 @@ public function parse($result) $parsed['items'] = $items; $parsed['ignoreCase'] = $synonymMappings['initArgs']['ignoreCase']; $parsed['initializedOn'] = $synonymMappings['initializedOn']; - $parsed['updatedSinceInit'] = $synonymMappings['updatedSinceInit']; } $this->addHeaderInfo($data, $parsed); diff --git a/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php b/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php index 647c3cb81..de1f9c6f1 100644 --- a/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php +++ b/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php @@ -49,6 +49,7 @@ class WordSet extends BaseResult implements \IteratorAggregate, \Countable public function __construct($query, $response) { Result::__construct($query, $response); + $this->parseResponse(); } /** @@ -94,15 +95,6 @@ public function count(): int return count($this->items); } - /** - * @return string - */ - public function getResourceId(): string - { - $this->parseResponse(); - return $this->resourceId; - } - /** * @return bool */ @@ -120,13 +112,4 @@ public function getInitializedOn(): string $this->parseResponse(); return $this->initializedOn; } - - /** - * @return string - */ - public function getUpdatedSinceInit(): string - { - return $this->updatedSinceInit; - } - } diff --git a/src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php b/src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php index e3f4c6351..647f7098c 100644 --- a/src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php +++ b/src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php @@ -125,12 +125,4 @@ public function getInitializedOn(): string $this->parseResponse(); return $this->initializedOn; } - - /** - * @return string - */ - public function getUpdatedSinceInit(): string - { - return $this->updatedSinceInit; - } } From 946d2e8e97b4097ed6ce109dbeb9b7b8dac7dcff Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 22 Oct 2018 17:44:33 +0200 Subject: [PATCH 18/22] Improved tests. --- .../Integration/AbstractTechproductsTest.php | 24 +++++++---- .../QueryType/ManagedResources/QueryTest.php | 2 +- .../ResponseParser/ResourcesTest.php | 16 +++++--- .../ResponseParser/StopwordsTest.php | 15 +++---- .../ResponseParser/SynonymsTest.php | 41 +++++++++++++++---- 5 files changed, 70 insertions(+), 28 deletions(-) diff --git a/tests/Integration/AbstractTechproductsTest.php b/tests/Integration/AbstractTechproductsTest.php index 008239dd9..5a1231182 100644 --- a/tests/Integration/AbstractTechproductsTest.php +++ b/tests/Integration/AbstractTechproductsTest.php @@ -659,7 +659,7 @@ public function testManagedStopwords() { $query = $this->client->createManagedStopwords(); $query->setName('english'); - $term = 'the'; + $term = 'managed_stopword_test'; // Add stopwords $add = new AddStopwords(); @@ -682,8 +682,7 @@ public function testManagedStopwords() $result = $this->client->execute($query); $this->assertEquals(200, $result->getResponse()->getStatusCode()); $items = $result->getItems(); - $this->assertCount(1, $items); - $this->assertSame($term, $items[0]); + $this->assertContains($term, $items); // Delete stopword $delete = new DeleteStopwords(); @@ -704,13 +703,13 @@ public function testManagedSynonyms() { $query = $this->client->createManagedSynonyms(); $query->setName('english'); - $term = 'mad'; + $term = 'managed_synonyms_test'; // Add synonyms $add = new AddSynonyms(); $synonyms = new Synonyms(); $synonyms->setTerm($term); - $synonyms->setSynonyms(['angry', 'upset']); + $synonyms->setSynonyms(['managed_synonym', 'synonym_test']); $add->setSynonyms($synonyms); $query->setCommand($add); $result = $this->client->execute($query); @@ -722,7 +721,7 @@ public function testManagedSynonyms() $query->setCommand($exists); $result = $this->client->execute($query); $this->assertEquals(200, $result->getResponse()->getStatusCode()); - $this->assertSame(['mad' => ['angry', 'upset']], $result->getData()); + $this->assertSame(['managed_synonyms_test' => ['managed_synonym', 'synonym_test']], $result->getData()); // We need to remove the current command in order to have no command. Having no command lists the items. $query->removeCommand(); @@ -731,8 +730,17 @@ public function testManagedSynonyms() $result = $this->client->execute($query); $this->assertEquals(200, $result->getResponse()->getStatusCode()); $items = $result->getItems(); - $this->assertCount(1, $items); - $this->assertSame($term, $items[0]->getTerm()); + $success = false; + foreach ($items as $item) { + if($item->getTerm() === 'managed_synonyms_test') + { + $success = true; + } + } + if(!$success) + { + $this->fail('Couldn\'t find synonym.'); + } // Delete synonyms $delete = new DeleteSynonyms(); diff --git a/tests/QueryType/ManagedResources/QueryTest.php b/tests/QueryType/ManagedResources/QueryTest.php index b4856898e..1315108e6 100644 --- a/tests/QueryType/ManagedResources/QueryTest.php +++ b/tests/QueryType/ManagedResources/QueryTest.php @@ -4,7 +4,7 @@ use PHPUnit\Framework\TestCase; use Solarium\Core\Client\Client; -use Solarium\QueryType\ManagedResources\Query\Resources\Resources as ResourcesQuery; +use Solarium\QueryType\ManagedResources\Query\Resources as ResourcesQuery; class QueryTest extends TestCase { diff --git a/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php b/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php index 29a932147..42b02e452 100644 --- a/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php +++ b/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php @@ -3,8 +3,10 @@ namespace Solarium\Tests\QueryType\ManagedResources\ResponseParser; use PHPUnit\Framework\TestCase; -use Solarium\Core\Query\Result\Result; + +use Solarium\QueryType\ManagedResources\Query\Resources; use Solarium\QueryType\ManagedResources\ResponseParser\Resources as ResourcesResponseParser; +use Solarium\QueryType\ManagedResources\Result\Resources\ResourceList; class ResourcesTest extends TestCase { @@ -29,7 +31,8 @@ public function testParse() ], ]; - $resultStub = $this->createMock(Result::class); + $query = new Resources(); + $resultStub = $this->createMock(ResourceList::class); $resultStub->expects($this->once()) ->method('getData') ->will($this->returnValue($data)); @@ -39,9 +42,12 @@ public function testParse() $result = $parser->parse($resultStub); $this->assertSame(count($data['managedResources']), count($result['items'])); - $this->assertSame('managedResources', $result['items']->getName()); - $this->assertSame('/schema/analysis/stopwords/dutch', $result['items']->getItems()[0]['resourceId']); - $this->assertSame('/schema/analysis/synonyms/dutch', $result['items']->getItems()[1]['resourceId']); + $this->assertSame('/schema/analysis/stopwords/dutch', $result['items'][0]->getResourceId()); + $this->assertSame(1, $result['items'][0]->getNumObservers()); + $this->assertSame('org.apache.solr.rest.schema.analysis.ManagedWordSetResource', $result['items'][0]->getClass()); + $this->assertSame('/schema/analysis/synonyms/dutch', $result['items'][1]->getResourceId()); + $this->assertSame(1, $result['items'][1]->getNumObservers()); + $this->assertSame('org.apache.solr.rest.schema.analysis.ManagedSynonymFilterFactory$SynonymManager', $result['items'][1]->getClass()); } } diff --git a/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php b/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php index 458709a0b..f973df015 100644 --- a/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php +++ b/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Solarium\Core\Client\Response; use Solarium\QueryType\ManagedResources\Query\Stopwords as StopwordsQuery; +use Solarium\QueryType\ManagedResources\Result\Stopwords\WordSet; class StopwordsTest extends TestCase { @@ -13,15 +14,15 @@ public function testParse() { $data = '{ "responseHeader":{ "status":0, "QTime":1 }, "wordSet":{ "initArgs":{"ignoreCase":true}, "initializedOn":"2014-03-28T20:53:53.058Z", "managedList":[ "a", "an", "and", "are" ]}}'; - $response = new Response($data, ['HTTP 1.1 200 OK']); - $result = new Stopwords(new StopwordsQuery(), $response); + $query = new StopwordsQuery(); + $result = new WordSet($query, new Response($data, ['HTTP 1.1 200 OK'])); + $parser = new ResponseParser(); + $parsed = $parser->parse($result); - $this->assertSame('200 OK', $result->getResponse()->getStatusMessage()); - $this->assertSame(0, $parsed['status']); - $this->assertSame(1, $parsed['queryTime']); - $this->assertSame('2014-03-28T20:53:53.058Z', $parsed['items']->getInitializedOn()); - $this->assertSame(true, $parsed['items']->isIgnoreCase()); + $this->assertSame('2014-03-28T20:53:53.058Z', $parsed['initializedOn']); + $this->assertTrue($parsed['ignoreCase']); + $this->assertEquals([0 => 'a',1 => 'an',2 => 'and',3 => 'are'], $parsed['items']); } } diff --git a/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php b/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php index c4d8820c7..5a9dcdbe1 100644 --- a/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php +++ b/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php @@ -6,6 +6,8 @@ use PHPUnit\Framework\TestCase; use Solarium\Core\Client\Response; use Solarium\QueryType\ManagedResources\Query\Synonyms as SynonymsQuery; +use Solarium\QueryType\ManagedResources\Result\Synonyms\Synonyms; +use Solarium\QueryType\ManagedResources\Result\Synonyms\SynonymMappings; class SynonymsTest extends TestCase { @@ -13,16 +15,41 @@ public function testParse() { $data = '{ "responseHeader":{ "status":0, "QTime":3}, "synonymMappings":{ "initArgs":{ "ignoreCase":true, "format":"solr"}, "initializedOn":"2014-12-16T22:44:05.33Z", "managedMap":{ "GB": ["GiB", "Gigabyte"], "TV": ["Television"], "happy": ["glad", "joyful"]}}}'; - $response = new Response($data, ['HTTP 1.1 200 OK']); - $result = new Synonyms(new SynonymsQuery(), $response); + $query = new SynonymsQuery(); + $result = new SynonymMappings($query, new Response($data, ['HTTP 1.1 200 OK'])); $parser = new ResponseParser(); + $parsed = $parser->parse($result); - $this->assertSame('200 OK', $result->getResponse()->getStatusMessage()); - $this->assertSame(0, $parsed['status']); - $this->assertSame(3, $parsed['queryTime']); - $this->assertSame('2014-12-16T22:44:05.33Z', $parsed['items']->getInitializedOn()); - $this->assertSame(true, $parsed['items']->isIgnoreCase()); + $this->assertSame('2014-12-16T22:44:05.33Z', $parsed['initializedOn']); + $this->assertTrue($parsed['ignoreCase']); + + $synonyms = + [ + 0 => + new Synonyms('GB', + [ + 0 => 'GiB', + 1 => 'Gigabyte' + ] + ) + , + 1 => + new Synonyms('TV', + [ + 0 => 'Television' + ] + ), + 2 => + new Synonyms('happy', + [ + 0 => 'glad', + 1 => 'joyful', + ] + ), + ]; + + $this->assertEquals($synonyms, $parsed['items']); } } From 9f48fecc6aa74d1c400cf5993ea2cab0c2569775 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 29 Oct 2018 17:40:26 +0100 Subject: [PATCH 19/22] Missing PUT method handling. --- src/Core/Client/Adapter/Http.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Core/Client/Adapter/Http.php b/src/Core/Client/Adapter/Http.php index 7715711c8..eb778ce80 100644 --- a/src/Core/Client/Adapter/Http.php +++ b/src/Core/Client/Adapter/Http.php @@ -113,6 +113,18 @@ public function createContext($request, $endpoint) } } } + elseif(Request::METHOD_PUT == $method) { + $data = $request->getRawData(); + if (null !== $data) { + stream_context_set_option( + $context, + 'http', + 'content', + $data + ); + $request->addHeader('Content-Type: application/json; charset=UTF-8'); + } + } $headers = $request->getHeaders(); if (count($headers) > 0) { From 40ec800e366effb272d07fbd855c53b212ec4813 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 29 Oct 2018 17:56:30 +0100 Subject: [PATCH 20/22] Changed expected exception assertion. --- tests/Integration/AbstractTechproductsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Integration/AbstractTechproductsTest.php b/tests/Integration/AbstractTechproductsTest.php index 5a1231182..49e3921f2 100644 --- a/tests/Integration/AbstractTechproductsTest.php +++ b/tests/Integration/AbstractTechproductsTest.php @@ -692,7 +692,7 @@ public function testManagedStopwords() $this->assertEquals(200, $result->getResponse()->getStatusCode()); // Check if stopword is gone - $this->expectExceptionCode(404); + $this->expectException(HttpException::class); $exists = new ExistsStopwords(); $exists->setTerm($term); $query->setCommand($exists); @@ -750,7 +750,7 @@ public function testManagedSynonyms() $this->assertEquals(200, $result->getResponse()->getStatusCode()); // Check if synonyms are gone - $this->expectExceptionCode(404); + $this->expectException(HttpException::class); $exists = new ExistsSynonyms(); $exists->setTerm($term); $query->setCommand($exists); From 96df858cf81e0222c9ff488a9e54db16cfe1116f Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 29 Oct 2018 18:01:55 +0100 Subject: [PATCH 21/22] Removed empty test. --- tests/QueryType/ManagedResources/QueryTest.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/QueryType/ManagedResources/QueryTest.php b/tests/QueryType/ManagedResources/QueryTest.php index 1315108e6..db5bf8db0 100644 --- a/tests/QueryType/ManagedResources/QueryTest.php +++ b/tests/QueryType/ManagedResources/QueryTest.php @@ -35,10 +35,4 @@ public function testGetRequestBuilder() $this->query->getRequestBuilder() ); } - - public function testQuery() - { - // TODO implement - //$this->query-> - } } From 88aa75e5e3b48e79871ea1993f5868cae0586e66 Mon Sep 17 00:00:00 2001 From: Jeroen Steggink Date: Mon, 29 Oct 2018 18:20:10 +0100 Subject: [PATCH 22/22] Style fixes. --- src/Core/Client/Adapter/Http.php | 3 +-- .../ManagedResources/Query/Resources.php | 4 +++- .../ManagedResources/Query/Stopwords.php | 6 ++++-- .../Query/Stopwords/Command/Add.php | 2 +- .../Query/Stopwords/Command/Delete.php | 4 +--- .../Query/Stopwords/Command/Exists.php | 4 +--- .../Query/Stopwords/Stopword.php | 6 +----- .../ManagedResources/Query/Synonyms.php | 11 +++++++---- .../Query/Synonyms/Command/Add.php | 11 ++++------- .../Query/Synonyms/Command/Delete.php | 4 +--- .../Query/Synonyms/Command/Exists.php | 4 +--- .../Query/Synonyms/Synonyms.php | 10 ++++------ .../RequestBuilder/Resources.php | 3 +-- .../RequestBuilder/Stopwords.php | 12 +++++------- .../RequestBuilder/Synonyms.php | 12 +++++------- .../ResponseParser/Resources.php | 5 ++--- .../ResponseParser/Stopwords.php | 7 +++---- .../ResponseParser/Synonyms.php | 7 +++---- .../Result/Resources/Resource.php | 16 ++++++---------- .../Result/Resources/ResourceList.php | 2 +- .../Result/Stopwords/WordSet.php | 6 ++++-- .../Result/Synonyms/SynonymMappings.php | 6 +++++- .../Result/Synonyms/Synonyms.php | 10 +++++----- tests/Integration/AbstractTechproductsTest.php | 6 ++---- .../RequestBuilder/ResourcesTest.php | 1 - .../RequestBuilder/StopwordsTest.php | 13 ++++++------- .../RequestBuilder/SynonymsTest.php | 11 +++++------ .../ResponseParser/ResourcesTest.php | 2 -- .../ResponseParser/StopwordsTest.php | 2 +- .../ResponseParser/SynonymsTest.php | 17 ++++++----------- 30 files changed, 89 insertions(+), 118 deletions(-) diff --git a/src/Core/Client/Adapter/Http.php b/src/Core/Client/Adapter/Http.php index eb778ce80..bbdcf9bd8 100644 --- a/src/Core/Client/Adapter/Http.php +++ b/src/Core/Client/Adapter/Http.php @@ -112,8 +112,7 @@ public function createContext($request, $endpoint) $request->addHeader('Content-Type: text/xml; charset=UTF-8'); } } - } - elseif(Request::METHOD_PUT == $method) { + } elseif (Request::METHOD_PUT == $method) { $data = $request->getRawData(); if (null !== $data) { stream_context_set_option( diff --git a/src/QueryType/ManagedResources/Query/Resources.php b/src/QueryType/ManagedResources/Query/Resources.php index 08e2a7d1d..f75bf642e 100644 --- a/src/QueryType/ManagedResources/Query/Resources.php +++ b/src/QueryType/ManagedResources/Query/Resources.php @@ -11,6 +11,7 @@ class Resources extends AbstractQuery { /** * Fixed name for resources. + * * @var string */ private $name = 'resources'; @@ -28,6 +29,7 @@ class Resources extends AbstractQuery /** * Get the name of resources. + * * @return string */ public function getName(): string @@ -64,4 +66,4 @@ public function getResponseParser(): ResponseParser { return new ResponseParser(); } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/Query/Stopwords.php b/src/QueryType/ManagedResources/Query/Stopwords.php index 38e055ca0..807b974ca 100644 --- a/src/QueryType/ManagedResources/Query/Stopwords.php +++ b/src/QueryType/ManagedResources/Query/Stopwords.php @@ -11,7 +11,6 @@ class Stopwords extends BaseQuery { - /** * Stopwords command add. */ @@ -29,6 +28,7 @@ class Stopwords extends BaseQuery /** * Name of the stopwords resource. + * * @var string */ protected $name = ''; @@ -94,6 +94,7 @@ public function getResponseParser(): ResponseParser /** * Get the name of the stopwords resource. + * * @return string */ public function getName(): string @@ -103,6 +104,7 @@ public function getName(): string /** * Set the name of the stopwords resource. + * * @param string $name */ public function setName(string $name) @@ -168,4 +170,4 @@ public function removeCommand(): self return $this; } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php b/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php index 07f781d1a..fec38c076 100644 --- a/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php +++ b/src/QueryType/ManagedResources/Query/Stopwords/Command/Add.php @@ -73,4 +73,4 @@ public function getTerm(): string { return ''; } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php b/src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php index 051dd862b..adbb8672a 100644 --- a/src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php +++ b/src/QueryType/ManagedResources/Query/Stopwords/Command/Delete.php @@ -1,9 +1,7 @@ term = $term; } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php b/src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php index 2386f3d38..ba3d3fab9 100644 --- a/src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php +++ b/src/QueryType/ManagedResources/Query/Stopwords/Command/Exists.php @@ -1,9 +1,7 @@ term = $term; } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/Query/Stopwords/Stopword.php b/src/QueryType/ManagedResources/Query/Stopwords/Stopword.php index 6fee5b01c..d74d3edec 100644 --- a/src/QueryType/ManagedResources/Query/Stopwords/Stopword.php +++ b/src/QueryType/ManagedResources/Query/Stopwords/Stopword.php @@ -1,9 +1,7 @@ term = $term; } - - -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/Query/Synonyms.php b/src/QueryType/ManagedResources/Query/Synonyms.php index ed33ff41c..6c2f0d0e2 100644 --- a/src/QueryType/ManagedResources/Query/Synonyms.php +++ b/src/QueryType/ManagedResources/Query/Synonyms.php @@ -1,6 +1,5 @@ getSynonyms() !== null && !empty($this->getSynonyms()->getSynonyms())) - { - if(strlen(trim($this->getSynonyms()->getTerm())) != 0) { - return json_encode(array($this->getSynonyms()->getTerm() => $this->getSynonyms()->getSynonyms())); + if (null !== $this->getSynonyms() && !empty($this->getSynonyms()->getSynonyms())) { + if (0 != strlen(trim($this->getSynonyms()->getTerm()))) { + return json_encode([$this->getSynonyms()->getTerm() => $this->getSynonyms()->getSynonyms()]); } return json_encode($this->getSynonyms()->getSynonyms()); @@ -81,4 +78,4 @@ public function getTerm(): string { return ''; } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php b/src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php index e8cedf408..2b3c2ab59 100644 --- a/src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php +++ b/src/QueryType/ManagedResources/Query/Synonyms/Command/Delete.php @@ -1,9 +1,7 @@ term = $term; } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php b/src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php index cfdb5fcd0..c1cb91e54 100644 --- a/src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php +++ b/src/QueryType/ManagedResources/Query/Synonyms/Command/Exists.php @@ -1,9 +1,7 @@ term = $term; } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/Query/Synonyms/Synonyms.php b/src/QueryType/ManagedResources/Query/Synonyms/Synonyms.php index 1ac29e93a..6fd421e85 100644 --- a/src/QueryType/ManagedResources/Query/Synonyms/Synonyms.php +++ b/src/QueryType/ManagedResources/Query/Synonyms/Synonyms.php @@ -1,11 +1,9 @@ synonyms = $synonyms; } - - -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/RequestBuilder/Resources.php b/src/QueryType/ManagedResources/RequestBuilder/Resources.php index 828c1f2b2..634bd8db3 100644 --- a/src/QueryType/ManagedResources/RequestBuilder/Resources.php +++ b/src/QueryType/ManagedResources/RequestBuilder/Resources.php @@ -6,5 +6,4 @@ class Resources extends BaseRequestBuilder { - -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php b/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php index 5d877b288..fc28a766d 100644 --- a/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php +++ b/src/QueryType/ManagedResources/RequestBuilder/Stopwords.php @@ -11,7 +11,6 @@ class Stopwords extends BaseRequestBuilder { - /** * Build request for a stopwords query. * @@ -22,16 +21,15 @@ class Stopwords extends BaseRequestBuilder public function build(QueryInterface $query) { if (empty($query->getName())) { - throw new \Solarium\Exception\RuntimeException("Name of the stopwords resource is not set in the query."); + throw new \Solarium\Exception\RuntimeException('Name of the stopwords resource is not set in the query.'); } $request = parent::build($query); $request->setHandler($query->getHandler().$query->getName()); - if ($query->getCommand() !== null) { + if (null !== $query->getCommand()) { $request->addHeader('Content-Type: application/json; charset=utf-8'); $this->buildCommand($request, $query->getCommand()); - } - else { + } else { // Lists all stopwords. $request->setMethod(Request::METHOD_GET); } @@ -40,7 +38,7 @@ public function build(QueryInterface $query) } /** - * @param Request $request + * @param Request $request * @param AbstractCommand $command */ protected function buildCommand(Request $request, AbstractCommand $command) @@ -64,4 +62,4 @@ protected function buildCommand(Request $request, AbstractCommand $command) $request->setMethod($command->getRequestMethod()); } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php b/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php index 169149df4..4f28e26e0 100644 --- a/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php +++ b/src/QueryType/ManagedResources/RequestBuilder/Synonyms.php @@ -11,7 +11,6 @@ class Synonyms extends BaseRequestBuilder { - /** * Build request for a synonyms query. * @@ -22,16 +21,15 @@ class Synonyms extends BaseRequestBuilder public function build(QueryInterface $query) { if (empty($query->getName())) { - throw new \Solarium\Exception\RuntimeException("Name of the synonym resource is not set in the query."); + throw new \Solarium\Exception\RuntimeException('Name of the synonym resource is not set in the query.'); } $request = parent::build($query); $request->setHandler($query->getHandler().$query->getName()); - if ($query->getCommand() !== null) { + if (null !== $query->getCommand()) { $request->addHeader('Content-Type: application/json; charset=utf-8'); $this->buildCommand($request, $query->getCommand()); - } - else { + } else { // Lists all synonyms. $request->setMethod(Request::METHOD_GET); } @@ -40,7 +38,7 @@ public function build(QueryInterface $query) } /** - * @param Request $request + * @param Request $request * @param AbstractCommand $command */ protected function buildCommand(Request $request, AbstractCommand $command) @@ -64,4 +62,4 @@ protected function buildCommand(Request $request, AbstractCommand $command) $request->setMethod($command->getRequestMethod()); } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/ResponseParser/Resources.php b/src/QueryType/ManagedResources/ResponseParser/Resources.php index ce5bbcd81..b80e44051 100644 --- a/src/QueryType/ManagedResources/ResponseParser/Resources.php +++ b/src/QueryType/ManagedResources/ResponseParser/Resources.php @@ -9,7 +9,6 @@ class Resources extends ResponseParserAbstract implements ResponseParserInterface { - /** * Parse response data. * @@ -24,11 +23,11 @@ public function parse($result) $items = []; if (isset($data['managedResources']) && !empty($data['managedResources'])) { - foreach($data['managedResources'] as $resource) { + foreach ($data['managedResources'] as $resource) { $items[] = new Resource($resource); } } return $this->addHeaderInfo($data, ['items' => $items]); } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/ResponseParser/Stopwords.php b/src/QueryType/ManagedResources/ResponseParser/Stopwords.php index 2e0d660c0..4a46c1a02 100644 --- a/src/QueryType/ManagedResources/ResponseParser/Stopwords.php +++ b/src/QueryType/ManagedResources/ResponseParser/Stopwords.php @@ -8,7 +8,6 @@ class Stopwords extends ResponseParserAbstract implements ResponseParserInterface { - /** * Parse response data. * @@ -20,13 +19,13 @@ public function parse($result) { $data = $result->getData(); $wordSet = null; - if(isset($data['wordSet'])) { + if (isset($data['wordSet'])) { $wordSet = $data['wordSet']; } $parsed = []; - if ($wordSet !== null && !empty($wordSet)) { + if (null !== $wordSet && !empty($wordSet)) { $parsed['items'] = $wordSet['managedList']; $parsed['ignoreCase'] = $wordSet['initArgs']['ignoreCase']; $parsed['initializedOn'] = $wordSet['initializedOn']; @@ -36,4 +35,4 @@ public function parse($result) return $parsed; } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/ResponseParser/Synonyms.php b/src/QueryType/ManagedResources/ResponseParser/Synonyms.php index 87aa65cf3..0be9b0a3f 100644 --- a/src/QueryType/ManagedResources/ResponseParser/Synonyms.php +++ b/src/QueryType/ManagedResources/ResponseParser/Synonyms.php @@ -10,7 +10,6 @@ class Synonyms extends ResponseParserAbstract implements ResponseParserInterface { - /** * Get result data for the response. * @@ -24,14 +23,14 @@ public function parse($result) { $data = $result->getData(); $synonymMappings = null; - if(isset($data['synonymMappings'])) { + if (isset($data['synonymMappings'])) { $synonymMappings = $data['synonymMappings']; } $parsed = []; $items = []; - if ($synonymMappings !== null && !empty($synonymMappings)) { + if (null !== $synonymMappings && !empty($synonymMappings)) { foreach ($synonymMappings['managedMap'] as $term => $synonyms) { $items[] = new \Solarium\QueryType\ManagedResources\Result\Synonyms\Synonyms($term, $synonyms); } @@ -45,4 +44,4 @@ public function parse($result) return $parsed; } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/Result/Resources/Resource.php b/src/QueryType/ManagedResources/Result/Resources/Resource.php index 03d88626a..09ec8bdfa 100644 --- a/src/QueryType/ManagedResources/Result/Resources/Resource.php +++ b/src/QueryType/ManagedResources/Result/Resources/Resource.php @@ -36,12 +36,11 @@ class Resource */ public function __construct(array $resource) { - $this->resourceId = $resource['resourceId']; - $this->numObservers = $resource['numObservers']; - $this->class = $resource['class']; + $this->resourceId = $resource['resourceId']; + $this->numObservers = $resource['numObservers']; + $this->class = $resource['class']; } - /** * @return string */ @@ -97,15 +96,12 @@ public function setClass(string $class) */ public function getType(): string { - if(strncmp($this->resourceId, '/schema/analysis/stopwords', strlen('/schema/analysis/stopwords')) === 0) - { + if (0 === strncmp($this->resourceId, '/schema/analysis/stopwords', strlen('/schema/analysis/stopwords'))) { return self::TYPE_STOPWORDS; - } - elseif (strncmp($this->resourceId, '/schema/analysis/synonyms', strlen('/schema/analysis/synonyms')) === 0) - { + } elseif (0 === strncmp($this->resourceId, '/schema/analysis/synonyms', strlen('/schema/analysis/synonyms'))) { return self::TYPE_SYNONYMS; } return ''; } -} \ No newline at end of file +} diff --git a/src/QueryType/ManagedResources/Result/Resources/ResourceList.php b/src/QueryType/ManagedResources/Result/Resources/ResourceList.php index 0a8b68f07..5cb3657ea 100644 --- a/src/QueryType/ManagedResources/Result/Resources/ResourceList.php +++ b/src/QueryType/ManagedResources/Result/Resources/ResourceList.php @@ -47,7 +47,7 @@ public function getName(): string /** * Get all items. * - * @return Resource[] + * @return resource[] */ public function getItems(): array { diff --git a/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php b/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php index de1f9c6f1..f875d16dd 100644 --- a/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php +++ b/src/QueryType/ManagedResources/Result/Stopwords/WordSet.php @@ -3,7 +3,6 @@ namespace Solarium\QueryType\ManagedResources\Result\Stopwords; use Solarium\Core\Query\Result\Result; - use Solarium\Core\Query\Result\QueryType as BaseResult; class WordSet extends BaseResult implements \IteratorAggregate, \Countable @@ -17,18 +16,21 @@ class WordSet extends BaseResult implements \IteratorAggregate, \Countable /** * Whether or not to ignore the case. - * @var boolean + * + * @var bool */ protected $ignoreCase; /** * Datetime when the resource was initialized. + * * @var string */ protected $initializedOn; /** * Datetime when the resource was last updated. + * * @var string */ protected $updatedSinceInit; diff --git a/src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php b/src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php index 647f7098c..047b0dd78 100644 --- a/src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php +++ b/src/QueryType/ManagedResources/Result/Synonyms/SynonymMappings.php @@ -16,24 +16,28 @@ class SynonymMappings extends BaseResult implements \IteratorAggregate, \Countab /** * ResourceId looked up using the managed resources component. + * * @var string */ protected $resourceId; /** * Whether or not to ignore the case. - * @var boolean + * + * @var bool */ protected $ignoreCase; /** * Datetime when the resource was initialized. + * * @var string */ protected $initializedOn; /** * Datetime when the resource was last updated. + * * @var string */ protected $updatedSinceInit; diff --git a/src/QueryType/ManagedResources/Result/Synonyms/Synonyms.php b/src/QueryType/ManagedResources/Result/Synonyms/Synonyms.php index e010035d6..2b98d4341 100644 --- a/src/QueryType/ManagedResources/Result/Synonyms/Synonyms.php +++ b/src/QueryType/ManagedResources/Result/Synonyms/Synonyms.php @@ -1,6 +1,5 @@ synonyms = $synonyms; } - - -} \ No newline at end of file +} diff --git a/tests/Integration/AbstractTechproductsTest.php b/tests/Integration/AbstractTechproductsTest.php index 49e3921f2..dbc4eb149 100644 --- a/tests/Integration/AbstractTechproductsTest.php +++ b/tests/Integration/AbstractTechproductsTest.php @@ -732,13 +732,11 @@ public function testManagedSynonyms() $items = $result->getItems(); $success = false; foreach ($items as $item) { - if($item->getTerm() === 'managed_synonyms_test') - { + if ('managed_synonyms_test' === $item->getTerm()) { $success = true; } } - if(!$success) - { + if (!$success) { $this->fail('Couldn\'t find synonym.'); } diff --git a/tests/QueryType/ManagedResources/RequestBuilder/ResourcesTest.php b/tests/QueryType/ManagedResources/RequestBuilder/ResourcesTest.php index 43afad4d2..6c52c5131 100644 --- a/tests/QueryType/ManagedResources/RequestBuilder/ResourcesTest.php +++ b/tests/QueryType/ManagedResources/RequestBuilder/ResourcesTest.php @@ -6,7 +6,6 @@ use Solarium\QueryType\ManagedResources\Query\Resources as ResourcesQuery; use Solarium\QueryType\ManagedResources\RequestBuilder\Resources as ResourcesRequestBuilder; - class ResourcesTest extends TestCase { /** diff --git a/tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php b/tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php index 396e93a94..ef902aa22 100644 --- a/tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php +++ b/tests/QueryType/ManagedResources/RequestBuilder/StopwordsTest.php @@ -10,7 +10,6 @@ use Solarium\QueryType\ManagedResources\Query\Stopwords\Command\Exists as ExistsCommand; use Solarium\QueryType\ManagedResources\RequestBuilder\Stopwords as StopwordsRequestBuilder; - class StopwordsTest extends TestCase { /** @@ -33,7 +32,7 @@ public function testBuild() { $handler = 'schema/analysis/stopwords/dutch'; - $this->query->setName("dutch"); + $this->query->setName('dutch'); $request = $this->builder->build($this->query); $this->assertEquals( @@ -56,17 +55,17 @@ public function testNoName() public function testQuery() { - $this->query->setName("dutch"); + $this->query->setName('dutch'); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_GET, $request->getMethod()); } public function testAdd() { - $stopwords = array('de'); + $stopwords = ['de']; $command = new AddCommand(); $command->setStopwords($stopwords); - $this->query->setName("dutch"); + $this->query->setName('dutch'); $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_PUT, $request->getMethod()); @@ -80,7 +79,7 @@ public function testDelete() $term = 'de'; $command = new DeleteCommand(); $command->setTerm($term); - $this->query->setName("dutch"); + $this->query->setName('dutch'); $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_DELETE, $request->getMethod()); @@ -93,7 +92,7 @@ public function testExists() $term = 'de'; $command = new ExistsCommand(); $command->setTerm('de'); - $this->query->setName("dutch"); + $this->query->setName('dutch'); $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_GET, $request->getMethod()); diff --git a/tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php b/tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php index 6a3272f95..c90edb2fd 100644 --- a/tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php +++ b/tests/QueryType/ManagedResources/RequestBuilder/SynonymsTest.php @@ -11,7 +11,6 @@ use Solarium\QueryType\ManagedResources\Query\Synonyms\Command\Exists as ExistsCommand; use Solarium\QueryType\ManagedResources\RequestBuilder\Synonyms as SynonymsRequestBuilder; - class SynonymsTest extends TestCase { /** @@ -39,7 +38,7 @@ public function setUp() public function testBuild() { $handler = 'schema/analysis/synonyms/dutch'; - $this->query->setName("dutch"); + $this->query->setName('dutch'); $request = $this->builder->build($this->query); $this->assertEquals( @@ -67,7 +66,7 @@ public function testAdd() $synonyms->setSynonyms(['angry', 'upset']); $command = new AddCommand(); $command->setSynonyms($synonyms); - $this->query->setName("dutch"); + $this->query->setName('dutch'); $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_PUT, $request->getMethod()); @@ -80,7 +79,7 @@ public function testAddSymmytrical() $synonyms->setSynonyms(['funny', 'entertaining', 'whimsical', 'jocular']); $command = new AddCommand(); $command->setSynonyms($synonyms); - $this->query->setName("dutch"); + $this->query->setName('dutch'); $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_PUT, $request->getMethod()); @@ -92,7 +91,7 @@ public function testDelete() $term = 'mad'; $command = new DeleteCommand(); $command->setTerm($term); - $this->query->setName("dutch"); + $this->query->setName('dutch'); $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_DELETE, $request->getMethod()); @@ -105,7 +104,7 @@ public function testExists() $term = 'mad'; $command = new ExistsCommand(); $command->setTerm($term); - $this->query->setName("dutch"); + $this->query->setName('dutch'); $this->query->setCommand($command); $request = $this->builder->build($this->query); $this->assertSame(Request::METHOD_GET, $request->getMethod()); diff --git a/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php b/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php index 42b02e452..b443b0031 100644 --- a/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php +++ b/tests/QueryType/ManagedResources/ResponseParser/ResourcesTest.php @@ -3,7 +3,6 @@ namespace Solarium\Tests\QueryType\ManagedResources\ResponseParser; use PHPUnit\Framework\TestCase; - use Solarium\QueryType\ManagedResources\Query\Resources; use Solarium\QueryType\ManagedResources\ResponseParser\Resources as ResourcesResponseParser; use Solarium\QueryType\ManagedResources\Result\Resources\ResourceList; @@ -49,5 +48,4 @@ public function testParse() $this->assertSame(1, $result['items'][1]->getNumObservers()); $this->assertSame('org.apache.solr.rest.schema.analysis.ManagedSynonymFilterFactory$SynonymManager', $result['items'][1]->getClass()); } - } diff --git a/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php b/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php index f973df015..542c9e59e 100644 --- a/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php +++ b/tests/QueryType/ManagedResources/ResponseParser/StopwordsTest.php @@ -23,6 +23,6 @@ public function testParse() $this->assertSame('2014-03-28T20:53:53.058Z', $parsed['initializedOn']); $this->assertTrue($parsed['ignoreCase']); - $this->assertEquals([0 => 'a',1 => 'an',2 => 'and',3 => 'are'], $parsed['items']); + $this->assertEquals([0 => 'a', 1 => 'an', 2 => 'and', 3 => 'are'], $parsed['items']); } } diff --git a/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php b/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php index 5a9dcdbe1..fc7bcfa78 100644 --- a/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php +++ b/tests/QueryType/ManagedResources/ResponseParser/SynonymsTest.php @@ -26,22 +26,18 @@ public function testParse() $synonyms = [ - 0 => - new Synonyms('GB', + 0 => new Synonyms('GB', [ 0 => 'GiB', - 1 => 'Gigabyte' + 1 => 'Gigabyte', ] - ) - , - 1 => - new Synonyms('TV', + ), + 1 => new Synonyms('TV', [ - 0 => 'Television' + 0 => 'Television', ] ), - 2 => - new Synonyms('happy', + 2 => new Synonyms('happy', [ 0 => 'glad', 1 => 'joyful', @@ -52,4 +48,3 @@ public function testParse() $this->assertEquals($synonyms, $parsed['items']); } } -