From 2e69a4ff890997e9e29b0962231b0b84a4c5a7ab Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 23 Feb 2025 15:57:44 +0000 Subject: [PATCH] Fix ci * Bumps version to 1.1.0-alpha * Bumps minimum MW support to MW 1.39. * Bumps minimum php requirements to php 8.1+. * Adds support for MW 1.42/43. * Adds support for SMW 5.0 --- .github/workflows/ci.yaml | 86 ++++++++++++ .gitmodules | 3 + .phpcs.xml | 44 ++++++ Makefile | 32 +++++ SemanticExternalQueryLookup.php | 5 +- build | 1 + codecov.yml | 2 + composer.json | 54 +++++--- extension.json | 10 +- phpcs.xml | 93 ------------- src/ByHttpRequest/CannedResultArray.php | 29 ++-- src/ByHttpRequest/JsonResponseParser.php | 29 ++-- src/ByHttpRequest/QueryResult.php | 8 +- src/ByHttpRequest/QueryResultFetcher.php | 39 +++--- src/ByHttpRequest/ResponsePropertyList.php | 19 +-- src/ByHttpRequestQueryLookup.php | 13 +- src/DataValueDeserializer.php | 26 ++-- src/DynamicInterwikiPrefixLoader.php | 13 +- src/EmbeddedLinksReplacer.php | 9 +- src/HookRegistry.php | 32 ++--- src/QueryEncoder.php | 28 ++-- src/QueryResultFactory.php | 10 +- .../JsonParseOnFauxHttpResponseTest.php | 35 ++--- .../Integration/I18nJsonFileIntegrityTest.php | 27 ++-- .../ByHttpRequest/CannedResultArrayTest.php | 91 ++++++------ .../ByHttpRequest/JsonResponseParserTest.php | 130 +++++++++--------- .../ByHttpRequest/QueryResultFetcherTest.php | 115 ++++++++-------- .../Unit/ByHttpRequest/QueryResultTest.php | 41 +++--- .../ResponsePropertyListTest.php | 24 ++-- .../Unit/ByHttpRequestQueryLookupTest.php | 32 ++--- .../Unit/DataValueDeserializerTest.php | 33 ++--- .../Unit/DynamicInterwikiPrefixLoaderTest.php | 29 ++-- .../Unit/EmbeddedLinksReplacerTest.php | 49 ++++--- tests/phpunit/Unit/HookRegistryTest.php | 26 ++-- tests/phpunit/Unit/QueryEncoderTest.php | 72 +++++----- tests/phpunit/Unit/QueryResultFactoryTest.php | 18 +-- 36 files changed, 650 insertions(+), 657 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .gitmodules create mode 100644 .phpcs.xml create mode 100644 Makefile create mode 160000 build create mode 100644 codecov.yml delete mode 100644 phpcs.xml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..c279b05 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,86 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + workflow_dispatch: + +jobs: + + test: + + runs-on: ubuntu-22.04 + continue-on-error: ${{ matrix.experimental }} + + strategy: + matrix: + include: + - mediawiki_version: '1.39' + smw_version: dev-master + php_version: 8.1 + database_type: mysql + database_image: "mariadb:10" + coverage: false + experimental: false + - mediawiki_version: '1.40' + smw_version: dev-master + php_version: 8.1 + database_type: mysql + database_image: "mariadb:11.2" + coverage: true + experimental: false + - mediawiki_version: '1.41' + smw_version: dev-master + php_version: 8.1 + database_type: mysql + database_image: "mariadb:11.2" + coverage: false + experimental: false + - mediawiki_version: '1.42' + smw_version: dev-master + php_version: 8.1 + database_type: mysql + database_image: "mariadb:11.2" + coverage: false + experimental: false + - mediawiki_version: '1.43' + smw_version: dev-master + php_version: 8.1 + database_type: mysql + database_image: "mariadb:11.2" + coverage: false + experimental: false + + env: + MW_VERSION: ${{ matrix.mediawiki_version }} + SMW_VERSION: ${{ matrix.smw_version }} + PHP_VERSION: ${{ matrix.php_version }} + DB_TYPE: ${{ matrix.database_type }} + DB_IMAGE: ${{ matrix.database_image }} + + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Update submodules + run: git submodule update --init --remote + + - name: Run tests + run: make ci + if: matrix.coverage == false + + - name: Run tests with coverage + run: make ci-coverage + if: matrix.coverage == true + + - name: Upload code coverage + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: coverage/php/coverage.xml + if: matrix.coverage == true diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2d846d0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "build"] + path = build + url = https://github.com/gesinn-it-pub/docker-compose-ci.git diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 0000000..866e637 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + . + /(vendor|conf)/ + extensions/* + + + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0780458 --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +-include .env +export + +# setup for docker-compose-ci build directory +# delete "build" directory to update docker-compose-ci + +ifeq (,$(wildcard ./build/)) + $(shell git submodule update --init --remote) +endif + +EXTENSION=SemanticExternalQueryLookup + +# docker images +MW_VERSION?=1.39 +PHP_VERSION?=8.1 +DB_TYPE?=mysql +DB_IMAGE?="mariadb:10" + +# extensions +SMW_VERSION?=dev-master + +# composer +# Enables "composer update" inside of extension +COMPOSER_EXT?=true + +# nodejs +# Enables node.js related tests and "npm install" +# NODE_JS?=true + +# check for build dir and git submodule init if it does not exist +include build/Makefile + diff --git a/SemanticExternalQueryLookup.php b/SemanticExternalQueryLookup.php index 882b405..eb9afb5 100644 --- a/SemanticExternalQueryLookup.php +++ b/SemanticExternalQueryLookup.php @@ -17,14 +17,13 @@ class SemanticExternalQueryLookup { * @since 1.0 */ public static function onExtensionFunction() { - define( 'SEQL_VERSION', '1.0.0-alpha' ); class_alias( 'SEQL\ByHttpRequestQueryLookup', 'SMWExternalQueryLookup' ); // deprecated class_alias( 'SEQL\ByHttpRequestQueryLookup', 'SMWExternalAskQueryLookup' ); - $options = array( + $options = [ 'externalRepositoryEndpoints' => $GLOBALS['seqlgExternalRepositoryEndpoints'] - ); + ]; $hookRegistry = new HookRegistry( $options diff --git a/build b/build new file mode 160000 index 0000000..13d00b1 --- /dev/null +++ b/build @@ -0,0 +1 @@ +Subproject commit 13d00b11a7743cb6a524c6ed577b8dea3913a62c diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..986ab9a --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ +fixes: + - "/var/www/html/extensions/SemanticExternalQueryLookup/::" diff --git a/composer.json b/composer.json index f199de9..491a15a 100644 --- a/composer.json +++ b/composer.json @@ -25,14 +25,15 @@ "source": "https://github.com/SemanticMediaWiki/SemanticExternalQueryLookup" }, "require": { - "php": ">=5.3.0", - "composer/installers": "1.*,>=1.0.1", - "mediawiki/semantic-media-wiki": "~3.0", - "onoi/http-request": "~1.3" + "php": ">=8.1.0", + "composer/installers": ">=1.0.1", + "mediawiki/http-request": "~2.0|~1.1" }, "require-dev": { - "squizlabs/php_codesniffer": "~2.1", - "phpmd/phpmd": "~2.1" + "mediawiki/mediawiki-codesniffer": "43.0.0", + "mediawiki/minus-x": "1.1.3", + "php-parallel-lint/php-console-highlighter": "1.0.0", + "php-parallel-lint/php-parallel-lint": "1.4.0" }, "extra": { "branch-alias": { @@ -40,18 +41,39 @@ } }, "config": { - "process-timeout": 0 + "process-timeout": 0, + "allow-plugins": { + "composer/installers": true, + "dealerdirect/phpcodesniffer-composer-installer": true + } }, "scripts":{ - "phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist", - "cs": [ - "vendor/bin/phpcs src/* tests/* --standard=phpcs.xml --extensions=php -sp", - "vendor/bin/phpmd src/,tests/ text phpmd.xml" + "test": [ + "@analyze", + "@phpunit" + ], + "test-coverage": [ + "@analyze", + "@phpunit-coverage" + ], + "analyze": [ + "@lint", + "@phpcs", + "@minus-x" + ], + "fix": [ + "@phpcs-fix" + ], + "phpunit": "php ${MW_INSTALL_PATH:-../..}/tests/phpunit/phpunit.php -c phpunit.xml.dist", + "phpunit-coverage": "php ${MW_INSTALL_PATH:-../..}/tests/phpunit/phpunit.php -c phpunit.xml.dist --testdox --coverage-text --coverage-html coverage/php --coverage-clover coverage/php/coverage.xml", + "post-test-coverage": [ + "sed -i 's|/var/www/html/extensions/SemanticResultFormats/||g' coverage/php/coverage.xml", + "find coverage/php -type f -name '*.html' -exec sed -i 's|/var/www/html/extensions/||g' {} +" ], - "ci": [ - "composer validate --no-interaction", - "composer phpunit", - "composer cs" - ] + "integration": "composer phpunit -- --testsuite=semantic-result-formats-integration", + "phpcs": "phpcs -ps -d memory_limit=2G", + "phpcs-fix": "phpcbf -p", + "lint": "parallel-lint . --exclude vendor --exclude node_modules --exclude extensions", + "minus-x": "minus-x check ." } } diff --git a/extension.json b/extension.json index a5e9ae2..0bc368d 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "SemanticExternalQueryLookup", - "version": "1.0.0-alpha", + "version": "1.1.0-alpha", "author": [ "James Hong Kong" ], @@ -9,9 +9,9 @@ "license-name": "GPL-2.0-or-later", "type": "semantic", "requires": { - "MediaWiki": ">= 1.28", + "MediaWiki": ">= 1.39", "extensions": { - "SemanticMediaWiki": ">= 3.0" + "SemanticMediaWiki": ">= 4.2" } }, "MessagesDirs": { @@ -25,7 +25,9 @@ "AutoloadClasses": { "SemanticExternalQueryLookup": "SemanticExternalQueryLookup.php" }, - "callback": "SemanticExternalQueryLookup::onExtensionFunction", + "ExtensionFunctions": [ + "SemanticExternalQueryLookup::onExtensionFunction" + ], "config_prefix": "seqlg", "config": { "HttpResponseCacheLifetime": { diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index 485bbed..0000000 --- a/phpcs.xml +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - - - - - - - - - - - - - - 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - - - - diff --git a/src/ByHttpRequest/CannedResultArray.php b/src/ByHttpRequest/CannedResultArray.php index bf6ff05..5a6907d 100644 --- a/src/ByHttpRequest/CannedResultArray.php +++ b/src/ByHttpRequest/CannedResultArray.php @@ -6,12 +6,12 @@ use SMW\DIProperty; use SMW\DIWikiPage; use SMW\Query\PrintRequest; +use SMW\Query\Result\ResultArray; use SMWDataItem; use SMWDataValue as DataValue; -use SMWResultArray as ResultArray; /** - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames @@ -73,7 +73,7 @@ public function getContent() { return $this->mContent; } - $content = array(); + $content = []; foreach ( $this->mContent as $value ) { $content[] = $value instanceof DataValue ? $value->getDataItem() : $value; @@ -99,7 +99,6 @@ public function getPrintRequest() { * @return SMWDataItem|false */ public function getNextDataItem() { - $this->loadContent(); $result = current( $this->mContent ); next( $this->mContent ); @@ -115,7 +114,6 @@ public function getNextDataItem() { * @return SMWDataItem|false */ public function reset() { - $this->loadContent(); $result = reset( $this->mContent ); @@ -130,7 +128,6 @@ public function reset() { * @return DataValue|false */ public function getNextDataValue() { - $this->loadContent(); $content = current( $this->mContent ); next( $this->mContent ); @@ -145,12 +142,12 @@ public function getNextDataValue() { // therefore don't try to recreate a DataValue and use the DV created // from the raw API response if ( $this->mPrintRequest->getMode() === PrintRequest::PRINT_PROP && - $property->findPropertyTypeId() === '_qty' ) { + $property->findPropertyTypeId() === '_qty' ) { return $content; } if ( $this->mPrintRequest->getMode() === PrintRequest::PRINT_PROP && - strpos( $property->findPropertyTypeId(), '_rec' ) !== false ) { + strpos( $property->findPropertyTypeId(), '_rec' ) !== false ) { if ( $this->mPrintRequest->getParameter( 'index' ) === false ) { return $content; @@ -167,7 +164,7 @@ public function getNextDataValue() { $content = $dataItems[$pos]; if ( array_key_exists( $pos, $diProperties ) && - !is_null( $diProperties[$pos] ) ) { + $diProperties[$pos] !== null ) { $diProperty = $diProperties[$pos]; } else { $diProperty = null; @@ -208,21 +205,20 @@ protected function loadContent() { return; } - $this->mContent = array(); + $this->mContent = []; switch ( $this->mPrintRequest->getMode() ) { case PrintRequest::PRINT_THIS: - $this->mContent = array( $this->mResult ); - break; + $this->mContent = [ $this->mResult ]; + break; case PrintRequest::PRINT_CCAT: case PrintRequest::PRINT_CATS: - $this->mContent = $this->jsonResponseParser->getPropertyValuesFor( $this->mResult, new DIProperty( '_INST' ) ); - break; + break; case PrintRequest::PRINT_PROP: $propertyValue = $this->mPrintRequest->getData(); @@ -233,16 +229,15 @@ protected function loadContent() { ); } - break; + break; default: - $this->mContent = array(); // Unknown print request. + $this->mContent = []; // Unknown print request. } reset( $this->mContent ); } private function getMatchablePropertyFromPrintRequest() { - if ( $this->mPrintRequest->getMode() !== PrintRequest::PRINT_PROP ) { return null; } diff --git a/src/ByHttpRequest/JsonResponseParser.php b/src/ByHttpRequest/JsonResponseParser.php index 210b9da..5acff54 100644 --- a/src/ByHttpRequest/JsonResponseParser.php +++ b/src/ByHttpRequest/JsonResponseParser.php @@ -7,7 +7,7 @@ use SMW\DIWikiPage; /** - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames @@ -27,22 +27,22 @@ class JsonResponseParser { /** * @var array */ - private $subjectList = array(); + private $subjectList = []; /** - * @var boolean + * @var bool */ private $furtherResults = false; /** * @var array */ - private $printouts = array(); + private $printouts = []; /** * @var string */ - private $rawResponseResult = array(); + private $rawResponseResult = []; /** * @since 1.0 @@ -62,7 +62,6 @@ public function __construct( DataValueDeserializer $dataValueDeserializer ) { * @return DIProperty */ public function findPropertyFromInMemoryExternalRepositoryCache( DIProperty $property ) { - $key = $property->getKey(); if ( $this->responsePropertyList->hasProperty( $key ) ) { @@ -74,8 +73,6 @@ public function findPropertyFromInMemoryExternalRepositoryCache( DIProperty $pro /** * @since 1.0 - * - * @param DIWikiPage[] */ public function getResultSubjectList() { return $this->subjectList; @@ -83,8 +80,6 @@ public function getResultSubjectList() { /** * @since 1.0 - * - * @param [] */ public function getPrintouts() { return $this->printouts; @@ -92,8 +87,6 @@ public function getPrintouts() { /** * @since 1.0 - * - * @param [] */ public function getPrintRequestPropertyList() { return $this->responsePropertyList->getPropertyList(); @@ -102,7 +95,7 @@ public function getPrintRequestPropertyList() { /** * @since 1.0 * - * @return boolean + * @return bool */ public function hasFurtherResults() { return $this->furtherResults; @@ -126,11 +119,10 @@ public function getRawResponseResult() { * @return array */ public function getPropertyValuesFor( DIWikiPage $subject, DIProperty $property ) { - $hash = $subject->getHash(); $key = $this->responsePropertyList->findPropertyKey( $property->getKey() ); - return isset( $this->printouts[$hash][$key] ) ? $this->printouts[$hash][$key] : array(); + return isset( $this->printouts[$hash][$key] ) ? $this->printouts[$hash][$key] : []; } /** @@ -139,9 +131,8 @@ public function getPropertyValuesFor( DIWikiPage $subject, DIProperty $property * @param array $result */ public function doParse( array $result ) { - if ( isset( $result['query'] ) ) { - $this->rawResponseResult = $result['query'] ; + $this->rawResponseResult = $result['query']; } foreach ( $result as $key => $item ) { @@ -166,7 +157,6 @@ public function doParse( array $result ) { } private function addResultsToPrintoutList( $k, $value ) { - // Most likely caused by `mainlabel=-` therefore mark it as special and // restore row integrity if ( !isset( $value['namespace'] ) || !isset( $value['fulltext'] ) ) { @@ -193,7 +183,6 @@ private function addResultsToPrintoutList( $k, $value ) { } private function addPropertyValues( $hash, $pk, $pvalues ) { - $property = DIProperty::newFromUserLabel( $pk ); $pk = $property->getKey(); @@ -207,7 +196,7 @@ private function addPropertyValues( $hash, $pk, $pvalues ) { foreach ( $pvalues as $pvalue ) { if ( !isset( $this->printouts[$hash][$pk] ) ) { - $this->printouts[$hash][$pk] = array(); + $this->printouts[$hash][$pk] = []; } // Unique row value display diff --git a/src/ByHttpRequest/QueryResult.php b/src/ByHttpRequest/QueryResult.php index 2566212..304e791 100644 --- a/src/ByHttpRequest/QueryResult.php +++ b/src/ByHttpRequest/QueryResult.php @@ -2,11 +2,11 @@ namespace SEQL\ByHttpRequest; +use SMW\Query\QueryResult as RootQueryResult; use SMWInfolink as Infolink; -use SMWQueryResult as RootQueryResult; /** - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames @@ -76,7 +76,7 @@ public function getNext() { return false; } - $row = array(); + $row = []; foreach ( $this->mPrintRequests as $p ) { $row[] = new CannedResultArray( $page, $p, $this->jsonResponseParser ); @@ -91,7 +91,7 @@ public function getNext() { * @return SMWInfolink */ public function getLink() { - $params = array( trim( $this->getQuery()->getQueryString() ) ); + $params = [ trim( $this->getQuery()->getQueryString() ?? '' ) ]; foreach ( $this->getQuery()->getExtraPrintouts() as $printout ) { $serialization = $printout->getSerialisation(); diff --git a/src/ByHttpRequest/QueryResultFetcher.php b/src/ByHttpRequest/QueryResultFetcher.php index 64c6b3f..c1d562a 100644 --- a/src/ByHttpRequest/QueryResultFetcher.php +++ b/src/ByHttpRequest/QueryResultFetcher.php @@ -8,7 +8,7 @@ use SMWQuery as Query; /** - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames @@ -46,7 +46,7 @@ class QueryResultFetcher { private $httpResponseCachePrefix; /** - * @var integer + * @var int */ private $httpResponseCacheLifetime; @@ -104,7 +104,7 @@ public function setHttpResponseCachePrefix( $httpResponseCachePrefix ) { /** * @since 1.0 * - * @param integer $httpResponseCacheLifetime + * @param int $httpResponseCacheLifetime */ public function setHttpResponseCacheLifetime( $httpResponseCacheLifetime ) { $this->httpResponseCacheLifetime = $httpResponseCacheLifetime; @@ -117,8 +117,7 @@ public function setHttpResponseCacheLifetime( $httpResponseCacheLifetime ) { * @param array $credentials */ public function doAuthenticateRemoteWiki( $credentials ) { - - $cookiefile = 'seql_'.time(); + $cookiefile = 'seql_' . time(); $httpRequest = $this->httpRequestFactory->newCurlRequest(); @@ -136,7 +135,7 @@ public function doAuthenticateRemoteWiki( $credentials ) { $response = $httpRequest->execute(); $result = json_decode( $response, true ); - if( isset( $result['query']['tokens']['logintoken'] ) ) { + if ( isset( $result['query']['tokens']['logintoken'] ) ) { $token = $result['query']['tokens']['logintoken']; @@ -149,13 +148,13 @@ public function doAuthenticateRemoteWiki( $credentials ) { $httpRequest->setOption( CURLOPT_COOKIEJAR, $cookiefile ); $httpRequest->setOption( CURLOPT_COOKIEFILE, $cookiefile ); - $httpRequest->setOption( CURLOPT_POSTFIELDS, http_build_query( array( + $httpRequest->setOption( CURLOPT_POSTFIELDS, http_build_query( [ 'action' => 'login', 'format' => 'json', 'lgname' => $credentials['username'], 'lgpassword' => $credentials['password'], 'lgtoken' => $token - )) + ] ) ); $response = $httpRequest->execute(); @@ -166,7 +165,6 @@ public function doAuthenticateRemoteWiki( $credentials ) { } } - } /** @@ -177,22 +175,21 @@ public function doAuthenticateRemoteWiki( $credentials ) { * @return QueryResult */ public function fetchQueryResult( Query $query ) { - $this->doResetPrintRequestsToQuerySource( $query ); - if( $this->credentials && !self::$cookies ) { + if ( $this->credentials && !self::$cookies ) { $this->doAuthenticateRemoteWiki( $this->credentials ); } - list( $result, $isFromCache ) = $this->doMakeHttpRequestFor( $query ); + [ $result, $isFromCache ] = $this->doMakeHttpRequestFor( $query ); - if ( $result === array() || $result === false || $result === null ) { + if ( $result === [] || $result === false || $result === null ) { return $this->queryResultFactory->newEmptyQueryResult( $query ); } if ( isset( $result['error'] ) ) { $query->addErrors( - isset( $result['error']['info'] ) ? array( implode( ', ', $result['error'] ) ) : $result['error']['query'] + isset( $result['error']['info'] ) ? [ implode( ', ', $result['error'] ) ] : $result['error']['query'] ); return $this->queryResultFactory->newEmptyQueryResult( $query ); @@ -213,14 +210,13 @@ public function fetchQueryResult( Query $query ) { $queryResult->setFromCache( $isFromCache ); $queryResult->setRemoteTargetUrl( - str_replace( '$1', '', $this->repositoryTargetUrl ) + str_replace( '$1', '', $this->repositoryTargetUrl ) ); return $queryResult; } private function doResetPrintRequestsToQuerySource( $query ) { - $querySource = $query->getQuerySource(); foreach ( $query->getExtraPrintouts() as $printRequest ) { @@ -230,7 +226,7 @@ private function doResetPrintRequestsToQuerySource( $query ) { } $property = $printRequest->getData()->getDataItem(); - $property->setInterwiki( $querySource ); + $property->setInterwiki( $querySource ?? '' ); $printRequest->getData()->setDataItem( $property ); @@ -240,7 +236,6 @@ private function doResetPrintRequestsToQuerySource( $query ) { } private function doMakeHttpRequestFor( $query ) { - $httpRequest = $this->httpRequestFactory->newCachedCurlRequest(); $httpRequest->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, $this->httpResponseCacheLifetime ); @@ -254,19 +249,19 @@ private function doMakeHttpRequestFor( $query ) { $httpRequest->setOption( CURLOPT_URL, $this->httpRequestEndpoint . '?action=ask&format=json&query=' . QueryEncoder::rawUrlEncode( $query ) ); - $httpRequest->setOption( CURLOPT_HTTPHEADER, array( + $httpRequest->setOption( CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'Content-Type: application/json; charset=utf-8' - ) ); + ] ); - if( self::$cookies ) { + if ( self::$cookies ) { $httpRequest->setOption( CURLOPT_COOKIEJAR, self::$cookies ); $httpRequest->setOption( CURLOPT_COOKIEFILE, self::$cookies ); } $response = $httpRequest->execute(); - return array( json_decode( $response, true ), $httpRequest->isFromCache() ); + return [ json_decode( $response ?? '', true ), $httpRequest->isFromCache() ]; } } diff --git a/src/ByHttpRequest/ResponsePropertyList.php b/src/ByHttpRequest/ResponsePropertyList.php index 0f6eb72..3cfe2d6 100644 --- a/src/ByHttpRequest/ResponsePropertyList.php +++ b/src/ByHttpRequest/ResponsePropertyList.php @@ -2,12 +2,11 @@ namespace SEQL\ByHttpRequest; -use SMW\DIProperty; -use SMW\DIWikiPage; use RuntimeException; +use SMW\DIProperty; /** - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames @@ -22,12 +21,12 @@ class ResponsePropertyList { /** * @var array */ - private $propertyList = array(); + private $propertyList = []; /** * @var array */ - private $internalLabelToKeyMap = array(); + private $internalLabelToKeyMap = []; /** * @since 1.0 @@ -35,7 +34,7 @@ class ResponsePropertyList { * @param string $querySource */ public function __construct( $querySource ) { - $this->querySource = $querySource; + $this->querySource = $querySource ?? ''; } /** @@ -55,7 +54,6 @@ public function getPropertyList() { * @return string */ public function findPropertyKey( $key ) { - if ( isset( $this->internalLabelToKeyMap[$key] ) ) { return $this->internalLabelToKeyMap[$key]; } @@ -68,7 +66,7 @@ public function findPropertyKey( $key ) { * * @param string $key * - * @return boolean + * @return bool */ public function hasProperty( $key ) { return isset( $this->propertyList[$this->findPropertyKey( $key )] ); @@ -82,7 +80,6 @@ public function hasProperty( $key ) { * @return DIProperty|null */ public function getProperty( $key ) { - $key = $this->findPropertyKey( $key ); if ( isset( $this->propertyList[$key] ) ) { @@ -98,7 +95,6 @@ public function getProperty( $key ) { * @param array $value */ public function addToPropertyList( array $value ) { - if ( $value['label'] === '' ) { return; } @@ -119,7 +115,6 @@ public function addToPropertyList( array $value ) { } private function newProperty( $value ) { - $property = DIProperty::newFromUserLabel( $value['label'] ); if ( $property->isUserDefined() ) { @@ -133,7 +128,7 @@ private function newProperty( $value ) { // Something like |Has foo=Text where `Text` is mapped to a DataType // cannot be redeclared when the type of `Has foo` (as `_wpg`) doesn't // correspond to the predefined property type - throw new RuntimeException( 'Cannot redeclare type "' . $value['typeid'] . '" for "' . $value['label'] . '" (as predefined property/type)' ); + throw new RuntimeException( 'Cannot redeclare type "' . $value['typeid'] . '" for "' . $value['label'] . '" (as predefined property/type)' ); } } diff --git a/src/ByHttpRequestQueryLookup.php b/src/ByHttpRequestQueryLookup.php index 1ca9a85..e91e9fd 100644 --- a/src/ByHttpRequestQueryLookup.php +++ b/src/ByHttpRequestQueryLookup.php @@ -7,13 +7,13 @@ use SEQL\ByHttpRequest\JsonResponseParser; use SEQL\ByHttpRequest\QueryResultFetcher; use SMW\CacheFactory; +use SMW\Query\QueryResult; +use SMW\Services\ServicesFactory as ApplicationFactory; use SMW\SQLStore\SQLStore; -use SMW\ApplicationFactory; use SMWQuery as Query; -use SMWQueryResult as QueryResult; /** - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames @@ -38,18 +38,17 @@ class ByHttpRequestQueryLookup extends SQLStore { * @return QueryResult */ public function getQueryResult( Query $query ) { - $this->queryResultFactory = new QueryResultFactory( $this ); if ( $query->querymode === Query::MODE_DEBUG ) { - $query->addErrors( array( wfMessage( 'seql-debug-query-not-supported' )->text() ) ); + $query->addErrors( [ wfMessage( 'seql-debug-query-not-supported' )->text() ] ); return $this->queryResultFactory->newEmptyQueryResult( $query ); } $interwiki = $this->tryToMatchInterwikiFor( $query ); if ( $interwiki === false || $interwiki === null ) { - $query->addErrors( array( wfMessage( 'seql-interwiki-prefix-is-missing', $query->getQuerySource() )->text() ) ); + $query->addErrors( [ wfMessage( 'seql-interwiki-prefix-is-missing', $query->getQuerySource() )->text() ] ); return $this->queryResultFactory->newEmptyQueryResult( $query ); } @@ -68,7 +67,6 @@ protected function tryToMatchInterwikiFor( Query $query ) { } protected function fetchQueryResultFor( Query $query, $interwiki, $credentials = false ) { - $queryResultFetcher = new QueryResultFetcher( new HttpRequestFactory( $this->getCacheFactory()->newMediaWikiCompositeCache( $GLOBALS['seqlgHttpResponseCacheType'] ) ), $this->queryResultFactory, @@ -86,7 +84,6 @@ protected function fetchQueryResultFor( Query $query, $interwiki, $credentials = } private function getCacheFactory() { - if ( $this->cacheFactory === null ) { $this->cacheFactory = ApplicationFactory::getInstance()->newCacheFactory(); } diff --git a/src/DataValueDeserializer.php b/src/DataValueDeserializer.php index 7762155..f1e9890 100644 --- a/src/DataValueDeserializer.php +++ b/src/DataValueDeserializer.php @@ -2,16 +2,16 @@ namespace SEQL; +use SMW\DataModel\ContainerSemanticData; use SMW\DataValueFactory; use SMW\DIProperty; use SMW\DIWikiPage; -use SMWContainerSemanticData as ContainerSemanticData; +use SMWDIBlob as DIBlob; use SMWDIContainer as DIContainer; use SMWDITime as DITime; -use SMWDIBlob as DIBlob; /** - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames @@ -56,9 +56,8 @@ public function getQuerySource() { * @return DataValue */ public function newDataValueFrom( DIProperty $property, $value ) { - $dv = null; - $propertyList = array(); + $propertyList = []; if ( $property->findPropertyTypeId() === '_wpg' || isset( $value['fulltext'] ) ) { $dv = $this->newDataValueFromDataItem( $property, $this->newDiWikiPage( $value ) ); @@ -70,7 +69,7 @@ public function newDataValueFrom( DIProperty $property, $value ) { } elseif ( strpos( $property->findPropertyTypeId(), '_txt' ) !== false ) { $dv = $this->newDataValueFromDataItem( $property, $this->newDiBlob( $value ) ); } elseif ( $property->findPropertyTypeId() === '_qty' ) { - $dv = $this->newDataValueFromPropertyObject( $property, $value['value'] . ' ' . $value['unit'] ); + $dv = $this->newDataValueFromPropertyObject( $property, $value['value'] . ' ' . $value['unit'] ); } if ( $dv === null ) { @@ -88,7 +87,6 @@ public function newDataValueFrom( DIProperty $property, $value ) { * @return DIWikiPage|false */ public function newDiWikiPage( array $value ) { - if ( !isset( $value['namespace'] ) || !isset( $value['fulltext'] ) ) { return false; } @@ -96,16 +94,15 @@ public function newDiWikiPage( array $value ) { $ns = (int)$value['namespace'] === NS_CATEGORY ? NS_CATEGORY : NS_MAIN; if ( $ns === NS_CATEGORY ) { - $value['fulltext'] = substr( $value['fulltext'], ($pos = strpos( $value['fulltext'], ':') ) !== false ? $pos + 1 : 0 ); + $value['fulltext'] = substr( $value['fulltext'], ( $pos = strpos( $value['fulltext'], ':' ) ) !== false ? $pos + 1 : 0 ); } - $title = \Title::newFromText( $this->querySource . ':' . str_replace(" ", "_", $value['fulltext'] ), $ns ); + $title = \Title::newFromText( $this->querySource . ':' . str_replace( " ", "_", $value['fulltext'] ), $ns ); return DIWikiPage::newFromTitle( $title ); } private function newDiTime( $value ) { - if ( isset( $value['raw'] ) ) { return DITime::doUnserialize( $value['raw'] ); } @@ -114,7 +111,7 @@ private function newDiTime( $value ) { // Avoid something like "Part of the date is out of bounds" where the API // doesn't sent a raw format // return 9999 BC to indicate that we hit a bounds with the timespamp - try{ + try { $dataItem = DITime::newFromTimestamp( $value ); } catch ( \Exception $e ) { $dataItem = DITime::doUnserialize( '2/-9999' ); @@ -128,8 +125,7 @@ private function newDiBlob( $value ) { } private function newDataValueFromPropertyObject( $property, $value ) { - - try{ + try { $dv = DataValueFactory::newPropertyObjectValue( $property, $value ); } catch ( \Exception $e ) { $dv = false; @@ -139,12 +135,11 @@ private function newDataValueFromPropertyObject( $property, $value ) { } private function newDataValueFromDataItem( $property, $dataItem = false ) { - if ( $dataItem === false ) { return false; } - try{ + try { $dv = DataValueFactory::newDataItemValue( $dataItem, $property ); } catch ( \Exception $e ) { $dv = false; @@ -154,7 +149,6 @@ private function newDataValueFromDataItem( $property, $dataItem = false ) { } private function newDiContainerOnRecordType( array $value, &$propertyList ) { - // Remote container to use an anonymous $semanticData = ContainerSemanticData::makeAnonymousContainer(); diff --git a/src/DynamicInterwikiPrefixLoader.php b/src/DynamicInterwikiPrefixLoader.php index ddb0ca2..71fadd7 100644 --- a/src/DynamicInterwikiPrefixLoader.php +++ b/src/DynamicInterwikiPrefixLoader.php @@ -6,7 +6,7 @@ * Allows to dynamically assign interwiki prefixes without having to * create an interwiki table entry. * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames @@ -16,14 +16,14 @@ class DynamicInterwikiPrefixLoader { /** * @var array */ - private $enabledExternalRepositoryEndpoints = array(); + private $enabledExternalRepositoryEndpoints = []; /** * @since 1.0 * * @param array $enabledExternalRepositoryEndpoints */ - public function __construct( array $enabledExternalRepositoryEndpoints = array() ) { + public function __construct( array $enabledExternalRepositoryEndpoints = [] ) { $this->enabledExternalRepositoryEndpoints = $enabledExternalRepositoryEndpoints; } @@ -43,21 +43,20 @@ public function isEnabledPrefixForExternalRepository( $prefix ) { * @param array &$interwiki */ public function tryToLoadIwMapForExternalRepository( $prefix, &$interwiki ) { - if ( !$this->isEnabledPrefixForExternalRepository( $prefix ) ) { return true; } - list( $iw_url, $iw_api, $iw_local ) = $this->enabledExternalRepositoryEndpoints[$prefix]; + [ $iw_url, $iw_api, $iw_local ] = $this->enabledExternalRepositoryEndpoints[$prefix]; - $interwiki = array( + $interwiki = [ 'iw_prefix' => $prefix, 'iw_url' => $iw_url, 'iw_api' => $iw_api, 'iw_wikiid' => $prefix, 'iw_local' => $iw_local, 'iw_trans' => false, - ); + ]; return false; } diff --git a/src/EmbeddedLinksReplacer.php b/src/EmbeddedLinksReplacer.php index a8588d8..27feec7 100644 --- a/src/EmbeddedLinksReplacer.php +++ b/src/EmbeddedLinksReplacer.php @@ -2,12 +2,12 @@ namespace SEQL; -use SMW\InTextAnnotationParser; +use SMW\Parser\InTextAnnotationParser; /** * Find and replace [[]] with an appropriate remote source link. * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames @@ -36,7 +36,6 @@ public function __construct( $querySource ) { * @return string */ public function replace( $value ) { - // Strip any [[ :: ]] from a value to avoid "foreign" annotation parsing // for annotation embedded within a value $value = InTextAnnotationParser::removeAnnotation( @@ -49,7 +48,7 @@ public function replace( $value ) { private function replaceEmbeddedLinksWith( $source, $value ) { $value = preg_replace_callback( '/\[\[(.*)\]\]/xu', - function( array $matches ) use( $source ) { + static function ( array $matches ) use( $source ) { $caption = false; $value = ''; @@ -63,7 +62,7 @@ function( array $matches ) use( $source ) { $caption = $value; } - return '[[' . $source . ':' . $value . '|' . $caption . ']]'; + return '[[' . $source . ':' . $value . '|' . $caption . ']]'; }, $value ); diff --git a/src/HookRegistry.php b/src/HookRegistry.php index 01f5a20..88e29b0 100644 --- a/src/HookRegistry.php +++ b/src/HookRegistry.php @@ -2,11 +2,10 @@ namespace SEQL; -use Hooks; -use SMW\Store; +use MediaWiki\MediaWikiServices; /** - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames @@ -16,7 +15,7 @@ class HookRegistry { /** * @var array */ - private $handlers = array(); + private $handlers = []; /** * @since 1.0 @@ -31,8 +30,9 @@ public function __construct( array $options ) { * @since 1.0 */ public function register() { + $hooks = MediaWikiServices::getInstance()->getHookContainer(); foreach ( $this->handlers as $name => $callback ) { - Hooks::register( $name, $callback ); + $hooks->register( $name, $callback ); } } @@ -41,10 +41,10 @@ public function register() { * * @param string $name * - * @return boolean + * @return bool */ public function isRegistered( $name ) { - return Hooks::isRegistered( $name ); + return MediaWikiServices::getInstance()->getHookContainer()->isRegistered( $name ); } /** @@ -52,19 +52,18 @@ public function isRegistered( $name ) { * * @param string $name * - * @return Callable|false + * @return callable|false */ public function getHandlerFor( $name ) { return isset( $this->handlers[$name] ) ? $this->handlers[$name] : false; } private function addCallbackHandlers( $options ) { - $dynamicInterwikiPrefixLoader = new DynamicInterwikiPrefixLoader( $options['externalRepositoryEndpoints'] ); - $this->handlers['InterwikiLoadPrefix'] = function( $prefix, &$interwiki ) use( $dynamicInterwikiPrefixLoader ) { + $this->handlers['InterwikiLoadPrefix'] = static function ( $prefix, &$interwiki ) use( $dynamicInterwikiPrefixLoader ) { return $dynamicInterwikiPrefixLoader->tryToLoadIwMapForExternalRepository( $prefix, $interwiki ); }; @@ -77,26 +76,25 @@ private function addCallbackHandlers( $options ) { * @param $args * @param $override */ - $this->handlers['smwAskParserFunction'] = $this->handlers['smwShowParserFunction'] = function( $parser, $frame, $args, &$override ) { - if( $frame ) { + $this->handlers['smwAskParserFunction'] = $this->handlers['smwShowParserFunction'] = static function ( $parser, $frame, $args, &$override ) { + if ( $frame ) { $params = []; - foreach ($args as $key => $value) { - if ( $key == 0 || ( $value !== '' && $value{0} === '?' ) ) { + foreach ( $args as $key => $value ) { + if ( $key == 0 || ( $value !== '' && $value[0] === '?' ) ) { continue; } if ( strpos( $value, '=' ) === false ) { continue; } - $pair = explode('=', $value); + $pair = explode( '=', $value ); $params[$pair[0]] = $pair[1]; } - if( array_key_exists('source', $params) && !in_array( $frame->getTitle()->getNamespace(), $GLOBALS['seqlgExternalQueryEnabledNamespaces'] ) ) { + if ( array_key_exists( 'source', $params ) && !in_array( $frame->getTitle()->getNamespace(), $GLOBALS['seqlgExternalQueryEnabledNamespaces'] ) ) { $override = 'Warning: source parameter is not allowed in the namespace!'; } } }; - } } diff --git a/src/QueryEncoder.php b/src/QueryEncoder.php index 8437ac1..504226d 100644 --- a/src/QueryEncoder.php +++ b/src/QueryEncoder.php @@ -5,7 +5,7 @@ use SMWQuery as Query; /** - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames @@ -31,32 +31,31 @@ public static function rawUrlEncode( Query $query ) { * @return string */ public static function encode( Query $query ) { - $serialized = array(); + $serialized = []; $serialized['conditions'] = $query->getQueryString(); - $serialized['parameters'] = array( + $serialized['parameters'] = [ 'limit=' . $query->getLimit(), 'offset=' . $query->getOffset(), 'mainlabel=' . $query->getMainlabel(), - // 'source=' . $query->getQuerySource() - ); + // 'source=' . $query->getQuerySource() + ]; - list( $serialized['sort'], $serialized['order'] ) = self::doSerializeSortKeys( $query ); + [ $serialized['sort'], $serialized['order'] ] = self::doSerializeSortKeys( $query ); $serialized['printouts'] = self::doSerializePrintouts( $query ); $encoded = $serialized['conditions'] . '|' . - ( $serialized['printouts'] !== array() ? implode( '|', $serialized['printouts'] ) . '|' : '' ) . + ( $serialized['printouts'] !== [] ? implode( '|', $serialized['printouts'] ) . '|' : '' ) . implode( '|', $serialized['parameters'] ) . - ( $serialized['sort'] !== array() ? '|sort=' . implode( ',', $serialized['sort'] ) : '' ) . - ( $serialized['order'] !== array() ? '|order=' . implode( ',', $serialized['order'] ) : '' ); + ( $serialized['sort'] !== [] ? '|sort=' . implode( ',', $serialized['sort'] ) : '' ) . + ( $serialized['order'] !== [] ? '|order=' . implode( ',', $serialized['order'] ) : '' ); return $encoded; } private static function doSerializePrintouts( $query ) { - - $printouts = array(); + $printouts = []; foreach ( $query->getExtraPrintouts() as $printout ) { $serialization = $printout->getSerialisation(); @@ -71,9 +70,8 @@ private static function doSerializePrintouts( $query ) { } private static function doSerializeSortKeys( $query ) { - - $sort = array(); - $order = array(); + $sort = []; + $order = []; foreach ( $query->getSortKeys() as $key => $value ) { @@ -85,7 +83,7 @@ private static function doSerializeSortKeys( $query ) { $order[] = strtolower( $value ); } - return array( $sort, $order ); + return [ $sort, $order ]; } } diff --git a/src/QueryResultFactory.php b/src/QueryResultFactory.php index 840a502..c96df8d 100644 --- a/src/QueryResultFactory.php +++ b/src/QueryResultFactory.php @@ -4,21 +4,18 @@ use SEQL\ByHttpRequest\JsonResponseParser; use SEQL\ByHttpRequest\QueryResult as ByHttpRequestQueryResult; +use SMW\Query\QueryResult; use SMW\Store; use SMWQuery as Query; -use SMWQueryResult as QueryResult; /** - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ class QueryResultFactory { - /** - * @var - */ private $store; /** @@ -41,7 +38,7 @@ public function newEmptyQueryResult( Query $query ) { return new QueryResult( $query->getDescription()->getPrintrequests(), $query, - array(), + [], $this->store, false ); @@ -56,7 +53,6 @@ public function newEmptyQueryResult( Query $query ) { * @return QueryResult */ public function newByHttpRequestQueryResult( Query $query, JsonResponseParser $jsonResponseParser ) { - $queryResult = new ByHttpRequestQueryResult( $query->getDescription()->getPrintrequests(), $query, diff --git a/tests/phpunit/Integration/ByHttpRequest/JsonParseOnFauxHttpResponseTest.php b/tests/phpunit/Integration/ByHttpRequest/JsonParseOnFauxHttpResponseTest.php index 425c502..c37ab82 100644 --- a/tests/phpunit/Integration/ByHttpRequest/JsonParseOnFauxHttpResponseTest.php +++ b/tests/phpunit/Integration/ByHttpRequest/JsonParseOnFauxHttpResponseTest.php @@ -2,49 +2,45 @@ namespace SEQL\Tests\Integration\ByHttpRequest; -use SMW\Tests\Utils\UtilityFactory; -use Onoi\HttpRequest\HttpRequestFactory; -use SEQL\ByHttpRequest\QueryResultFetcher; use SEQL\ByHttpRequest\JsonResponseParser; -use SEQL\QueryResultFactory; use SEQL\DataValueDeserializer; use SEQL\HookRegistry; -use SMW\DIWikiPage; use SMW\DIProperty; +use SMW\DIWikiPage; +use SMW\Tests\Utils\UtilityFactory; /** * @group semantic-external-query-lookup * @group medium * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class JsonParseOnFauxHttpResponseTest extends \PHPUnit_Framework_TestCase { - - protected function setUp() { +class JsonParseOnFauxHttpResponseTest extends \PHPUnit\Framework\TestCase { - $externalRepositoryEndpoints = array( - 'api-foo' => array( + protected function setUp(): void { + $externalRepositoryEndpoints = [ + 'api-foo' => [ 'http://example.org/index.php/$1', 'http://example.org/api.php/', true - ) - ); + ] + ]; - $hookRegistry = new HookRegistry( array( + $hookRegistry = new HookRegistry( [ 'externalRepositoryEndpoints' => $externalRepositoryEndpoints - ) ); + ] ); $hookRegistry->register(); } /** + * @covers I18nJsonFileIntegrity * @dataProvider jsonFileProvider */ public function testQueryResultFetcherFromCannedJsonResponse( $file ) { - $jsonFileReader = UtilityFactory::getInstance()->newJsonFileReader( $file ); $content = $jsonFileReader->read(); @@ -71,7 +67,6 @@ public function testQueryResultFetcherFromCannedJsonResponse( $file ) { } private function assertSubjectList( $expectedSubjectList, $subjectList ) { - foreach ( $subjectList as $subject ) { foreach ( $expectedSubjectList as $key => $sub ) { $sub = DIWikiPage::doUnserialize( str_replace( " ", "_", $sub ) ); @@ -89,7 +84,6 @@ private function assertSubjectList( $expectedSubjectList, $subjectList ) { } private function assertPrintRequestPropertyList( $expectedPropertyList, $printRequestPropertyList ) { - foreach ( $printRequestPropertyList as $property ) { foreach ( $expectedPropertyList as $key => $prop ) { $prop = new DIProperty( str_replace( " ", "_", $prop ) ); @@ -107,15 +101,14 @@ private function assertPrintRequestPropertyList( $expectedPropertyList, $printRe } public function jsonFileProvider() { - - $provider = array(); + $provider = []; $location = __DIR__ . '/Fixtures'; $bulkFileProvider = UtilityFactory::getInstance()->newBulkFileProvider( $location ); $bulkFileProvider->searchByFileExtension( 'json' ); foreach ( $bulkFileProvider->getFiles() as $file ) { - $provider[] = array( $file ); + $provider[] = [ $file ]; } return $provider; diff --git a/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php b/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php index 87df919..2df348b 100644 --- a/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php +++ b/tests/phpunit/Integration/I18nJsonFileIntegrityTest.php @@ -8,41 +8,40 @@ * @group semantic-external-query-lookup * @group medium * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class I18nJsonFileIntegrityTest extends \PHPUnit_Framework_TestCase { +class I18nJsonFileIntegrityTest extends \PHPUnit\Framework\TestCase { /** + * @covers I18nJsonFileIntegrity * @dataProvider i18nFileProvider */ public function testI18NJsonDecodeEncode( $file ) { - $jsonFileReader = UtilityFactory::getInstance()->newJsonFileReader( $file ); - $this->assertInternalType( - 'integer', + $this->assertIsInt( $jsonFileReader->getModificationTime() ); - $this->assertInternalType( - 'array', + $this->assertIsArray( $jsonFileReader->read() ); } public function i18nFileProvider() { + $provider = []; + $locations = $GLOBALS['wgMessagesDirs']['SemanticExternalQueryLookup']; - $provider = array(); - $location = $GLOBALS['wgMessagesDirs']['SemanticExternalQueryLookup']; - - $bulkFileProvider = UtilityFactory::getInstance()->newBulkFileProvider( $location ); - $bulkFileProvider->searchByFileExtension( 'json' ); + foreach ( $locations as $location ) { + $bulkFileProvider = UtilityFactory::getInstance()->newBulkFileProvider( $location ); + $bulkFileProvider->searchByFileExtension( 'json' ); - foreach ( $bulkFileProvider->getFiles() as $file ) { - $provider[] = array( $file ); + foreach ( $bulkFileProvider->getFiles() as $file ) { + $provider[] = [ $file ]; + } } return $provider; diff --git a/tests/phpunit/Unit/ByHttpRequest/CannedResultArrayTest.php b/tests/phpunit/Unit/ByHttpRequest/CannedResultArrayTest.php index 54746d5..7272896 100644 --- a/tests/phpunit/Unit/ByHttpRequest/CannedResultArrayTest.php +++ b/tests/phpunit/Unit/ByHttpRequest/CannedResultArrayTest.php @@ -3,32 +3,30 @@ namespace SEQL\ByHttpRequest\Tests; use SEQL\ByHttpRequest\CannedResultArray; -use SMW\DIWikiPage; use SMW\DIProperty; +use SMW\DIWikiPage; use SMWDINumber as DINumber; /** * @covers \SEQL\ByHttpRequest\CannedResultArray * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class CannedResultArrayTest extends \PHPUnit_Framework_TestCase { +class CannedResultArrayTest extends \PHPUnit\Framework\TestCase { private $jsonResponseParser; - protected function setUp() { - + protected function setUp(): void { $this->jsonResponseParser = $this->getMockBuilder( '\SEQL\ByHttpRequest\JsonResponseParser' ) ->disableOriginalConstructor() ->getMock(); } public function testCanConstruct() { - $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) ->disableOriginalConstructor() ->getMock(); @@ -40,7 +38,6 @@ public function testCanConstruct() { } public function testGetResultSubject() { - $subject = new DIWikiPage( 'Foo', NS_MAIN ); $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) @@ -60,7 +57,6 @@ public function testGetResultSubject() { } public function testGetContentForMode_PRINT_THIS() { - $subject = new DIWikiPage( 'Foo', NS_MAIN ); $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) @@ -69,7 +65,7 @@ public function testGetContentForMode_PRINT_THIS() { $printRequest->expects( $this->any() ) ->method( 'getMode' ) - ->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_THIS ) ); + ->willReturn( \SMW\Query\PrintRequest::PRINT_THIS ); $instance = new CannedResultArray( $subject, @@ -84,16 +80,15 @@ public function testGetContentForMode_PRINT_THIS() { } public function testGetContentForMode_PRINT_CCAT() { - $subject = new DIWikiPage( 'Foo', NS_MAIN ); $category = new DIWikiPage( 'Bar', NS_CATEGORY, 'mw-foo' ); $this->jsonResponseParser->expects( $this->any() ) ->method( 'getPropertyValuesFor' ) ->with( - $this->equalTo( $subject ), - $this->equalTo( new DIProperty( '_INST' ) ) ) - ->will( $this->returnValue( array( $category ) ) ); + $subject, + new DIProperty( '_INST' ) ) + ->willReturn( [ $category ] ); $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) ->disableOriginalConstructor() @@ -101,7 +96,7 @@ public function testGetContentForMode_PRINT_CCAT() { $printRequest->expects( $this->any() ) ->method( 'getMode' ) - ->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_CCAT ) ); + ->willReturn( \SMW\Query\PrintRequest::PRINT_CCAT ); $instance = new CannedResultArray( $subject, @@ -116,43 +111,42 @@ public function testGetContentForMode_PRINT_CCAT() { } public function testGetContentOnDifferentPropertyLabelForMode_PRINT_PROP() { - $subject = new DIWikiPage( 'Foo', NS_MAIN ); $dataItem = new DINumber( 1001 ); - $propertyValue = $this->getMockBuilder( '\SMWPropertyValue' ) + $propertyValue = $this->getMockBuilder( '\SMW\DataValues\PropertyValue' ) ->disableOriginalConstructor() ->getMock(); $propertyValue->expects( $this->any() ) ->method( 'isValid' ) - ->will( $this->returnValue( true ) ); + ->willReturn( true ); $propertyValue->expects( $this->any() ) ->method( 'getDataItem' ) - ->will( $this->returnValue( new DIProperty( 'ABC' ) ) ); + ->willReturn( new DIProperty( 'ABC' ) ); $dataValue = $this->getMockBuilder( '\SMWDataValue' ) ->disableOriginalConstructor() - ->setMethods( array( 'getDataItem' ) ) + ->onlyMethods( [ 'getDataItem' ] ) ->getMockForAbstractClass(); $dataValue->expects( $this->any() ) ->method( 'getDataItem' ) - ->will( $this->returnValue( $dataItem ) ); + ->willReturn( $dataItem ); $this->jsonResponseParser->expects( $this->any() ) ->method( 'getPropertyValuesFor' ) ->with( - $this->equalTo( $subject ), - $this->equalTo( new DIProperty( 'isPropertyFromInMemoryExternalRepositoryCache' ) ) ) - ->will( $this->returnValue( array( $dataValue ) ) ); + $subject, + new DIProperty( 'isPropertyFromInMemoryExternalRepositoryCache' ) ) + ->willReturn( [ $dataValue ] ); $this->jsonResponseParser->expects( $this->any() ) ->method( 'findPropertyFromInMemoryExternalRepositoryCache' ) ->with( - $this->equalTo( new DIProperty( 'withDifferentPropertyLabel' ) ) ) - ->will( $this->returnValue( new DIProperty( 'isPropertyFromInMemoryExternalRepositoryCache' ) ) ); + new DIProperty( 'withDifferentPropertyLabel' ) ) + ->willReturn( new DIProperty( 'isPropertyFromInMemoryExternalRepositoryCache' ) ); $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) ->disableOriginalConstructor() @@ -160,15 +154,15 @@ public function testGetContentOnDifferentPropertyLabelForMode_PRINT_PROP() { $printRequest->expects( $this->any() ) ->method( 'getMode' ) - ->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_PROP ) ); + ->willReturn( \SMW\Query\PrintRequest::PRINT_PROP ); $printRequest->expects( $this->any() ) ->method( 'getData' ) - ->will( $this->returnValue( $propertyValue ) ); + ->willReturn( $propertyValue ); $printRequest->expects( $this->atLeastOnce() ) ->method( 'getLabel' ) - ->will( $this->returnValue( 'withDifferentPropertyLabel' ) ); + ->willReturn( 'withDifferentPropertyLabel' ); $instance = new CannedResultArray( $subject, @@ -183,7 +177,6 @@ public function testGetContentOnDifferentPropertyLabelForMode_PRINT_PROP() { } public function testGetContentOnQuantityTypeWithSameLabelForMode_PRINT_PROP() { - $subject = new DIWikiPage( 'Foo', NS_MAIN ); $property = new DIProperty( 'QuantityType' ); @@ -191,39 +184,39 @@ public function testGetContentOnQuantityTypeWithSameLabelForMode_PRINT_PROP() { $dataItem = new DINumber( 1001 ); - $propertyValue = $this->getMockBuilder( '\SMWPropertyValue' ) + $propertyValue = $this->getMockBuilder( '\SMW\DataValues\PropertyValue' ) ->disableOriginalConstructor() ->getMock(); $propertyValue->expects( $this->any() ) ->method( 'isValid' ) - ->will( $this->returnValue( true ) ); + ->willReturn( true ); $propertyValue->expects( $this->any() ) ->method( 'getDataItem' ) - ->will( $this->returnValue( new DIProperty( 'ABC' ) ) ); + ->willReturn( new DIProperty( 'ABC' ) ); $dataValue = $this->getMockBuilder( '\SMWDataValue' ) ->disableOriginalConstructor() - ->setMethods( array( 'getDataItem' ) ) + ->onlyMethods( [ 'getDataItem' ] ) ->getMockForAbstractClass(); $dataValue->expects( $this->any() ) ->method( 'getDataItem' ) - ->will( $this->returnValue( $dataItem ) ); + ->willReturn( $dataItem ); $this->jsonResponseParser->expects( $this->any() ) ->method( 'getPropertyValuesFor' ) ->with( - $this->equalTo( $subject ), - $this->equalTo( $property ) ) - ->will( $this->returnValue( array( $dataValue ) ) ); + $subject, + $property ) + ->willReturn( [ $dataValue ] ); $this->jsonResponseParser->expects( $this->any() ) ->method( 'findPropertyFromInMemoryExternalRepositoryCache' ) ->with( - $this->equalTo( new DIProperty( 'ABC' ) ) ) - ->will( $this->returnValue( $property ) ); + new DIProperty( 'ABC' ) ) + ->willReturn( $property ); $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) ->disableOriginalConstructor() @@ -231,15 +224,15 @@ public function testGetContentOnQuantityTypeWithSameLabelForMode_PRINT_PROP() { $printRequest->expects( $this->any() ) ->method( 'getMode' ) - ->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_PROP ) ); + ->willReturn( \SMW\Query\PrintRequest::PRINT_PROP ); $printRequest->expects( $this->any() ) ->method( 'getData' ) - ->will( $this->returnValue( $propertyValue ) ); + ->willReturn( $propertyValue ); $printRequest->expects( $this->atLeastOnce() ) ->method( 'getLabel' ) - ->will( $this->returnValue( '' ) ); + ->willReturn( '' ); $instance = new CannedResultArray( $subject, @@ -254,7 +247,6 @@ public function testGetContentOnQuantityTypeWithSameLabelForMode_PRINT_PROP() { } public function testOptions() { - $subject = new DIWikiPage( 'Foo', NS_MAIN ); $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) @@ -263,7 +255,7 @@ public function testOptions() { $printRequest->expects( $this->any() ) ->method( 'getMode' ) - ->will( $this->returnValue( \SMW\Query\PrintRequest::PRINT_THIS ) ); + ->willReturn( \SMW\Query\PrintRequest::PRINT_THIS ); $instance = new CannedResultArray( $subject, @@ -273,19 +265,18 @@ public function testOptions() { $dataValue = $instance->getNextDataValue(); - $this->assertInternalType( - 'string', + $this->assertIsString( + $dataValue->getOption( 'user.language' ) ); - $this->assertInternalType( - 'string', + $this->assertIsString( + $dataValue->getOption( 'content.language' ) ); } private function assertDataItem( $dataItem, $instance ) { - $this->assertEquals( $dataItem, $instance->getNextDataItem() @@ -299,7 +290,7 @@ private function assertDataItem( $dataItem, $instance ) { ); $this->assertEquals( - array( $dataItem ), + [ $dataItem ], $instance->getContent() ); } diff --git a/tests/phpunit/Unit/ByHttpRequest/JsonResponseParserTest.php b/tests/phpunit/Unit/ByHttpRequest/JsonResponseParserTest.php index 322a4fd..0ef6410 100644 --- a/tests/phpunit/Unit/ByHttpRequest/JsonResponseParserTest.php +++ b/tests/phpunit/Unit/ByHttpRequest/JsonResponseParserTest.php @@ -9,15 +9,14 @@ * @covers \SEQL\ByHttpRequest\JsonResponseParser * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class JsonResponseParserTest extends \PHPUnit_Framework_TestCase { +class JsonResponseParserTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { - $dataValueDeserializer = $this->getMockBuilder( '\SEQL\DataValueDeserializer' ) ->disableOriginalConstructor() ->getMock(); @@ -32,7 +31,6 @@ public function testCanConstruct() { * @dataProvider resultProvider */ public function testDoParse( $result, $rawResponseResult, $hasFurtherResults, $property ) { - $dataValueDeserializer = $this->getMockBuilder( '\SEQL\DataValueDeserializer' ) ->disableOriginalConstructor() ->getMock(); @@ -60,22 +58,21 @@ public function testDoParse( $result, $rawResponseResult, $hasFurtherResults, $p } public function testDoParseForRedirect() { - - $result = array( - 'query' => array( - 'printrequests' => array( - array( 'label' => 'Foo', 'mode' => 2, 'redi' => 'Bar' , 'typeid' => '_wpg' ) - ), - 'results' => array() - ) - ); - - $rawResponseResult = array( - 'printrequests' => array( - array( 'label' => 'Foo', 'mode' => 2, 'redi' => 'Bar' , 'typeid' => '_wpg' ) - ), - 'results' => array() - ); + $result = [ + 'query' => [ + 'printrequests' => [ + [ 'label' => 'Foo', 'mode' => 2, 'redi' => 'Bar', 'typeid' => '_wpg' ] + ], + 'results' => [] + ] + ]; + + $rawResponseResult = [ + 'printrequests' => [ + [ 'label' => 'Foo', 'mode' => 2, 'redi' => 'Bar', 'typeid' => '_wpg' ] + ], + 'results' => [] + ]; $property = new DIProperty( 'Foo' ); $property->setPropertyTypeId( '_wpg' ); @@ -87,7 +84,7 @@ public function testDoParseForRedirect() { $dataValueDeserializer->expects( $this->once() ) ->method( 'getQuerySource' ) - ->will( $this->returnValue( 'abc' ) ); + ->willReturn( 'abc' ); $instance = new JsonResponseParser( $dataValueDeserializer ); @@ -110,64 +107,63 @@ public function testDoParseForRedirect() { } public function resultProvider() { - - #0 - $provider[] = array( - array( 'query' => array() ), - array(), + # 0 + $provider[] = [ + [ 'query' => [] ], + [], false, null - ); + ]; - #1 - $provider[] = array( - array( + # 1 + $provider[] = [ + [ 'query-continue-offset' => 3, - 'query' => array() - ), - array(), + 'query' => [] + ], + [], true, null - ); + ]; - #2 - $provider[] = array( - array( + # 2 + $provider[] = [ + [ 'query-continue-offset' => 3, - 'query' => array( - 'printrequests' => array( - array( 'label' => 'Category', 'mode' => 0 ) - ) - ) - ), - array( - 'printrequests' => array( - array( 'label' => 'Category', 'mode' => 0 ) - ) - ), + 'query' => [ + 'printrequests' => [ + [ 'label' => 'Category', 'mode' => 0 ] + ] + ] + ], + [ + 'printrequests' => [ + [ 'label' => 'Category', 'mode' => 0 ] + ] + ], true, new DIProperty( '_INST' ) - ); - - #3 - $provider[] = array( - array( - 'query' => array( - 'printrequests' => array( - array( 'label' => 'Category', 'mode' => 0 ) - ), - 'results' => array() - ), - ), - array( - 'printrequests' => array( - array( 'label' => 'Category', 'mode' => 0 ) - ), - 'results' => array() - ), + ]; + + # 3 + $provider[] = [ + [ + 'query' => [ + 'printrequests' => [ + [ 'label' => 'Category', 'mode' => 0 ] + ], + 'results' => [] + ], + ], + [ + 'printrequests' => [ + [ 'label' => 'Category', 'mode' => 0 ] + ], + 'results' => [] + ], false, new DIProperty( '_INST' ) - ); + ]; return $provider; } diff --git a/tests/phpunit/Unit/ByHttpRequest/QueryResultFetcherTest.php b/tests/phpunit/Unit/ByHttpRequest/QueryResultFetcherTest.php index c772c92..a7cde8f 100644 --- a/tests/phpunit/Unit/ByHttpRequest/QueryResultFetcherTest.php +++ b/tests/phpunit/Unit/ByHttpRequest/QueryResultFetcherTest.php @@ -4,27 +4,25 @@ use SEQL\ByHttpRequest\QueryResultFetcher; use SEQL\QueryResultFactory; -use SMW\DIWikiPage; use SMW\DIProperty; /** * @covers \SEQL\ByHttpRequest\QueryResultFetcher * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class QueryResultFetcherTest extends \PHPUnit_Framework_TestCase { +class QueryResultFetcherTest extends \PHPUnit\Framework\TestCase { private $store; private $httpRequest; private $httpRequestFactory; private $jsonResponseParser; - protected function setUp() { - + protected function setUp(): void { $this->store = $this->getMockBuilder( '\SMW\Store' ) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -39,7 +37,7 @@ protected function setUp() { $this->httpRequestFactory->expects( $this->any() ) ->method( 'newCachedCurlRequest' ) - ->will( $this->returnValue( $this->httpRequest ) ); + ->willReturn( $this->httpRequest ); $this->jsonResponseParser = $this->getMockBuilder( '\SEQL\ByHttpRequest\JsonResponseParser' ) ->disableOriginalConstructor() @@ -47,19 +45,17 @@ protected function setUp() { } public function testCanConstruct() { - $queryResultFactory = $this->getMockBuilder( '\SEQL\QueryResultFactory' ) ->disableOriginalConstructor() ->getMock(); $this->assertInstanceOf( '\SEQL\ByHttpRequest\QueryResultFetcher', - new QueryResultFetcher( $this->httpRequestFactory, $queryResultFactory, $this->jsonResponseParser ) + new QueryResultFetcher( $this->httpRequestFactory, $queryResultFactory, $this->jsonResponseParser, [] ) ); } public function testFetchEmptyQueryResult() { - $queryResultFactory = new QueryResultFactory( $this->store ); $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) @@ -68,7 +64,7 @@ public function testFetchEmptyQueryResult() { $printRequest->expects( $this->any() ) ->method( 'getSerialisation' ) - ->will( $this->returnValue( '?ABC' ) ); + ->willReturn( '?ABC' ); $description = $this->getMockBuilder( '\SMW\Query\Language\Description' ) ->disableOriginalConstructor() @@ -76,7 +72,7 @@ public function testFetchEmptyQueryResult() { $description->expects( $this->any() ) ->method( 'getPrintrequests' ) - ->will( $this->returnValue( array( $printRequest ) ) ); + ->willReturn( [ $printRequest ] ); $query = $this->getMockBuilder( '\SMWQuery' ) ->disableOriginalConstructor() @@ -84,39 +80,39 @@ public function testFetchEmptyQueryResult() { $query->expects( $this->any() ) ->method( 'getSortKeys' ) - ->will( $this->returnValue( array() ) ); + ->willReturn( [] ); $query->expects( $this->any() ) ->method( 'getExtraPrintouts' ) - ->will( $this->returnValue( array( $printRequest ) ) ); + ->willReturn( [ $printRequest ] ); $query->expects( $this->any() ) ->method( 'getDescription' ) - ->will( $this->returnValue( $description ) ); + ->willReturn( $description ); $instance = new QueryResultFetcher( $this->httpRequestFactory, $queryResultFactory, - $this->jsonResponseParser + $this->jsonResponseParser, + [] ); $this->assertInstanceOf( - '\SMWQueryResult', + '\SMW\Query\QueryResult', $instance->fetchQueryResult( $query ) ); } public function testResetOfPrintRequest() { - $queryResultFactory = new QueryResultFactory( $this->store ); - $dataValue = $this->getMockBuilder( '\SMWPropertyValue' ) + $dataValue = $this->getMockBuilder( '\SMW\DataValues\PropertyValue' ) ->disableOriginalConstructor() ->getMock(); $dataValue->expects( $this->once() ) ->method( 'getDataItem' ) - ->will( $this->returnValue( new DIProperty( 'Foo' ) ) ); + ->willReturn( new DIProperty( 'Foo' ) ); $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) ->disableOriginalConstructor() @@ -124,11 +120,11 @@ public function testResetOfPrintRequest() { $printRequest->expects( $this->any() ) ->method( 'getSerialisation' ) - ->will( $this->returnValue( '?ABC' ) ); + ->willReturn( '?ABC' ); $printRequest->expects( $this->atLeastOnce() ) ->method( 'getData' ) - ->will( $this->returnValue( $dataValue ) ); + ->willReturn( $dataValue ); $description = $this->getMockBuilder( '\SMW\Query\Language\Description' ) ->disableOriginalConstructor() @@ -136,7 +132,7 @@ public function testResetOfPrintRequest() { $description->expects( $this->any() ) ->method( 'getPrintrequests' ) - ->will( $this->returnValue( array( $printRequest ) ) ); + ->willReturn( [ $printRequest ] ); $query = $this->getMockBuilder( '\SMWQuery' ) ->disableOriginalConstructor() @@ -144,30 +140,30 @@ public function testResetOfPrintRequest() { $query->expects( $this->any() ) ->method( 'getSortKeys' ) - ->will( $this->returnValue( array() ) ); + ->willReturn( [] ); $query->expects( $this->any() ) ->method( 'getExtraPrintouts' ) - ->will( $this->returnValue( array( $printRequest ) ) ); + ->willReturn( [ $printRequest ] ); $query->expects( $this->any() ) ->method( 'getDescription' ) - ->will( $this->returnValue( $description ) ); + ->willReturn( $description ); $instance = new QueryResultFetcher( $this->httpRequestFactory, $queryResultFactory, - $this->jsonResponseParser + $this->jsonResponseParser, + [] ); $this->assertInstanceOf( - '\SMWQueryResult', + '\SMW\Query\QueryResult', $instance->fetchQueryResult( $query ) ); } public function testFetchQueryResultWithResponseCache() { - $queryResultFactory = new QueryResultFactory( $this->store ); $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) @@ -176,7 +172,7 @@ public function testFetchQueryResultWithResponseCache() { $printRequest->expects( $this->any() ) ->method( 'getSerialisation' ) - ->will( $this->returnValue( '?ABC' ) ); + ->willReturn( '?ABC' ); $description = $this->getMockBuilder( '\SMW\Query\Language\Description' ) ->disableOriginalConstructor() @@ -184,7 +180,7 @@ public function testFetchQueryResultWithResponseCache() { $description->expects( $this->any() ) ->method( 'getPrintrequests' ) - ->will( $this->returnValue( array( $printRequest ) ) ); + ->willReturn( [ $printRequest ] ); $query = $this->getMockBuilder( '\SMWQuery' ) ->disableOriginalConstructor() @@ -192,20 +188,21 @@ public function testFetchQueryResultWithResponseCache() { $query->expects( $this->any() ) ->method( 'getSortKeys' ) - ->will( $this->returnValue( array() ) ); + ->willReturn( [] ); $query->expects( $this->any() ) ->method( 'getExtraPrintouts' ) - ->will( $this->returnValue( array( $printRequest ) ) ); + ->willReturn( [ $printRequest ] ); $query->expects( $this->any() ) ->method( 'getDescription' ) - ->will( $this->returnValue( $description ) ); + ->willReturn( $description ); $instance = new QueryResultFetcher( $this->httpRequestFactory, $queryResultFactory, - $this->jsonResponseParser + $this->jsonResponseParser, + [] ); $instance->setHttpResponseCacheLifetime( 42 ); @@ -220,20 +217,19 @@ public function testFetchQueryResultWithResponseCache() { $this->httpRequest->expects( $this->at( 0 ) ) ->method( 'setOption' ) - ->with( $this->anything(), $this->equalTo( 42 ) ); + ->with( $this->anything(), 42 ); $this->httpRequest->expects( $this->at( 1 ) ) ->method( 'setOption' ) - ->with( $this->anything(), $this->equalTo( 'Foo:seql:' ) ); + ->with( $this->anything(), 'Foo:seql:' ); $this->assertInstanceOf( - '\SMWQueryResult', + '\SMW\Query\QueryResult', $instance->fetchQueryResult( $query ) ); } public function testHttpRequestToReturnWithError() { - $queryResultFactory = new QueryResultFactory( $this->store ); $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) @@ -242,7 +238,7 @@ public function testHttpRequestToReturnWithError() { $printRequest->expects( $this->any() ) ->method( 'getSerialisation' ) - ->will( $this->returnValue( '?ABC' ) ); + ->willReturn( '?ABC' ); $description = $this->getMockBuilder( '\SMW\Query\Language\Description' ) ->disableOriginalConstructor() @@ -250,7 +246,7 @@ public function testHttpRequestToReturnWithError() { $description->expects( $this->any() ) ->method( 'getPrintrequests' ) - ->will( $this->returnValue( array( $printRequest ) ) ); + ->willReturn( [ $printRequest ] ); $query = $this->getMockBuilder( '\SMWQuery' ) ->disableOriginalConstructor() @@ -258,20 +254,21 @@ public function testHttpRequestToReturnWithError() { $query->expects( $this->any() ) ->method( 'getSortKeys' ) - ->will( $this->returnValue( array() ) ); + ->willReturn( [] ); $query->expects( $this->any() ) ->method( 'getExtraPrintouts' ) - ->will( $this->returnValue( array( $printRequest ) ) ); + ->willReturn( [ $printRequest ] ); $query->expects( $this->any() ) ->method( 'getDescription' ) - ->will( $this->returnValue( $description ) ); + ->willReturn( $description ); $instance = new QueryResultFetcher( $this->httpRequestFactory, $queryResultFactory, - $this->jsonResponseParser + $this->jsonResponseParser, + [] ); $instance->setHttpRequestEndpoint( 'http://example.org/api.php' ); @@ -279,16 +276,15 @@ public function testHttpRequestToReturnWithError() { $this->httpRequest->expects( $this->any() ) ->method( 'execute' ) - ->will( $this->returnValue( json_encode( array( 'error' => array( 'info' => 'error' ) ) ) ) ); + ->willReturn( json_encode( [ 'error' => [ 'info' => 'error' ] ] ) ); $this->assertInstanceOf( - '\SMWQueryResult', + '\SMW\Query\QueryResult', $instance->fetchQueryResult( $query ) ); } public function testHttpRequestToReturnWithValidJson() { - $queryResultFactory = new QueryResultFactory( $this->store ); $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) @@ -297,7 +293,7 @@ public function testHttpRequestToReturnWithValidJson() { $printRequest->expects( $this->any() ) ->method( 'getSerialisation' ) - ->will( $this->returnValue( '?ABC' ) ); + ->willReturn( '?ABC' ); $description = $this->getMockBuilder( '\SMW\Query\Language\Description' ) ->disableOriginalConstructor() @@ -305,7 +301,7 @@ public function testHttpRequestToReturnWithValidJson() { $description->expects( $this->any() ) ->method( 'getPrintrequests' ) - ->will( $this->returnValue( array( $printRequest ) ) ); + ->willReturn( [ $printRequest ] ); $query = $this->getMockBuilder( '\SMWQuery' ) ->disableOriginalConstructor() @@ -313,40 +309,41 @@ public function testHttpRequestToReturnWithValidJson() { $query->expects( $this->any() ) ->method( 'getSortKeys' ) - ->will( $this->returnValue( array() ) ); + ->willReturn( [] ); $query->expects( $this->any() ) ->method( 'getExtraPrintouts' ) - ->will( $this->returnValue( array( $printRequest ) ) ); + ->willReturn( [ $printRequest ] ); $query->expects( $this->any() ) ->method( 'getDescription' ) - ->will( $this->returnValue( $description ) ); + ->willReturn( $description ); $this->jsonResponseParser->expects( $this->any() ) ->method( 'getResultSubjectList' ) - ->will( $this->returnValue( array() ) ); + ->willReturn( [] ); $instance = new QueryResultFetcher( $this->httpRequestFactory, $queryResultFactory, - $this->jsonResponseParser + $this->jsonResponseParser, + [] ); $instance->setHttpRequestEndpoint( 'http://example.org/api.php' ); $instance->setRepositoryTargetUrl( 'http://example.org/$1' ); - $expected = array( + $expected = [ 'query-continue-offset' => 3, - 'query' => array() - ); + 'query' => [] + ]; $this->httpRequest->expects( $this->once() ) ->method( 'execute' ) - ->will( $this->returnValue( json_encode( $expected ) ) ); + ->willReturn( json_encode( $expected ) ); $this->assertInstanceOf( - '\SMWQueryResult', + '\SMW\Query\QueryResult', $instance->fetchQueryResult( $query ) ); } diff --git a/tests/phpunit/Unit/ByHttpRequest/QueryResultTest.php b/tests/phpunit/Unit/ByHttpRequest/QueryResultTest.php index ab9d0d2..992c01d 100644 --- a/tests/phpunit/Unit/ByHttpRequest/QueryResultTest.php +++ b/tests/phpunit/Unit/ByHttpRequest/QueryResultTest.php @@ -9,30 +9,28 @@ * @covers \SEQL\ByHttpRequest\QueryResult * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class QueryResultTest extends \PHPUnit_Framework_TestCase { +class QueryResultTest extends \PHPUnit\Framework\TestCase { private $store; - protected function setUp() { - + protected function setUp(): void { $this->store = $this->getMockBuilder( '\SMW\Store' ) ->disableOriginalConstructor() ->getMockForAbstractClass(); } public function testCanConstruct() { - $query = $this->getMockBuilder( '\SMWQuery' ) ->disableOriginalConstructor() ->getMock(); - $printRequests = array(); - $results = array(); + $printRequests = []; + $results = []; $this->assertInstanceOf( '\SEQL\ByHttpRequest\QueryResult', @@ -41,7 +39,6 @@ public function testCanConstruct() { } public function testGetNext() { - $jsonResponseParser = $this->getMockBuilder( '\SEQL\ByHttpRequest\JsonResponseParser' ) ->disableOriginalConstructor() ->getMock(); @@ -54,13 +51,13 @@ public function testGetNext() { ->disableOriginalConstructor() ->getMock(); - $printRequests = array( + $printRequests = [ $printRequest - ); + ]; - $results = array( + $results = [ new DIWikiPage( 'Foo', NS_MAIN ) - ); + ]; $instance = new QueryResult( $printRequests, $query, $results, $this->store, false ); $instance->setJsonResponseParser( $jsonResponseParser ); @@ -74,10 +71,9 @@ public function testGetNext() { } public function testToArray() { - - $expected = array( + $expected = [ 'Foo' - ); + ]; $query = $this->getMockBuilder( '\SMWQuery' ) ->disableOriginalConstructor() @@ -93,10 +89,10 @@ public function testToArray() { $jsonResponseParser->expects( $this->exactly( 2 ) ) ->method( 'getRawResponseResult' ) - ->will( $this->returnValue( $expected ) ); + ->willReturn( $expected ); - $printRequests = array(); - $results = array(); + $printRequests = []; + $results = []; $instance = new QueryResult( $printRequests, $query, $results, $this->store, false ); $instance->setJsonResponseParser( $jsonResponseParser ); @@ -113,14 +109,13 @@ public function testToArray() { } public function testGetLink() { - $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) ->disableOriginalConstructor() ->getMock(); $printRequest->expects( $this->once() ) ->method( 'getSerialisation' ) - ->will( $this->returnValue( '?ABC' ) ); + ->willReturn( '?ABC' ); $query = $this->getMockBuilder( '\SMWQuery' ) ->disableOriginalConstructor() @@ -128,10 +123,10 @@ public function testGetLink() { $query->expects( $this->any() ) ->method( 'getExtraPrintouts' ) - ->will( $this->returnValue( array( $printRequest ) ) ); + ->willReturn( [ $printRequest ] ); - $printRequests = array(); - $results = array(); + $printRequests = []; + $results = []; $instance = new QueryResult( $printRequests, $query, $results, $this->store, false ); $instance->setRemoteTargetUrl( 'http://example.org:8080' ); diff --git a/tests/phpunit/Unit/ByHttpRequest/ResponsePropertyListTest.php b/tests/phpunit/Unit/ByHttpRequest/ResponsePropertyListTest.php index 66c8c51..14afe80 100644 --- a/tests/phpunit/Unit/ByHttpRequest/ResponsePropertyListTest.php +++ b/tests/phpunit/Unit/ByHttpRequest/ResponsePropertyListTest.php @@ -9,15 +9,14 @@ * @covers \SEQL\ByHttpRequest\ResponsePropertyList * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class ResponsePropertyListTest extends \PHPUnit_Framework_TestCase { +class ResponsePropertyListTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { - $this->assertInstanceOf( '\SEQL\ByHttpRequest\ResponsePropertyList', new ResponsePropertyList( 'abc' ) @@ -25,10 +24,9 @@ public function testCanConstruct() { } public function testGetPropertyForCategory() { - - $value = array( + $value = [ 'label' => 'Category', 'mode' => 0 - ); + ]; $property = new DIProperty( '_INST' ); $property->setInterwiki( 'abc' ); @@ -48,10 +46,9 @@ public function testGetPropertyForCategory() { } public function testGetPropertyForRedirectedProperty() { - - $value = array( - 'label' => 'Foo', 'mode' => 2, 'redi' => 'was redirect from Bar' , 'typeid' => '_wpg' - ); + $value = [ + 'label' => 'Foo', 'mode' => 2, 'redi' => 'was redirect from Bar', 'typeid' => '_wpg' + ]; $property = new DIProperty( 'Foo' ); $property->setInterwiki( 'abc' ); @@ -71,16 +68,15 @@ public function testGetPropertyForRedirectedProperty() { ); $this->assertEquals( - array( 'Foo' => $property ), + [ 'Foo' => $property ], $instance->getPropertyList() ); } public function testTryToRedeclareTypeOfPredefinedPropertyThrowsException() { - - $value = array( + $value = [ 'label' => 'Modification date', 'mode' => 2, 'typeid' => '_wpg' - ); + ]; $instance = new ResponsePropertyList( 'abc' ); diff --git a/tests/phpunit/Unit/ByHttpRequestQueryLookupTest.php b/tests/phpunit/Unit/ByHttpRequestQueryLookupTest.php index 0809e26..8aab333 100644 --- a/tests/phpunit/Unit/ByHttpRequestQueryLookupTest.php +++ b/tests/phpunit/Unit/ByHttpRequestQueryLookupTest.php @@ -8,15 +8,14 @@ * @covers \SEQL\ByHttpRequestQueryLookup * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class ByHttpRequestQueryLookupTest extends \PHPUnit_Framework_TestCase { +class ByHttpRequestQueryLookupTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { - $instance = $this->getMockBuilder( '\SEQL\ByHttpRequestQueryLookup' ) ->disableOriginalConstructor() ->getMock(); @@ -28,7 +27,6 @@ public function testCanConstruct() { } public function testGetQueryResult() { - $description = $this->getMockBuilder( '\SMW\Query\Language\Description' ) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -39,21 +37,20 @@ public function testGetQueryResult() { $query->expects( $this->any() ) ->method( 'getDescription' ) - ->will( $this->returnValue( $description ) ); + ->willReturn( $description ); $instance = $this->getMockBuilder( '\SEQL\ByHttpRequestQueryLookup' ) ->disableOriginalConstructor() - ->setMethods( null ) + ->onlyMethods( [] ) ->getMock(); $this->assertInstanceOf( - '\SMWQueryResult', + '\SMW\Query\QueryResult', $instance->getQueryResult( $query ) ); } public function testGetEmptyQueryResult_MODE_DEBUG() { - $description = $this->getMockBuilder( '\SMW\Query\Language\Description' ) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -64,26 +61,25 @@ public function testGetEmptyQueryResult_MODE_DEBUG() { $query->expects( $this->any() ) ->method( 'getDescription' ) - ->will( $this->returnValue( $description ) ); + ->willReturn( $description ); $query->expects( $this->once() ) ->method( 'addErrors' ); $instance = $this->getMockBuilder( '\SEQL\ByHttpRequestQueryLookup' ) ->disableOriginalConstructor() - ->setMethods( null ) + ->onlyMethods( [] ) ->getMock(); $query->querymode = Query::MODE_DEBUG; $this->assertInstanceOf( - '\SMWQueryResult', + '\SMW\Query\QueryResult', $instance->getQueryResult( $query ) ); } public function testGetQueryResultForSimulatedInterwikiMatch() { - $interwiki = $this->getMockBuilder( '\Interwiki' ) ->disableOriginalConstructor() ->getMock(); @@ -98,27 +94,27 @@ public function testGetQueryResultForSimulatedInterwikiMatch() { $query->expects( $this->any() ) ->method( 'getDescription' ) - ->will( $this->returnValue( $description ) ); + ->willReturn( $description ); $query->expects( $this->atLeastOnce() ) ->method( 'getExtraPrintouts' ) - ->will( $this->returnValue( array() ) ); + ->willReturn( [] ); $query->expects( $this->once() ) ->method( 'getSortKeys' ) - ->will( $this->returnValue( array() ) ); + ->willReturn( [] ); $instance = $this->getMockBuilder( '\SEQL\ByHttpRequestQueryLookup' ) ->disableOriginalConstructor() - ->setMethods( array( 'tryToMatchInterwikiFor' ) ) + ->onlyMethods( [ 'tryToMatchInterwikiFor' ] ) ->getMock(); $instance->expects( $this->once() ) ->method( 'tryToMatchInterwikiFor' ) - ->will( $this->returnValue( $interwiki ) ); + ->willReturn( $interwiki ); $this->assertInstanceOf( - '\SMWQueryResult', + '\SMW\Query\QueryResult', $instance->getQueryResult( $query ) ); } diff --git a/tests/phpunit/Unit/DataValueDeserializerTest.php b/tests/phpunit/Unit/DataValueDeserializerTest.php index d577790..a8a5048 100644 --- a/tests/phpunit/Unit/DataValueDeserializerTest.php +++ b/tests/phpunit/Unit/DataValueDeserializerTest.php @@ -3,23 +3,22 @@ namespace SEQL\Tests; use SEQL\DataValueDeserializer; -use SMW\DIWikiPage; use SMW\DIProperty; +use SMW\DIWikiPage; use SMWDITime as DITime; /** * @covers \SEQL\DataValueDeserializer * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class DataValueDeserializerTest extends \PHPUnit_Framework_TestCase { +class DataValueDeserializerTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { - $this->assertInstanceOf( '\SEQL\DataValueDeserializer', new DataValueDeserializer( 'foo' ) @@ -27,13 +26,12 @@ public function testCanConstruct() { } public function testNewDiWikiPage() { - $instance = new DataValueDeserializer( 'foo' ); - $value = array( + $value = [ 'namespace' => NS_MAIN, 'fulltext' => 'abc def' - ); + ]; $this->assertEquals( new DIWikiPage( 'Foo:abc_def', NS_MAIN ), @@ -42,16 +40,14 @@ public function testNewDiWikiPage() { } public function testTryNewDiWikiPageForInvalidSeralization() { - $instance = new DataValueDeserializer( 'foo' ); $this->assertFalse( - $instance->newDiWikiPage( array( 'Foo' ) ) + $instance->newDiWikiPage( [ 'Foo' ] ) ); } public function testNewTimeValueForOutOfRangeTimestamp() { - $instance = new DataValueDeserializer( 'foo' ); $property = new DIProperty( 'Bar' ); @@ -64,7 +60,6 @@ public function testNewTimeValueForOutOfRangeTimestamp() { } public function testNewTimeValueForRawTimeFromat() { - $instance = new DataValueDeserializer( 'foo' ); $property = new DIProperty( 'Bar' ); @@ -72,27 +67,26 @@ public function testNewTimeValueForRawTimeFromat() { $this->assertEquals( DITime::doUnserialize( '2/-200' ), - $instance->newDataValueFrom( $property, array( 'raw' => '2/-200' ) )->getDataItem() + $instance->newDataValueFrom( $property, [ 'raw' => '2/-200' ] )->getDataItem() ); } public function testNewRecordValue() { - $instance = new DataValueDeserializer( 'foo' ); $property = new DIProperty( 'Foo' ); $property->setPropertyTypeId( '_rec' ); - $item = array( + $item = [ 'namespace' => NS_MAIN, 'fulltext' => 'abc def' - ); + ]; - $record[] = array( + $record[] = [ 'label' => 'Foo', 'typeid' => '_wpg', - 'item' => array( $item ) - ); + 'item' => [ $item ] + ]; $this->assertInstanceOf( '\SMWRecordValue', @@ -101,7 +95,6 @@ public function testNewRecordValue() { } public function testTextValueWithEmbeddedLink() { - $instance = new DataValueDeserializer( 'abc' ); $property = new DIProperty( 'Bar' ); @@ -110,7 +103,7 @@ public function testTextValueWithEmbeddedLink() { $dataValue = $instance->newDataValueFrom( $property, 'Foo [[42]] bar' ); $this->assertInstanceOf( - '\SMWStringValue', + '\SMW\DataValues\StringValue', $dataValue ); diff --git a/tests/phpunit/Unit/DynamicInterwikiPrefixLoaderTest.php b/tests/phpunit/Unit/DynamicInterwikiPrefixLoaderTest.php index de32b95..d83e5e7 100644 --- a/tests/phpunit/Unit/DynamicInterwikiPrefixLoaderTest.php +++ b/tests/phpunit/Unit/DynamicInterwikiPrefixLoaderTest.php @@ -8,16 +8,15 @@ * @covers \SEQL\DynamicInterwikiPrefixLoader * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class DynamicInterwikiPrefixLoaderTest extends \PHPUnit_Framework_TestCase { +class DynamicInterwikiPrefixLoaderTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { - - $interwikiPrefixMap = array(); + $interwikiPrefixMap = []; $this->assertInstanceOf( '\SEQL\DynamicInterwikiPrefixLoader', @@ -26,27 +25,26 @@ public function testCanConstruct() { } public function testLoadIwMapForExternalRepositoryMatch() { - - $interwikiPrefixMap = array( - 'mw-foo' => array( + $interwikiPrefixMap = [ + 'mw-foo' => [ 'http://example.org:8080/mw-foo/index.php/$1', // corresponds to iw_url - 'http://example.org:8080/mw-foo/api.php', // corresponds to iw_api + 'http://example.org:8080/mw-foo/api.php', // corresponds to iw_api true // corresponds to iw_local - ) - ); + ] + ]; $instance = new DynamicInterwikiPrefixLoader( $interwikiPrefixMap ); - $expected = array( + $expected = [ 'iw_prefix' => 'mw-foo', 'iw_url' => 'http://example.org:8080/mw-foo/index.php/$1', 'iw_api' => 'http://example.org:8080/mw-foo/api.php', 'iw_wikiid' => 'mw-foo', 'iw_local' => true, 'iw_trans' => false - ); + ]; - $interwiki = array(); + $interwiki = []; $this->assertFalse( $instance->tryToLoadIwMapForExternalRepository( 'mw-foo', $interwiki ) @@ -59,12 +57,11 @@ public function testLoadIwMapForExternalRepositoryMatch() { } public function testTryLoadIwMapForNoExternalRepositoryMatch() { - - $interwikiPrefixMap = array(); + $interwikiPrefixMap = []; $instance = new DynamicInterwikiPrefixLoader( $interwikiPrefixMap ); - $interwiki = array(); + $interwiki = []; $this->assertTrue( $instance->tryToLoadIwMapForExternalRepository( 'mw-foo', $interwiki ) diff --git a/tests/phpunit/Unit/EmbeddedLinksReplacerTest.php b/tests/phpunit/Unit/EmbeddedLinksReplacerTest.php index 5afdc9d..6a55ed4 100644 --- a/tests/phpunit/Unit/EmbeddedLinksReplacerTest.php +++ b/tests/phpunit/Unit/EmbeddedLinksReplacerTest.php @@ -8,21 +8,20 @@ * @covers \SEQL\EmbeddedLinksReplacer * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class EmbeddedLinksReplacerTest extends \PHPUnit_Framework_TestCase { +class EmbeddedLinksReplacerTest extends \PHPUnit\Framework\TestCase { private $querySource; - protected function setUp() { + protected function setUp(): void { $this->querySource = 'abc'; } public function testCanConstruct() { - $this->assertInstanceOf( '\SEQL\EmbeddedLinksReplacer', new EmbeddedLinksReplacer( $this->querySource ) @@ -33,7 +32,6 @@ public function testCanConstruct() { * @dataProvider textProvider */ public function testReplace( $text, $expected ) { - $instance = new EmbeddedLinksReplacer( $this->querySource ); $this->assertEquals( @@ -43,51 +41,50 @@ public function testReplace( $text, $expected ) { } public function textProvider() { - - #0 - $provider[] = array( + # 0 + $provider[] = [ 'Foo bar', 'Foo bar' - ); + ]; - #1 - $provider[] = array( + # 1 + $provider[] = [ 'Foo [42] bar', 'Foo [42] bar' - ); + ]; - #2 - $provider[] = array( + # 2 + $provider[] = [ 'Foo [42 1001] bar', 'Foo [42 1001] bar' - ); + ]; - #3 - $provider[] = array( + # 3 + $provider[] = [ 'Foo [[42]] bar', 'Foo [[abc:42|42]] bar' - ); + ]; - #4 - $provider[] = array( + # 4 + $provider[] = [ 'Foo [[42|1001]] bar', 'Foo [[abc:42|1001]] bar' - ); + ]; // We can't guess the type of a remote annotation therefore it is turned // into an simple text value #5 - $provider[] = array( + $provider[] = [ 'Foo [[Has number::42]] bar', 'Foo 42 bar' - ); + ]; - #6 - $provider[] = array( + # 6 + $provider[] = [ 'Foo [[Has number::42|1001]] bar', 'Foo 1001 bar' - ); + ]; return $provider; } diff --git a/tests/phpunit/Unit/HookRegistryTest.php b/tests/phpunit/Unit/HookRegistryTest.php index 12e52cc..3569531 100644 --- a/tests/phpunit/Unit/HookRegistryTest.php +++ b/tests/phpunit/Unit/HookRegistryTest.php @@ -8,18 +8,17 @@ * @covers \SEQL\HookRegistry * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class HookRegistryTest extends \PHPUnit_Framework_TestCase { +class HookRegistryTest extends \PHPUnit\Framework\TestCase { public function testCanConstruct() { - - $options = array( - 'externalRepositoryEndpoints' => array(), - ); + $options = [ + 'externalRepositoryEndpoints' => [], + ]; $this->assertInstanceOf( '\SEQL\HookRegistry', @@ -28,10 +27,9 @@ public function testCanConstruct() { } public function testRegister() { - - $options = array( - 'externalRepositoryEndpoints' => array(), - ); + $options = [ + 'externalRepositoryEndpoints' => [], + ]; $instance = new HookRegistry( $options @@ -43,11 +41,10 @@ public function testRegister() { } public function doTestRegisteredInterwikiLoadPrefixHandler( $instance ) { - $handler = 'InterwikiLoadPrefix'; $prefix = ''; - $interwiki = array(); + $interwiki = []; $this->assertTrue( $instance->isRegistered( $handler ) @@ -55,13 +52,12 @@ public function doTestRegisteredInterwikiLoadPrefixHandler( $instance ) { $this->assertThatHookIsExcutable( $instance->getHandlerFor( $handler ), - array( $prefix, &$interwiki ) + [ $prefix, &$interwiki ] ); } private function assertThatHookIsExcutable( \Closure $handler, $arguments ) { - $this->assertInternalType( - 'boolean', + $this->assertIsBool( call_user_func_array( $handler, $arguments ) ); } diff --git a/tests/phpunit/Unit/QueryEncoderTest.php b/tests/phpunit/Unit/QueryEncoderTest.php index 170a519..9df08db 100644 --- a/tests/phpunit/Unit/QueryEncoderTest.php +++ b/tests/phpunit/Unit/QueryEncoderTest.php @@ -8,45 +8,44 @@ * @covers \SEQL\QueryEncoder * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class QueryEncoderTest extends \PHPUnit_Framework_TestCase { +class QueryEncoderTest extends \PHPUnit\Framework\TestCase { /** * @dataProvider queryElementProvider */ public function testEncode( $sortKeys, $extraPrintouts, $expectedEncode, $expectedRawEncode ) { - $query = $this->getMockBuilder( '\SMWQuery' ) ->disableOriginalConstructor() ->getMock(); $query->expects( $this->any() ) ->method( 'getQueryString' ) - ->will( $this->returnValue( '[[Foo::bar]]' ) ); + ->willReturn( '[[Foo::bar]]' ); $query->expects( $this->any() ) ->method( 'getLimit' ) - ->will( $this->returnValue( 42 ) ); + ->willReturn( 42 ); $query->expects( $this->any() ) ->method( 'getOffset' ) - ->will( $this->returnValue( 0 ) ); + ->willReturn( 0 ); $query->expects( $this->any() ) ->method( 'getMainlabel' ) - ->will( $this->returnValue( '' ) ); + ->willReturn( '' ); $query->expects( $this->any() ) ->method( 'getSortKeys' ) - ->will( $this->returnValue( $sortKeys ) ); + ->willReturn( $sortKeys ); $query->expects( $this->any() ) ->method( 'getExtraPrintouts' ) - ->will( $this->returnValue( $extraPrintouts ) ); + ->willReturn( $extraPrintouts ); $this->assertSame( $expectedEncode, @@ -60,62 +59,61 @@ public function testEncode( $sortKeys, $extraPrintouts, $expectedEncode, $expect } public function queryElementProvider() { - - #0 - $provider[] = array( - array(), - array(), + # 0 + $provider[] = [ + [], + [], '[[Foo::bar]]|limit=42|offset=0|mainlabel=', '%5B%5BFoo%3A%3Abar%5D%5D%7Climit%3D42%7Coffset%3D0%7Cmainlabel%3D' - ); + ]; - #1 - $provider[] = array( - array( 'Foobar' => 'DESC' ), - array(), + # 1 + $provider[] = [ + [ 'Foobar' => 'DESC' ], + [], '[[Foo::bar]]|limit=42|offset=0|mainlabel=|sort=Foobar|order=desc', '%5B%5BFoo%3A%3Abar%5D%5D%7Climit%3D42%7Coffset%3D0%7Cmainlabel%3D%7Csort%3DFoobar%7Corder%3Ddesc' - ); + ]; - #2 - $provider[] = array( - array( 'Foobar' => 'DESC', 'Foobaz' => 'ASC' ), - array(), + # 2 + $provider[] = [ + [ 'Foobar' => 'DESC', 'Foobaz' => 'ASC' ], + [], '[[Foo::bar]]|limit=42|offset=0|mainlabel=|sort=Foobar,Foobaz|order=desc,asc', '%5B%5BFoo%3A%3Abar%5D%5D%7Climit%3D42%7Coffset%3D0%7Cmainlabel%3D%7Csort%3DFoobar%2CFoobaz%7Corder%3Ddesc%2Casc' - ); + ]; - #3 + # 3 $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) ->disableOriginalConstructor() ->getMock(); $printRequest->expects( $this->any() ) ->method( 'getSerialisation' ) - ->will( $this->returnValue( '?ABC' ) ); + ->willReturn( '?ABC' ); - $provider[] = array( - array(), - array( $printRequest ), + $provider[] = [ + [], + [ $printRequest ], '[[Foo::bar]]|?ABC|limit=42|offset=0|mainlabel=', '%5B%5BFoo%3A%3Abar%5D%5D%7C%3FABC%7Climit%3D42%7Coffset%3D0%7Cmainlabel%3D' - ); + ]; - #4 (#show returns with an extra =) + # 4 (#show returns with an extra =) $printRequest = $this->getMockBuilder( '\SMW\Query\PrintRequest' ) ->disableOriginalConstructor() ->getMock(); $printRequest->expects( $this->any() ) ->method( 'getSerialisation' ) - ->will( $this->returnValue( '?ABC=' ) ); + ->willReturn( '?ABC=' ); - $provider[] = array( - array(), - array( $printRequest ), + $provider[] = [ + [], + [ $printRequest ], '[[Foo::bar]]|?ABC|limit=42|offset=0|mainlabel=', '%5B%5BFoo%3A%3Abar%5D%5D%7C%3FABC%7Climit%3D42%7Coffset%3D0%7Cmainlabel%3D' - ); + ]; return $provider; } diff --git a/tests/phpunit/Unit/QueryResultFactoryTest.php b/tests/phpunit/Unit/QueryResultFactoryTest.php index 4658e3b..5758c0d 100644 --- a/tests/phpunit/Unit/QueryResultFactoryTest.php +++ b/tests/phpunit/Unit/QueryResultFactoryTest.php @@ -8,24 +8,22 @@ * @covers \SEQL\QueryResultFactory * @group semantic-external-query-lookup * - * @license GNU GPL v2+ + * @license GPL-2.0-or-later * @since 1.0 * * @author mwjames */ -class QueryResultFactoryTest extends \PHPUnit_Framework_TestCase { +class QueryResultFactoryTest extends \PHPUnit\Framework\TestCase { private $store; - protected function setUp() { - + protected function setUp(): void { $this->store = $this->getMockBuilder( '\SMW\Store' ) ->disableOriginalConstructor() ->getMockForAbstractClass(); } public function testCanConstruct() { - $this->assertInstanceOf( '\SEQL\QueryResultFactory', new QueryResultFactory( $this->store ) @@ -33,7 +31,6 @@ public function testCanConstruct() { } public function testNewEmptyQueryResult() { - $description = $this->getMockBuilder( '\SMW\Query\Language\Description' ) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -44,18 +41,17 @@ public function testNewEmptyQueryResult() { $query->expects( $this->any() ) ->method( 'getDescription' ) - ->will( $this->returnValue( $description ) ); + ->willReturn( $description ); $instance = new QueryResultFactory( $this->store ); $this->assertInstanceOf( - '\SMWQueryResult', + '\SMW\Query\QueryResult', $instance->newEmptyQueryResult( $query ) ); } public function testNewByHttpLookupQueryResult() { - $jsonResponseParser = $this->getMockBuilder( '\SEQL\ByHttpRequest\JsonResponseParser' ) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -70,12 +66,12 @@ public function testNewByHttpLookupQueryResult() { $query->expects( $this->any() ) ->method( 'getDescription' ) - ->will( $this->returnValue( $description ) ); + ->willReturn( $description ); $instance = new QueryResultFactory( $this->store ); $this->assertInstanceOf( - '\SMWQueryResult', + '\SMW\Query\QueryResult', $instance->newByHttpRequestQueryResult( $query, $jsonResponseParser ) ); }