diff --git a/.editorconfig b/.editorconfig index 70778bf..ba60096 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,7 +6,7 @@ charset = utf-8 end_of_line = lf indent_size = 4 -indent_style = tab +indent_style = space insert_final_newline = true trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore index b307e14..ec7927e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/src/ +/assets/ /htdocs/2.4/ /htdocs/master/ /htdocs/3.*/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..29620c7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: php + +php: + - 5.6 + - 7.1 + +before_script: + - composer install --dev + +script: + - vendor/bin/phpunit diff --git a/README.md b/README.md index 57acdd2..78c58dc 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,9 @@ generated through [APIGen](http://apigen.org/). * Update the redirections in `htdocs/.htaccess` to the stable version number * Make a separate commit with the redirection (explained in deployment below) +**Please note:** Often the `master` branch will be representing an unstable major version (currently 4). When this needs +to be updated, please edit `htdocs/search/lookup.php`. + ### Deployment to production 1. Raise a ticket with ops team (they have to run a script after deployment) 2. Login to SilverStripe Platform (you'll need to ensure you have "api" stack permissions) @@ -56,11 +59,13 @@ Parameters: * `q`: (required) Class name, method name (`::()` or ->()`), as well as property name ((`::$` or ->`). - * `version`: (optional) Version of the targeted module. Should map to a folder name. Defaults to trunk. + * `version`: (optional) Version of the targeted module. Should map to a folder name. Defaults to trunk. Will switch current unstable major version (e.g. 4) to "master". * `module`: (optional) Module name. Should map to a folder name. Defaults to framework. Examples: * `/search/lookup.php?q=DataObject`: Shows `DataObject` docs in `trunk` version of framework * `/search/lookup.php?q=DataObject::get()&version=3.0`: Shows `DataObject::get()` docs in `3.0` version of framework - * `/search/lookup.php?q=DPSPayment&module=payemtn`: Shows `DPSPayment` class docs in the `ecommerce` module \ No newline at end of file + * `/search/lookup.php?q=DataObject::get()&version=3.0`: Shows `DataObject::get()` docs in `3.6` version of framework (or whatever is the latest stable minor version) + * `/search/lookup.php?q=DPSPayment&module=payemnt`: Shows `DPSPayment` class docs in the `ecommerce` module + * `/search/lookup.php?q=SilverStripe\ORM\DataExtension::onBeforeWrite()&version=4`: Shows `SilverStripe\ORM\DataExtension::onBeforeWrite()` docs in `master` (4.x) version of framework diff --git a/composer.json b/composer.json index 633a6f8..177d3ef 100644 --- a/composer.json +++ b/composer.json @@ -9,12 +9,22 @@ } ], "require": { - "apigen/apigen": "2.8.x-dev" + "apigen/apigen": "2.8.x-dev", + "symfony/yaml": "^3.3" }, - "repositories": [ - { - "type": "vcs", - "url": "git@github.com:silverstripe-labs/ApiGen.git" - } - ] + "repositories": [ + { + "type": "vcs", + "url": "git@github.com:silverstripe-labs/ApiGen.git" + } + ], + "autoload": { + "psr-4": { + "SilverStripe\\ApiDocs\\": "src/", + "SilverStripe\\ApiDocs\\Test\\": "tests/" + } + }, + "require-dev": { + "phpunit/phpunit": "^5.7" + } } diff --git a/composer.lock b/composer.lock index 34f438c..301a084 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "8473e4f4ff354f4791932c040080bfee", + "content-hash": "fe27a4996880cf928629546e1c416c2b", "packages": [ { "name": "andrewsville/php-token-reflection", @@ -50,19 +50,19 @@ "reflection", "tokenizer" ], - "time": "2012-08-25 21:26:44" + "time": "2012-08-25T21:26:44+00:00" }, { "name": "apigen/apigen", "version": "2.8.x-dev", "source": { "type": "git", - "url": "https://github.com/silverstripe-labs/ApiGen.git", + "url": "https://github.com/silverstripe-archive/ApiGen.git", "reference": "a589f78fd2a6fcd0205f11cdb761f5784a97784f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/silverstripe-labs/ApiGen/zipball/a589f78fd2a6fcd0205f11cdb761f5784a97784f", + "url": "https://api.github.com/repos/silverstripe-archive/ApiGen/zipball/a589f78fd2a6fcd0205f11cdb761f5784a97784f", "reference": "a589f78fd2a6fcd0205f11cdb761f5784a97784f", "shasum": "" }, @@ -170,7 +170,7 @@ "library", "syntax" ], - "time": "2012-09-08 19:00:07" + "time": "2012-09-08T19:00:07+00:00" }, { "name": "nette/nette", @@ -258,7 +258,62 @@ "mvc", "templating" ], - "time": "2015-05-06 21:05:47" + "time": "2015-05-06T21:05:47+00:00" + }, + { + "name": "symfony/yaml", + "version": "v3.3.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/9752a30000a8ca9f4b34b5227d15d0101b96b063", + "reference": "9752a30000a8ca9f4b34b5227d15d0101b96b063", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "require-dev": { + "symfony/console": "~2.8|~3.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2017-06-02T22:05:06+00:00" }, { "name": "texy/texy", @@ -314,10 +369,1269 @@ "wiki", "xhtml" ], - "time": "2014-02-10 02:34:57" + "time": "2014-02-10T02:34:57+00:00" + } + ], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2015-06-14T21:17:01+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.6.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/8e6e04167378abf1ddb4d3522d8755c5fd90d102", + "reference": "8e6e04167378abf1ddb4d3522d8755c5fd90d102", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "doctrine/collections": "1.*", + "phpunit/phpunit": "~4.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "homepage": "https://github.com/myclabs/DeepCopy", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2017-04-12T18:52:22+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2015-12-27T11:43:31+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "3.1.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "reference": "8331b5efe816ae05461b7ca1e721c01b46bafb3e", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0@dev", + "phpdocumentor/type-resolver": "^0.2.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2016-09-30T07:12:33+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.2.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "reference": "e224fb2ea2fba6d3ad6fdaef91cd09a172155ccb", + "shasum": "" + }, + "require": { + "php": ">=5.5", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2016-11-25T06:54:22+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "v1.7.0", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "93d39f1f7f9326d746203c7c056f300f7f126073" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/93d39f1f7f9326d746203c7c056f300f7f126073", + "reference": "93d39f1f7f9326d746203c7c056f300f7f126073", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", + "sebastian/comparator": "^1.1|^2.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8 || ^5.6.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2017-03-02T20:05:34+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "4.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^5.6 || ^7.0", + "phpunit/php-file-iterator": "^1.3", + "phpunit/php-text-template": "^1.2", + "phpunit/php-token-stream": "^1.4.2 || ^2.0", + "sebastian/code-unit-reverse-lookup": "^1.0", + "sebastian/environment": "^1.3.2 || ^2.0", + "sebastian/version": "^1.0 || ^2.0" + }, + "require-dev": { + "ext-xdebug": "^2.1.4", + "phpunit/phpunit": "^5.7" + }, + "suggest": { + "ext-xdebug": "^2.5.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2017-04-02T07:44:40+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2016-10-03T07:40:28+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2017-02-26T11:10:40+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.11", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", + "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2017-02-27T10:12:30+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "5.7.20", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "3cb94a5f8c07a03c8b7527ed7468a2926203f58b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3cb94a5f8c07a03c8b7527ed7468a2926203f58b", + "reference": "3cb94a5f8c07a03c8b7527ed7468a2926203f58b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "~1.3", + "php": "^5.6 || ^7.0", + "phpspec/prophecy": "^1.6.2", + "phpunit/php-code-coverage": "^4.0.4", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "^1.0.6", + "phpunit/phpunit-mock-objects": "^3.2", + "sebastian/comparator": "^1.2.4", + "sebastian/diff": "^1.4.3", + "sebastian/environment": "^1.3.4 || ^2.0", + "sebastian/exporter": "~2.0", + "sebastian/global-state": "^1.1", + "sebastian/object-enumerator": "~2.0", + "sebastian/resource-operations": "~1.0", + "sebastian/version": "~1.0.3|~2.0", + "symfony/yaml": "~2.1|~3.0" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-xdebug": "*", + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.7.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2017-05-22T07:42:55+00:00" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "3.4.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "3ab72b65b39b491e0c011e2e09bb2206c2aa8e24" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/3ab72b65b39b491e0c011e2e09bb2206c2aa8e24", + "reference": "3ab72b65b39b491e0c011e2e09bb2206c2aa8e24", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.6 || ^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^1.2 || ^2.0" + }, + "conflict": { + "phpunit/phpunit": "<5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2016-12-08T20:27:08+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" + }, + { + "name": "sebastian/comparator", + "version": "1.2.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2 || ~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2017-01-29T09:50:25+00:00" + }, + { + "name": "sebastian/diff", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2017-05-22T07:24:03+00:00" + }, + { + "name": "sebastian/environment", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2016-11-26T07:53:53+00:00" + }, + { + "name": "sebastian/exporter", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2016-11-19T08:54:04+00:00" + }, + { + "name": "sebastian/global-state", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2015-10-12T03:26:01+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/1311872ac850040a79c3c058bea3e22d0f09cbb7", + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-02-18T15:18:39+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2016-11-19T07:33:16+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "shasum": "" + }, + "require": { + "php": ">=5.6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28T20:34:47+00:00" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03T07:35:21+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", + "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2016-11-23T20:04:58+00:00" } ], - "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": { diff --git a/htdocs/search/lookup.php b/htdocs/search/lookup.php index f0265fd..78bd1ae 100644 --- a/htdocs/search/lookup.php +++ b/htdocs/search/lookup.php @@ -3,41 +3,13 @@ // to their URL representation in the API docs. Redirects to this URL. // See README for more info. -$paths = array(); +require_once __DIR__ . '/../../vendor/autoload.php'; -// Module -// Only include modules path if we're not request core. -if(@$_GET['module'] && !in_array($_GET['module'], array('cms', 'framework', 'sapphire'))) { - $paths[] = 'modules/' . $_GET['module']; -} +$lookup = new SilverStripe\ApiDocs\Lookup($_GET); -// Version -$paths[] = (@$_GET['version']) ? $_GET['version'] : 'trunk'; +$lookup->setVersionMap(array( + '4' => 'master', + '3' => '3.6' +)); -// Search -if($searchOrig = @$_GET['q']) { - $search = str_replace(array('()', '$'), '', $searchOrig); - $searchParts = preg_split('/(::|\->)/', $search); - $searchConfig = array(); - if(count($searchParts) == 2) { - $searchConfig['class'] = $searchParts[0]; - $searchConfig['property'] = $searchParts[1]; - $searchConfig['type'] = (strpos($searchOrig, '()') !== FALSE) ? 'method' : 'property'; - } else { - $searchConfig['class'] = $search; - $searchConfig['property'] = ''; - $searchConfig['type'] = 'class'; - } - $searchPath = 'class-' . $searchConfig['class'] . '.html'; - if($searchConfig['property']) { - if($searchConfig['type'] == 'method') { - $searchPath .= '#_' . $searchConfig['property']; - } else { - $searchPath .= '#$' . $searchConfig['property']; - } - } - $paths[] = $searchPath; - -} -$url = 'http://' . $_SERVER['SERVER_NAME'] . '/' . implode('/', array_filter($paths)); -header('Location: ' . $url); \ No newline at end of file +$lookup->handle(); diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..374d6dd --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,7 @@ + + + + tests + + + diff --git a/src/.htaccess b/src/.htaccess deleted file mode 100644 index e04db96..0000000 --- a/src/.htaccess +++ /dev/null @@ -1,2 +0,0 @@ -# The SilverStripe source code does not have to be accessible through the web -deny from all \ No newline at end of file diff --git a/src/Lookup.php b/src/Lookup.php new file mode 100644 index 0000000..1910015 --- /dev/null +++ b/src/Lookup.php @@ -0,0 +1,243 @@ +args = $args; + } + + /** + * @return string[] + */ + public function getArgs() + { + return $this->args; + } + + /** + * Return an argument from the array + * + * @param string $key + * @return string + */ + public function getArg($key) + { + if (array_key_exists($key, $this->args)) { + return $this->args[$key]; + } + } + + /** + * Redirect the user to where they need to go + * + * @param bool $return When true, the redirect URL will be returned instead of a header issued + * @return string|null + */ + public function handle($return = false) + { + $paths = array(); + + // Only include modules path if we're not request core. + if ($this->getArg('module') && !in_array($this->getArg('module'), array('cms', 'framework', 'sapphire'))) { + $paths[] = 'modules/' . $this->getArg('module'); + } + + $paths[] = $this->getVersion(); + + // Search + if ($searchOrig = $this->getArg('q')) { + $search = str_replace(array('()', '$'), '', $searchOrig); + $searchParts = preg_split('/(::|\->)/', $search); + $searchConfig = array(); + if (count($searchParts) == 2) { + $searchConfig['class'] = $searchParts[0]; + $searchConfig['property'] = $searchParts[1]; + $searchConfig['type'] = (strpos($searchOrig, '()') !== false) ? 'method' : 'property'; + } else { + $searchConfig['class'] = $search; + $searchConfig['property'] = ''; + $searchConfig['type'] = 'class'; + } + $searchConfig['class'] = $this->getWithNamespace($searchConfig['class']); + $searchPath = 'class-' . $searchConfig['class'] . '.html'; + if ($searchConfig['property']) { + if ($searchConfig['type'] == 'method') { + $searchPath .= '#_' . $searchConfig['property']; + } else { + $searchPath .= '#$' . $searchConfig['property']; + } + } + $paths[] = $searchPath; + } + + $url = 'http://' . $this->getServerName() . '/' . implode('/', array_filter($paths)); + + if ($return) { + return $url; + } + header('Location: ' . $url); + } + + /** + * Allow setting the "version mapping" that can be used to convert "4" to "master", etc + * + * @param array $map + * @return $this + */ + public function setVersionMap($map) + { + $this->versionMap = $map; + return $this; + } + + /** + * Get the version from the URL, check for manually set version mapping + * + * @return string + */ + public function getVersion() + { + $version = $this->getArg('version') ?: self::DEFAULT_BRANCH; + if (array_key_exists($version, $this->versionMap)) { + return $this->versionMap[$version]; + } + return $version; + } + + /** + * Using any available silverstripe/upgrader mapping files, see if we can convert an unqualified class name + * into a fully qualified one + * + * @param string $class + * @param bool $sanitise Whether to have the return value sanitised + * @return string + */ + public function getWithNamespace($class, $sanitise = true) + { + $map = $this->getUpgraderMap(); + if (!empty($map) && array_key_exists($class, $map)) { + $class = $map[$class]; + } + + if ($sanitise) { + return $this->sanitiseNamespaces($class); + } + + return $class; + } + + /** + * Look for silverstripe/upgrader .upgrade.yml mapping files in this version's core modules. If found, combine + * them and return whether or not anything useful was found. + * + * @return bool + */ + public function getUpgraderMap() + { + if ($this->upgraderMap) { + return $this->upgraderMap; + } + + $mapFilePaths = __DIR__ . '/../assets/src/' . $this->getVersion() . '/*/.upgrade.yml'; + foreach (glob($mapFilePaths) as $mapFile) { + try { + $mapping = (array) Yaml::parse(file_get_contents($mapFile)); + } catch (\Symfony\Component\Yaml\ParseException $ex) { + // Fail gracefully here + } + if (!empty($mapping['mappings'])) { + $this->upgraderMap = array_merge($this->upgraderMap, $mapping['mappings']); + } + } + return $this->upgraderMap; + } + + /** + * Allow ability to set the upgrader mapping manually. Useful for tests. + * + * @param array $map + * @return $this + */ + public function setUpgraderMap($map) + { + $this->upgraderMap = $map; + return $this; + } + + /** + * Returns the given class name with any namespace backslashes replaced with periods, and the leading slash + * trimmed off. + * + * @param string $class E.g. \SilverStripe\ORM\DataExtension + * @return string E.g. SilverStripe.ORM.DataExtension + */ + public function sanitiseNamespaces($class) + { + return str_replace('\\', '.', ltrim($class, '\\')); + } + + /** + * Get the server name to use for API reference links. Defaults to retrieving a server variable. + * + * @return string + */ + public function getServerName() + { + if ($this->serverName) { + return $this->serverName; + } + return $_SERVER['SERVER_NAME']; + } + + /** + * Set the server name to use for API reference links + * + * @param string $name + * @return $this + */ + public function setServerName($name) + { + $this->serverName = $name; + return $this; + } +} diff --git a/tests/LookupTest.php b/tests/LookupTest.php new file mode 100644 index 0000000..3a658b7 --- /dev/null +++ b/tests/LookupTest.php @@ -0,0 +1,162 @@ + 'bar', 'bar' => 'baz'); + $lookup = new Lookup($input); + + $this->assertSame('bar', $lookup->getArg('foo')); + $this->assertNull($lookup->getArg('animal')); + $this->assertSame($input, $lookup->getArgs()); + } + + /** + * End to end tests + * + * @param array $input + * @param string $expected + * @dataProvider handleProvider + */ + public function testHandle($input, $expected) + { + $lookup = new Lookup($input); + $lookup->setServerName('mockserver'); + $lookup->setVersionMap(array('4' => 'master', '3' => '3.6')); + + if (empty($input['version']) || in_array($input['version'], array('master', '4'))) { + $lookup->setUpgraderMap(array( + 'DataExtension' => 'SilverStripe\ORM\DataExtension', + 'SiteTree' => 'SilverStripe\CMS\Model\SiteTree', + 'Director' => 'SilverStripe\Control\Director' + )); + } + + $this->assertSame($expected, $lookup->handle(true)); + } + + /** + * @return array[] + */ + public function handleProvider() + { + return array( + array( + array('q' => 'DataExtension', 'version' => '4'), + 'http://mockserver/master/class-SilverStripe.ORM.DataExtension.html' + ), + array( + array('q' => 'DataExtension'), + 'http://mockserver/master/class-SilverStripe.ORM.DataExtension.html' + ), + array( + array('q' => 'SomeClass'), + 'http://mockserver/master/class-SomeClass.html' + ), + array( + array('q' => 'SomeClass', 'version' => '3'), + 'http://mockserver/3.6/class-SomeClass.html' + ), + array( + array('q' => 'SomeClass', 'version' => '3.4'), + 'http://mockserver/3.4/class-SomeClass.html' + ), + array( + array('q' => '\Already\Fully\Qualified', 'version' => '3.4'), + 'http://mockserver/3.4/class-Already.Fully.Qualified.html' + ), + array( + array('q' => 'Director', 'module' => 'framework'), + 'http://mockserver/master/class-SilverStripe.Control.Director.html' + ), + array( + array('q' => 'SiteTree::write()', 'module' => 'cms'), + 'http://mockserver/master/class-SilverStripe.CMS.Model.SiteTree.html#_write' + ), + array( + array('q' => 'SiteTree::$allowed_children', 'module' => 'cms'), + 'http://mockserver/master/class-SilverStripe.CMS.Model.SiteTree.html#$allowed_children' + ), + ); + } + + /** + * Ensure that when major versions are provided, they are converted to the appropriate branch name to provide + * relevant API docs + * + * @param string $version + * @param string $expected + * @dataProvider versionProvider + */ + public function testGetVersions($version, $expected) + { + $lookup = new Lookup(array('version' => $version)); + $lookup->setVersionMap(array('4' => 'master', '3' => '3.6')); + $this->assertSame($expected, $lookup->getVersion()); + } + + /** + * @return array[] + */ + public function versionProvider() + { + return array( + array('master', 'master'), + array('4', 'master'), + array('3', '3.6'), + array('3.5', '3.5'), + array('3.4', '3.4'), + ); + } + + /** + * Ensure that class names, whether namespaced or not, are handled correctly + * + * @param string $class + * @param string $expected + * @dataProvider classNameProvider + */ + public function testSanitiseClassNames($class, $expected) + { + $this->assertSame($expected, (new Lookup)->sanitiseNamespaces($class)); + } + + /** + * @return array[] + */ + public function classNameProvider() + { + return array( + array('Director', 'Director'), + array('SilverStripe\ORM\DataExtension', 'SilverStripe.ORM.DataExtension'), + array('\SilverStripe\ORM\DataExtension', 'SilverStripe.ORM.DataExtension'), + array('\Convert', 'Convert') + ); + } + + /** + * Ensure that the namespace for a class can be acquired from a map of upgrader class names + */ + public function testGetNamespacesForClass() + { + $lookup = new Lookup; + $lookup->setUpgraderMap(array( + 'DataExtension' => 'SilverStripe\ORM\DataExtension', + 'SiteTree' => 'SilverStripe\CMS\Model\SiteTree', + 'Director' => 'SilverStripe\Control\Director' + )); + + $this->assertSame('SilverStripe\ORM\DataExtension', $lookup->getWithNamespace('DataExtension', false)); + $this->assertSame('SilverStripe\CMS\Model\SiteTree', $lookup->getWithNamespace('SiteTree', false)); + $this->assertSame('SilverStripe\Control\Director', $lookup->getWithNamespace('Director', false)); + $this->assertSame('SilverStripe.Control.Director', $lookup->getWithNamespace('Director', true)); + } +}