From ce49874d9f71962a9a026b76162b93791e94fe3c Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 8 Dec 2014 12:08:52 -0800 Subject: [PATCH] Add checkComposerLockUpToDate.php script Checks whether your composer.lock file is up to date with the current composer.json file. Bug: T77388 Change-Id: I528d63172c238cf1ea9bc02e8eb39b93225865de --- autoload.php | 3 + includes/libs/composer/ComposerJson.php | 54 + includes/libs/composer/ComposerLock.php | 35 + maintenance/checkComposerLockUpToDate.php | 63 ++ tests/phpunit/data/composer/composer.json | 48 + tests/phpunit/data/composer/composer.lock | 921 ++++++++++++++++++ tests/phpunit/data/composer/new-composer.json | 48 + .../libs/composer/ComposerJsonTest.php | 57 ++ .../libs/composer/ComposerLockTest.php | 31 + 9 files changed, 1260 insertions(+) create mode 100644 includes/libs/composer/ComposerJson.php create mode 100644 includes/libs/composer/ComposerLock.php create mode 100644 maintenance/checkComposerLockUpToDate.php create mode 100644 tests/phpunit/data/composer/composer.json create mode 100644 tests/phpunit/data/composer/composer.lock create mode 100644 tests/phpunit/data/composer/new-composer.json create mode 100644 tests/phpunit/includes/libs/composer/ComposerJsonTest.php create mode 100644 tests/phpunit/includes/libs/composer/ComposerLockTest.php diff --git a/autoload.php b/autoload.php index 6cefa13269..b36153a2ca 100644 --- a/autoload.php +++ b/autoload.php @@ -202,6 +202,7 @@ $wgAutoloadLocalClasses = array( 'ChangesListSpecialPage' => __DIR__ . '/includes/specialpage/ChangesListSpecialPage.php', 'ChannelFeed' => __DIR__ . '/includes/Feed.php', 'CheckBadRedirects' => __DIR__ . '/maintenance/checkBadRedirects.php', + 'CheckComposerLockUpToDate' => __DIR__ . '/maintenance/checkComposerLockUpToDate.php', 'CheckExtensionsCLI' => __DIR__ . '/maintenance/language/checkLanguage.inc', 'CheckImages' => __DIR__ . '/maintenance/checkImages.php', 'CheckLanguageCLI' => __DIR__ . '/maintenance/language/checkLanguage.inc', @@ -229,6 +230,8 @@ $wgAutoloadLocalClasses = array( 'CompareParserCache' => __DIR__ . '/maintenance/compareParserCache.php', 'CompareParsers' => __DIR__ . '/maintenance/compareParsers.php', 'ComposerHookHandler' => __DIR__ . '/includes/composer/ComposerHookHandler.php', + 'ComposerJson' => __DIR__ . '/includes/libs/composer/ComposerJson.php', + 'ComposerLock' => __DIR__ . '/includes/libs/composer/ComposerLock.php', 'ComposerPackageModifier' => __DIR__ . '/includes/composer/ComposerPackageModifier.php', 'ComposerVersionNormalizer' => __DIR__ . '/includes/composer/ComposerVersionNormalizer.php', 'CompressOld' => __DIR__ . '/maintenance/storage/compressOld.php', diff --git a/includes/libs/composer/ComposerJson.php b/includes/libs/composer/ComposerJson.php new file mode 100644 index 0000000000..478616515a --- /dev/null +++ b/includes/libs/composer/ComposerJson.php @@ -0,0 +1,54 @@ +hash = md5_file( $location ); + $this->contents = json_decode( file_get_contents( $location ), true ); + } + + public function getHash() { + return $this->hash; + } + + /** + * Dependencies as specified by composer.json + * + * @return array + */ + public function getRequiredDependencies() { + $deps = array(); + foreach ( $this->contents['require'] as $package => $version ) { + if ( $package !== "php" ) { + $deps[$package] = self::normalizeVersion( $version ); + } + } + + return $deps; + } + + /** + * Strip a leading "v" from the version name + * + * @param string $version + * @return string + */ + public static function normalizeVersion( $version ) { + if ( strpos( $version, 'v' ) === 0 ) { + // Composer auto-strips the "v" in front of the tag name + $version = ltrim( $version, 'v' ); + } + + return $version; + } + +} \ No newline at end of file diff --git a/includes/libs/composer/ComposerLock.php b/includes/libs/composer/ComposerLock.php new file mode 100644 index 0000000000..d2b0e8e76f --- /dev/null +++ b/includes/libs/composer/ComposerLock.php @@ -0,0 +1,35 @@ +contents = json_decode( file_get_contents( $location ), true ); + } + + public function getHash() { + return $this->contents['hash']; + } + + /** + * Dependencies currently installed according to composer.lock + * + * @return array + */ + public function getInstalledDependencies() { + $deps = array(); + foreach ( $this->contents['packages'] as $installed ) { + $deps[$installed['name']] = ComposerJson::normalizeVersion( $installed['version'] ); + } + + return $deps; + } +} diff --git a/maintenance/checkComposerLockUpToDate.php b/maintenance/checkComposerLockUpToDate.php new file mode 100644 index 0000000000..5ef2de6f24 --- /dev/null +++ b/maintenance/checkComposerLockUpToDate.php @@ -0,0 +1,63 @@ +mDescription = 'Checks whether your composer.lock file is up to date with the current composer.json'; + } + + public function execute() { + global $IP; + $lockLocation = "$IP/composer.lock"; + $jsonLocation = "$IP/composer.json"; + if ( !file_exists( $lockLocation ) ) { + // Maybe they're using mediawiki/vendor? + $lockLocation = "$IP/vendor/composer.lock"; + if ( !file_exists( $lockLocation ) ) { + $this->error( 'Could not find composer.lock file. Have you run "composer install"?', 1 ); + } + } + + $lock = new ComposerLock( $lockLocation ); + $json = new ComposerJson( $jsonLocation ); + + if ( $lock->getHash() === $json->getHash() ) { + $this->output( "Your composer.lock file is up to date with current dependencies!\n" ); + return; + } + // Out of date, lets figure out which dependencies are old + $found = false; + $installed = $lock->getInstalledDependencies(); + foreach ( $json->getRequiredDependencies() as $name => $version ) { + if ( isset( $installed[$name] ) ) { + if ( $installed[$name] !== $version ) { + $this->output( "$name: {$installed[$name]} installed, $version required.\n" ); + $found = true; + } + } else { + $this->output( "$name: not installed, $version required.\n" ); + $found = true; + } + } + if ( $found ) { + $this->error( 'Error: your composer.lock file is not up to date, run "composer update" to install newer dependencies', 1 ); + } else { + // The hash is the entire composer.json file, so it can be updated without any of the dependencies changing + // We couldn't find any out-of-date dependencies, so assume everything is ok! + $this->output( "Your composer.lock file is up to date with current dependencies!\n" ); + } + + } +} + +$maintClass = 'CheckComposerLockUpToDate'; +require_once RUN_MAINTENANCE_IF_MAIN; \ No newline at end of file diff --git a/tests/phpunit/data/composer/composer.json b/tests/phpunit/data/composer/composer.json new file mode 100644 index 0000000000..bcd196f4fd --- /dev/null +++ b/tests/phpunit/data/composer/composer.json @@ -0,0 +1,48 @@ +{ + "name": "mediawiki/core", + "description": "Free software wiki application developed by the Wikimedia Foundation and others", + "keywords": ["mediawiki", "wiki"], + "homepage": "https://www.mediawiki.org/", + "authors": [ + { + "name": "MediaWiki Community", + "homepage": "https://www.mediawiki.org/wiki/Special:Version/Credits" + } + ], + "license": "GPL-2.0", + "support": { + "issues": "https://bugzilla.wikimedia.org/", + "irc": "irc://irc.freenode.net/mediawiki", + "wiki": "https://www.mediawiki.org/" + }, + "require": { + "leafo/lessphp": "0.5.0", + "php": ">=5.3.3", + "psr/log": "1.0.0", + "cssjanus/cssjanus": "1.1.1", + "cdb/cdb": "1.0.0" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "suggest": { + "ext-fileinfo": "*", + "ext-mbstring": "*", + "ext-wikidiff2": "*", + "ext-apc": "*", + "monolog/monolog": "*" + }, + "autoload": { + "psr-0": { + "ComposerHookHandler": "includes/composer" + } + }, + "scripts": { + "pre-update-cmd": "ComposerHookHandler::onPreUpdate", + "pre-install-cmd": "ComposerHookHandler::onPreInstall" + }, + "config": { + "prepend-autoloader": false, + "optimize-autoloader": true + } +} diff --git a/tests/phpunit/data/composer/composer.lock b/tests/phpunit/data/composer/composer.lock new file mode 100644 index 0000000000..8b490de881 --- /dev/null +++ b/tests/phpunit/data/composer/composer.lock @@ -0,0 +1,921 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "cc6e7fc565b246cb30b0cac103a2b31e", + "packages": [ + { + "name": "cdb/cdb", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/wikimedia/cdb.git", + "reference": "918601ea3d31b8c37312e9c0e54446aa8bfb3425" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wikimedia/cdb/zipball/918601ea3d31b8c37312e9c0e54446aa8bfb3425", + "reference": "918601ea3d31b8c37312e9c0e54446aa8bfb3425", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPLv2" + ], + "authors": [ + { + "name": "Tim Starling", + "email": "tstarling@wikimedia.org" + }, + { + "name": "Chad Horohoe", + "email": "chad@wikimedia.org" + } + ], + "description": "Constant Database (CDB) wrapper library for PHP. Provides pure-PHP fallback when dba_* functions are absent.", + "homepage": "https://www.mediawiki.org/wiki/CDB", + "time": "2014-11-12 19:03:26" + }, + { + "name": "cssjanus/cssjanus", + "version": "v1.1.1", + "source": { + "type": "git", + "url": "https://github.com/cssjanus/php-cssjanus.git", + "reference": "62a9c32e6e140de09082b40a6e99d868ad14d4e0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cssjanus/php-cssjanus/zipball/62a9c32e6e140de09082b40a6e99d868ad14d4e0", + "reference": "62a9c32e6e140de09082b40a6e99d868ad14d4e0", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "jakub-onderka/php-parallel-lint": "0.8.*", + "phpunit/phpunit": "3.7.*", + "squizlabs/php_codesniffer": "1.*" + }, + "type": "library", + "autoload": { + "psr-0": { + "": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "Convert CSS stylesheets between left-to-right and right-to-left.", + "time": "2014-11-14 20:00:50" + }, + { + "name": "leafo/lessphp", + "version": "v0.5.0", + "source": { + "type": "git", + "url": "https://github.com/leafo/lessphp.git", + "reference": "0f5a7f5545d2bcf4e9fad9a228c8ad89cc9aa283" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/leafo/lessphp/zipball/0f5a7f5545d2bcf4e9fad9a228c8ad89cc9aa283", + "reference": "0f5a7f5545d2bcf4e9fad9a228c8ad89cc9aa283", + "shasum": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "lessc.inc.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT", + "GPL-3.0" + ], + "authors": [ + { + "name": "Leaf Corcoran", + "email": "leafot@gmail.com", + "homepage": "http://leafo.net" + } + ], + "description": "lessphp is a compiler for LESS written in PHP.", + "homepage": "http://leafo.net/lessphp/", + "time": "2014-11-24 18:39:20" + }, + { + "name": "psr/log", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", + "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "shasum": "" + }, + "type": "library", + "autoload": { + "psr-0": { + "Psr\\Log\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2012-12-21 11:40:51" + } + ], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", + "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.*@ALPHA" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Instantiator\\": "src" + } + }, + "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": "2014-10-13 12:58:55" + }, + { + "name": "phpunit/php-code-coverage", + "version": "2.0.12", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "7ce9da20f96964bb7a4033f53834df13328dbeab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/7ce9da20f96964bb7a4033f53834df13328dbeab", + "reference": "7ce9da20f96964bb7a4033f53834df13328dbeab", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "~1.0", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4.1" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "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": "2014-12-02 13:17:01" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.3.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", + "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "File/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "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": "2013-10-10 15:34:57" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "Text/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2014-01-30 17:20:04" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "PHP/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "" + ], + "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": "2013-08-02 07:42:54" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "f8d5d08c56de5cfd592b3340424a81733259a876" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/f8d5d08c56de5cfd592b3340424a81733259a876", + "reference": "f8d5d08c56de5cfd592b3340424a81733259a876", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-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": "2014-08-31 06:12:13" + }, + { + "name": "phpunit/phpunit", + "version": "4.3.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2dab9d593997db4abcf58d0daf798eb4e9cecfe1", + "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpunit/php-code-coverage": "~2.0", + "phpunit/php-file-iterator": "~1.3.2", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "~1.0.2", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.0", + "sebastian/diff": "~1.1", + "sebastian/environment": "~1.0", + "sebastian/exporter": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "include-path": [ + "", + "../../symfony/yaml/" + ], + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "http://www.phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2014-11-11 10:11:09" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "c63d2367247365f688544f0d500af90a11a44c65" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c63d2367247365f688544f0d500af90a11a44c65", + "reference": "c63d2367247365f688544f0d500af90a11a44c65", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "~1.0,>=1.0.1", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.3" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.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": "2014-10-03 05:12:11" + }, + { + "name": "sebastian/comparator", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", + "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.1", + "sebastian/exporter": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.1" + }, + "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": "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": "2014-05-11 23:00:21" + }, + { + "name": "sebastian/diff", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "5843509fed39dee4b356a306401e9dd1a931fec7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/5843509fed39dee4b356a306401e9dd1a931fec7", + "reference": "5843509fed39dee4b356a306401e9dd1a931fec7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-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": "http://www.github.com/sebastianbergmann/diff", + "keywords": [ + "diff" + ], + "time": "2014-08-15 10:29:00" + }, + { + "name": "sebastian/environment", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6e6c71d918088c251b181ba8b3088af4ac336dd7", + "reference": "6e6c71d918088c251b181ba8b3088af4ac336dd7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.3" + }, + "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": "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": "2014-10-25 08:00:45" + }, + { + "name": "sebastian/exporter", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", + "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.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": "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": "2014-09-10 00:51:36" + }, + { + "name": "sebastian/version", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", + "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", + "shasum": "" + }, + "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": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2014-03-07 15:35:33" + }, + { + "name": "symfony/yaml", + "version": "v2.6.0", + "target-dir": "Symfony/Component/Yaml", + "source": { + "type": "git", + "url": "https://github.com/symfony/Yaml.git", + "reference": "51c845cf3e4bfc182d1d5c05ed1c7338361d86f8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/51c845cf3e4bfc182d1d5c05ed1c7338361d86f8", + "reference": "51c845cf3e4bfc182d1d5c05ed1c7338361d86f8", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Yaml\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony Yaml Component", + "homepage": "http://symfony.com", + "time": "2014-11-20 13:24:23" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "platform": { + "php": ">=5.3.3" + }, + "platform-dev": [] +} diff --git a/tests/phpunit/data/composer/new-composer.json b/tests/phpunit/data/composer/new-composer.json new file mode 100644 index 0000000000..0634c2ddbf --- /dev/null +++ b/tests/phpunit/data/composer/new-composer.json @@ -0,0 +1,48 @@ +{ + "name": "mediawiki/core", + "description": "Free software wiki application developed by the Wikimedia Foundation and others", + "keywords": ["mediawiki", "wiki"], + "homepage": "https://www.mediawiki.org/", + "authors": [ + { + "name": "MediaWiki Community", + "homepage": "https://www.mediawiki.org/wiki/Special:Version/Credits" + } + ], + "license": "GPL-2.0", + "support": { + "issues": "https://bugzilla.wikimedia.org/", + "irc": "irc://irc.freenode.net/mediawiki", + "wiki": "https://www.mediawiki.org/" + }, + "require": { + "leafo/lessphp": "0.5.0", + "php": ">=5.3.3", + "psr/log": "1.0.0", + "cssjanus/cssjanus": "1.1.1", + "wikimedia/cdb": "1.0.1" + }, + "require-dev": { + "phpunit/phpunit": "*" + }, + "suggest": { + "ext-fileinfo": "*", + "ext-mbstring": "*", + "ext-wikidiff2": "*", + "ext-apc": "*", + "monolog/monolog": "*" + }, + "autoload": { + "psr-0": { + "ComposerHookHandler": "includes/composer" + } + }, + "scripts": { + "pre-update-cmd": "ComposerHookHandler::onPreUpdate", + "pre-install-cmd": "ComposerHookHandler::onPreInstall" + }, + "config": { + "prepend-autoloader": false, + "optimize-autoloader": true + } +} diff --git a/tests/phpunit/includes/libs/composer/ComposerJsonTest.php b/tests/phpunit/includes/libs/composer/ComposerJsonTest.php new file mode 100644 index 0000000000..5c5c828a07 --- /dev/null +++ b/tests/phpunit/includes/libs/composer/ComposerJsonTest.php @@ -0,0 +1,57 @@ +json = "$IP/tests/phpunit/data/composer/composer.json"; + $this->json2 = "$IP/tests/phpunit/data/composer/new-composer.json"; + } + + public static function provideGetHash() { + return array( + array( 'json', 'cc6e7fc565b246cb30b0cac103a2b31e' ), + array( 'json2', '19921dd1fc457f1b00561da932432001' ), + ); + } + + /** + * @dataProvider provideGetHash + * @covers ComposerJsonParser::getHash + */ + public function testIsHashUpToDate( $file, $expected ) { + $json = new ComposerJson( $this->$file ); + $this->assertEquals( $expected, $json->getHash() ); + } + + /** + * @covers ComposerLockComparer::getRequiredDependencies + */ + public function testGetRequiredDependencies() { + $json = new ComposerJson( $this->json ); + $this->assertArrayEquals( array( + 'cdb/cdb' => '1.0.0', + 'cssjanus/cssjanus' => '1.1.1', + 'leafo/lessphp' => '0.5.0', + 'psr/log' => '1.0.0', + ), $json->getRequiredDependencies(), false, true ); + } + + public static function provideNormalizeVersion() { + return array( + array( 'v1.0.0', '1.0.0' ), + array( '0.0.5', '0.0.5' ), + ); + } + + /** + * @dataProvider provideNormalizeVersion + * @covers ComposerJsonParser::normalizeVersion + */ + public function testNormalizeVersion( $input, $expected ) { + $this->assertEquals( $expected, ComposerJson::normalizeVersion( $input ) ); + } +} diff --git a/tests/phpunit/includes/libs/composer/ComposerLockTest.php b/tests/phpunit/includes/libs/composer/ComposerLockTest.php new file mode 100644 index 0000000000..5b09cdb880 --- /dev/null +++ b/tests/phpunit/includes/libs/composer/ComposerLockTest.php @@ -0,0 +1,31 @@ +lock = "$IP/tests/phpunit/data/composer/composer.lock"; + } + + public function testGetHash() { + $lock = new ComposerLock( $this->lock ); + $this->assertEquals( 'cc6e7fc565b246cb30b0cac103a2b31e', $lock->getHash() ); + } + + /** + * @covers ComposerLockParser::getInstalledDependencies + */ + public function testGetInstalledDependencies() { + $lock = new ComposerLock( $this->lock ); + $this->assertArrayEquals( array( + 'cdb/cdb' => '1.0.0', + 'cssjanus/cssjanus' => '1.1.1', + 'leafo/lessphp' => '0.5.0', + 'psr/log' => '1.0.0', + ), $lock->getInstalledDependencies(), false, true ); + } + +} -- 2.20.1