/** * @test * * @depends testInstallerCreationShouldNotCreateVendorDirectory * @depends testInstallerCreationShouldNotCreateBinDirectory */ public function updateStableToDevelopment() { $installer = new SharedPackageInstaller($this->io, $this->composer, $this->fs, $this->dataManager); $defaultInstaller = $this->getMockBuilder('Composer\\Installer\\LibraryInstaller')->disableOriginalConstructor()->getMock(); $im = new InstallationManager(); $im->addInstaller(new SharedPackageInstallerSolver($installer, $defaultInstaller)); $this->composer->setInstallationManager($im); $initial = $this->createStablePackageMock(); $target = $this->createDevelopmentPackageMock(); $this->fs->ensureDirectoryExists($installer->getInstallPath($initial)); $initial->expects($this->any())->method('getPrettyName')->will($this->returnValue('initial-package')); $initial->expects($this->any())->method('getTargetDir')->will($this->returnValue('oldtarget')); $initial->expects($this->once())->method('getType')->willReturn('shared-package'); $target->expects($this->once())->method('getType')->willReturn('shared-package'); $target->expects($this->any())->method('getTargetDir')->will($this->returnValue('newtarget')); $this->dm->expects($this->once())->method('download')->with($target, $this->dependenciesDir . '/letudiant/foo-bar/dev-develop/newtarget'); $this->repository->expects($this->exactly(2))->method('hasPackage')->will($this->onConsecutiveCalls(true, true, false, false)); $this->dataManager->expects($this->once())->method('addPackageUsage')->willReturn($target); $installer->update($this->repository, $initial, $target); $this->assertFileExists($this->vendorDir, 'Vendor dir should be created'); $this->assertFileExists($this->binDir, 'Bin dir should be created'); $this->assertFileExists($this->dependenciesDir, 'Dependencies dir should be created'); $this->assertFileExists($this->symlinkDir, 'Symlink dir should be created'); $this->assertFileNotExists($installer->getInstallPath($initial)); $this->assertTrue(is_link($this->symlinkDir . '/letudiant/foo-bar')); }
/** * @param PackageInterface $package * * @throws FilesystemException */ protected function removePackageVendorSymlink(PackageInterface $package) { if ($this->config->isSymlinkEnabled() && $this->filesystem->removeSymlink($this->getPackageVendorSymlink($package))) { $this->io->write(array(' - Deleting symlink for <info>' . $package->getPrettyName() . '</info> ' . '(<fg=yellow>' . $package->getPrettyVersion() . '</fg=yellow>)', '')); $symlinkParentDirectory = dirname($this->getPackageVendorSymlink($package)); $this->filesystem->removeEmptyDirectory($symlinkParentDirectory); } }
/** * @test */ public function install() { $installer = $this->createInstaller(); $package = $this->createPackageMock(); $this->dm->expects($this->exactly(1))->method('download')->with($package, $this->dependenciesDir . '/letudiant/foo-bar/dev-develop'); $this->repository->expects($this->exactly(2))->method('addPackage')->with($package); $this->dataManager->expects($this->exactly(2))->method('addPackageUsage')->willReturn($package); $installer->install($this->repository, $package); $this->assertFileExists($this->vendorDir, 'Vendor dir should be created'); $this->assertFileExists($this->binDir, 'Bin dir should be created'); $this->assertFileExists($this->symlinkDir, 'Symlink dir should be created'); $this->assertFileExists($this->symlinkDir . '/letudiant', 'Symlink package prefix dir should be created'); $this->assertTrue(is_link($this->symlinkDir . '/letudiant/foo-bar'), 'Symlink should be created'); $this->assertFileExists($this->dependenciesDir, 'Dependencies dir should be created'); // Install another time with already created directory $this->fs->ensureDirectoryExists($installer->getInstallPath($package)); $this->repository->expects($this->once())->method('hasPackage')->with($package)->willReturn(false); $installer->install($this->repository, $package); }
/** * @test */ public function removeEmptyDirectoryWhenNotExists() { $filesystem = new SymlinkFilesystem(); $this->assertFalse($filesystem->removeEmptyDirectory($this->testDir . '/bar')); }