From c6ec739766c53245edd9f18b8d31f91abd04d8d3 Mon Sep 17 00:00:00 2001 From: Karoly Negyesi Date: Fri, 20 Sep 2013 06:02:36 +0200 Subject: [PATCH] allow injecting a mock filesystem into LibraryInstaller and fix LibraryInstallerTest --- src/Composer/Installer/LibraryInstaller.php | 5 +++-- tests/Composer/Test/Installer/LibraryInstallerTest.php | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index a754eb590..cd3a6d947 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/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'), '/'); } diff --git a/tests/Composer/Test/Installer/LibraryInstallerTest.php b/tests/Composer/Test/Installer/LibraryInstallerTest.php index dd36e6184..92e0437d6 100644 --- a/tests/Composer/Test/Installer/LibraryInstallerTest.php +++ b/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')