Quellcode durchsuchen

allow injecting a mock filesystem into LibraryInstaller and fix LibraryInstallerTest

Karoly Negyesi vor 11 Jahren
Ursprung
Commit
c6ec739766

+ 3 - 2
src/Composer/Installer/LibraryInstaller.php

@@ -41,15 +41,16 @@ class LibraryInstaller implements InstallerInterface
      * @param IOInterface $io
      * @param Composer    $composer
      * @param string      $type
+     * @param Filesystem  $filesystem
      */
-    public function __construct(IOInterface $io, Composer $composer, $type = 'library')
+    public function __construct(IOInterface $io, Composer $composer, $type = 'library', $filesystem = NULL)
     {
         $this->composer = $composer;
         $this->downloadManager = $composer->getDownloadManager();
         $this->io = $io;
         $this->type = $type;
 
-        $this->filesystem = new Filesystem();
+        $this->filesystem = $filesystem ?: new Filesystem();
         $this->vendorDir = rtrim($composer->getConfig()->get('vendor-dir'), '/');
         $this->binDir = rtrim($composer->getConfig()->get('bin-dir'), '/');
     }

+ 7 - 1
tests/Composer/Test/Installer/LibraryInstallerTest.php

@@ -131,7 +131,8 @@ class LibraryInstallerTest extends TestCase
      */
     public function testUpdate()
     {
-        $library = new LibraryInstaller($this->io, $this->composer);
+        $filesystem = $this->getMockBuilder('Composer\Util\Filesystem')->getMock();
+        $library = new LibraryInstaller($this->io, $this->composer, 'library', $filesystem);
         $initial = $this->createPackageMock();
         $target  = $this->createPackageMock();
 
@@ -140,6 +141,11 @@ class LibraryInstallerTest extends TestCase
             ->method('getPrettyName')
             ->will($this->returnValue('package1'));
 
+        $target
+            ->expects($this->once())
+            ->method('getPrettyName')
+            ->will($this->returnValue('package1'));
+
         $this->repository
             ->expects($this->exactly(3))
             ->method('hasPackage')