Browse Source

Add tests for installer with lock: false

https://github.com/composer/composer/issues/8354
Arnout Boks 5 years ago
parent
commit
22caa0f097

+ 25 - 0
tests/Composer/Test/Fixtures/installer/install-without-lock.test

@@ -0,0 +1,25 @@
+--TEST--
+Installs from composer.json without writing a lock file
+--COMPOSER--
+{
+    "repositories": [
+        {
+            "type": "package",
+            "package": [
+                { "name": "a/a", "version": "1.0.0" }
+            ]
+        }
+    ],
+    "require": {
+        "a/a": "1.0.0"
+    },
+    "config": {
+        "lock": "false"
+    }
+}
+--RUN--
+install
+--EXPECT--
+Installing a/a (1.0.0)
+--EXPECT-LOCK--
+false

+ 25 - 0
tests/Composer/Test/Fixtures/installer/update-without-lock.test

@@ -0,0 +1,25 @@
+--TEST--
+Updates when no lock file is present without writing a lock file
+--COMPOSER--
+{
+    "repositories": [
+        {
+            "type": "package",
+            "package": [
+                { "name": "a/a", "version": "1.0.0" }
+            ]
+        }
+    ],
+    "require": {
+        "a/a": "1.0.0"
+    },
+    "config": {
+        "lock": false
+    }
+}
+--RUN--
+update
+--EXPECT--
+Installing a/a (1.0.0)
+--EXPECT-LOCK--
+false

+ 8 - 1
tests/Composer/Test/InstallerTest.php

@@ -197,6 +197,9 @@ class InstallerTest extends TestCase
                     // so store value temporarily in reference for later assetion
                     $actualLock = $hash;
                 }));
+        } elseif ($expectLock === false) {
+            $lockJsonMock->expects($this->never())
+                ->method('write');
         }
 
         $contents = json_encode($composerConfig);
@@ -319,7 +322,11 @@ class InstallerTest extends TestCase
                 }
                 $run = $testData['RUN'];
                 if (!empty($testData['EXPECT-LOCK'])) {
-                    $expectLock = JsonFile::parseJson($testData['EXPECT-LOCK']);
+                    if ($testData['EXPECT-LOCK'] === 'false') {
+                        $expectLock = false;
+                    } else {
+                        $expectLock = JsonFile::parseJson($testData['EXPECT-LOCK']);
+                    }
                 }
                 $expectOutput = isset($testData['EXPECT-OUTPUT']) ? $testData['EXPECT-OUTPUT'] : null;
                 $expect = $testData['EXPECT'];