checkComposerLockUpToDate: Always check dependencies
authorKunal Mehta <legoktm@member.fsf.org>
Sun, 16 Oct 2016 19:49:41 +0000 (12:49 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Sun, 16 Oct 2016 19:49:41 +0000 (12:49 -0700)
Upstream composer has replaced the 'hash' with a smarter 'content-hash',
but instead of re-implementing (or copy-pasting) all of that in MediaWiki
we can just compare the dependencies themselves, since that's all we
care about.

Bug: T147189
Change-Id: Ic2f22a82699e2b707b6ccb355605999a183a56a0

includes/libs/composer/ComposerJson.php
includes/libs/composer/ComposerLock.php
maintenance/checkComposerLockUpToDate.php
tests/phpunit/includes/libs/composer/ComposerJsonTest.php
tests/phpunit/includes/libs/composer/ComposerLockTest.php

index 311508f..62231a8 100644 (file)
@@ -12,14 +12,9 @@ class ComposerJson {
         * @param string $location
         */
        public function __construct( $location ) {
-               $this->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
         *
index e93127c..818ccdf 100644 (file)
@@ -15,10 +15,6 @@ class ComposerLock {
                $this->contents = json_decode( file_get_contents( $location ), true );
        }
 
-       public function getHash() {
-               return $this->contents['hash'];
-       }
-
        /**
         * Dependencies currently installed according to composer.lock
         *
index 9ec61dc..3f0a83d 100644 (file)
@@ -34,11 +34,7 @@ class CheckComposerLockUpToDate extends Maintenance {
                $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
+               // Check all the dependencies to see if any are old
                $found = false;
                $installed = $lock->getInstalledDependencies();
                foreach ( $json->getRequiredDependencies() as $name => $version ) {
@@ -61,8 +57,6 @@ class CheckComposerLockUpToDate extends Maintenance {
                                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" );
                }
index 3cde3e2..ded5f8f 100644 (file)
@@ -11,22 +11,6 @@ class ComposerJsonTest extends MediaWikiTestCase {
                $this->json2 = "$IP/tests/phpunit/data/composer/new-composer.json";
        }
 
-       public static function provideGetHash() {
-               return [
-                       [ 'json', 'cc6e7fc565b246cb30b0cac103a2b31e' ],
-                       [ 'json2', '19921dd1fc457f1b00561da932432001' ],
-               ];
-       }
-
-       /**
-        * @dataProvider provideGetHash
-        * @covers ComposerJson::getHash
-        */
-       public function testIsHashUpToDate( $file, $expected ) {
-               $json = new ComposerJson( $this->$file );
-               $this->assertEquals( $expected, $json->getHash() );
-       }
-
        /**
         * @covers ComposerJson::__construct
         * @covers ComposerJson::getRequiredDependencies
index 3d5e8d3..eef7e27 100644 (file)
@@ -10,14 +10,6 @@ class ComposerLockTest extends MediaWikiTestCase {
                $this->lock = "$IP/tests/phpunit/data/composer/composer.lock";
        }
 
-       /**
-        * @covers ComposerLock::getHash
-        */
-       public function testGetHash() {
-               $lock = new ComposerLock( $this->lock );
-               $this->assertEquals( 'a3bb80b0ac4c4a31e52574d48c032923', $lock->getHash() );
-       }
-
        /**
         * @covers ComposerLock::__construct
         * @covers ComposerLock::getInstalledDependencies