Pārlūkot izejas kodu

Merge pull request #3685 from xfornesa/issue3647

fix for issue #3647
Nils Adermann 10 gadi atpakaļ
vecāks
revīzija
2697673666

+ 5 - 7
src/Composer/IO/ConsoleIO.php

@@ -96,13 +96,11 @@ class ConsoleIO extends BaseIO
     public function write($messages, $newline = true)
     {
         if (null !== $this->startTime) {
-            $messages = (array) $messages;
-            $messages[0] = sprintf(
-                '[%.1fMB/%.2fs] %s',
-                memory_get_usage() / 1024 / 1024,
-                microtime(true) - $this->startTime,
-                $messages[0]
-            );
+            $memoryUsage = memory_get_usage() / 1024 / 1024;
+            $timeSpent = microtime(true) - $this->startTime;
+            $messages = array_map(function ($message) use ($memoryUsage, $timeSpent) {
+                return sprintf('[%.1fMB/%.2fs] %s', $memoryUsage, $timeSpent, $message);
+            }, (array) $messages);
         }
         $this->output->write($messages, $newline);
         $this->lastMessage = join($newline ? "\n" : '', (array) $messages);

+ 24 - 0
tests/Composer/Test/IO/ConsoleIOTest.php

@@ -49,6 +49,30 @@ class ConsoleIOTest extends TestCase
         $consoleIO->write('some information about something', false);
     }
 
+    public function testWriteWithMultipleLineStringWhenDebugging()
+    {
+        $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface');
+        $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
+        $outputMock->expects($this->once())
+            ->method('write')
+            ->with(
+                $this->callback(function($messages){
+                    $result = preg_match("[(.*)/(.*) First line]", $messages[0]) > 0;
+                    $result &= preg_match("[(.*)/(.*) Second line]", $messages[1]) > 0;
+                    return $result;
+                }),
+                $this->equalTo(false)
+            );
+        $helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet');
+
+        $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock);
+        $startTime = microtime(true);
+        $consoleIO->enableDebugging($startTime);
+
+        $example = explode('\n', 'First line\nSecond lines');
+        $consoleIO->write($example, false);
+    }
+
     public function testOverwrite()
     {
         $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface');