Clean up useless mocks

main
Jordi Boggiano 2 years ago
parent a16ed3d0ed
commit 137ebddc25
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -13,6 +13,7 @@
namespace Composer\Test\Installer;
use Composer\Installer\LibraryInstaller;
use Composer\Repository\InstalledArrayRepository;
use Composer\Util\Filesystem;
use Composer\Test\TestCase;
use Composer\Composer;
@ -121,16 +122,21 @@ class LibraryInstallerTest extends TestCase
public function testIsInstalled(): void
{
$library = new LibraryInstaller($this->io, $this->composer);
$package = $this->createPackageMock();
$package = $this->getPackage('test/pkg', '1.0.0');
$this->repository
->expects($this->exactly(2))
->method('hasPackage')
->with($package)
->will($this->onConsecutiveCalls(true, false));
$repository = new InstalledArrayRepository();
$this->assertFalse($library->isInstalled($repository, $package));
// package being in repo is not enough to be installed
$repository->addPackage($package);
$this->assertFalse($library->isInstalled($repository, $package));
$this->assertTrue($library->isInstalled($this->repository, $package));
$this->assertFalse($library->isInstalled($this->repository, $package));
// package being in repo and vendor/pkg/foo dir present means it is seen as installed
$this->ensureDirectoryExistsAndClear($this->vendorDir.'/'.$package->getPrettyName());
$this->assertTrue($library->isInstalled($repository, $package));
$repository->removePackage($package);
$this->assertFalse($library->isInstalled($repository, $package));
}
/**
@ -140,12 +146,7 @@ class LibraryInstallerTest extends TestCase
public function testInstall(): void
{
$library = new LibraryInstaller($this->io, $this->composer);
$package = $this->createPackageMock();
$package
->expects($this->any())
->method('getPrettyName')
->will($this->returnValue('some/package'));
$package = $this->getPackage('some/package', '1.0.0');
$this->dm
->expects($this->once())
@ -173,30 +174,13 @@ class LibraryInstallerTest extends TestCase
$filesystem
->expects($this->once())
->method('rename')
->with($this->vendorDir.'/package1/oldtarget', $this->vendorDir.'/package1/newtarget');
$initial = $this->createPackageMock();
$target = $this->createPackageMock();
$initial
->expects($this->any())
->method('getPrettyName')
->will($this->returnValue('package1'));
$initial
->expects($this->any())
->method('getTargetDir')
->will($this->returnValue('oldtarget'));
->with($this->vendorDir.'/vendor/package1/oldtarget', $this->vendorDir.'/vendor/package1/newtarget');
$target
->expects($this->any())
->method('getPrettyName')
->will($this->returnValue('package1'));
$initial = $this->getPackage('vendor/package1', '1.0.0');
$target = $this->getPackage('vendor/package1', '2.0.0');
$target
->expects($this->any())
->method('getTargetDir')
->will($this->returnValue('newtarget'));
$initial->setTargetDir('oldtarget');
$target->setTargetDir('newtarget');
$this->repository
->expects($this->exactly(3))
@ -206,7 +190,7 @@ class LibraryInstallerTest extends TestCase
$this->dm
->expects($this->once())
->method('update')
->with($initial, $target, $this->vendorDir.'/package1/newtarget');
->with($initial, $target, $this->vendorDir.'/vendor/package1/newtarget');
$this->repository
->expects($this->once())
@ -231,16 +215,7 @@ class LibraryInstallerTest extends TestCase
public function testUninstall(): void
{
$library = new LibraryInstaller($this->io, $this->composer);
$package = $this->createPackageMock();
$package
->expects($this->any())
->method('getPrettyName')
->will($this->returnValue('pkg'));
$package
->expects($this->any())
->method('getName')
->will($this->returnValue('pkg'));
$package = $this->getPackage('vendor/pkg', '1.0.0');
$this->repository
->expects($this->exactly(2))
@ -251,7 +226,7 @@ class LibraryInstallerTest extends TestCase
$this->dm
->expects($this->once())
->method('remove')
->with($package, $this->vendorDir.'/pkg');
->with($package, $this->vendorDir.'/vendor/pkg');
$this->repository
->expects($this->once())
@ -265,32 +240,19 @@ class LibraryInstallerTest extends TestCase
$library->uninstall($this->repository, $package);
}
public function testGetInstallPath(): void
public function testGetInstallPathWithoutTargetDir(): void
{
$library = new LibraryInstaller($this->io, $this->composer);
$package = $this->createPackageMock();
$package
->expects($this->once())
->method('getTargetDir')
->will($this->returnValue(null));
$package = $this->getPackage('Vendor/Pkg', '1.0.0');
$this->assertEquals($this->vendorDir.'/'.$package->getName(), $library->getInstallPath($package));
$this->assertEquals($this->vendorDir.'/'.$package->getPrettyName(), $library->getInstallPath($package));
}
public function testGetInstallPathWithTargetDir(): void
{
$library = new LibraryInstaller($this->io, $this->composer);
$package = $this->createPackageMock();
$package
->expects($this->once())
->method('getTargetDir')
->will($this->returnValue('Some/Namespace'));
$package
->expects($this->any())
->method('getPrettyName')
->will($this->returnValue('foo/bar'));
$package = $this->getPackage('Foo/Bar', '1.0.0');
$package->setTargetDir('Some/Namespace');
$this->assertEquals($this->vendorDir.'/'.$package->getPrettyName().'/Some/Namespace', $library->getInstallPath($package));
}
@ -306,7 +268,7 @@ class LibraryInstallerTest extends TestCase
->getMock();
$library = new LibraryInstaller($this->io, $this->composer, 'library', null, $binaryInstallerMock);
$package = $this->createPackageMock();
$package = $this->getPackage('foo/bar', '1.0.0');
$binaryInstallerMock
->expects($this->never())
@ -320,14 +282,4 @@ class LibraryInstallerTest extends TestCase
$library->ensureBinariesPresence($package);
}
/**
* @return \Composer\Package\PackageInterface&\PHPUnit\Framework\MockObject\MockObject
*/
protected function createPackageMock()
{
return $this->getMockBuilder('Composer\Package\Package')
->setConstructorArgs(array(md5((string) mt_rand()), '1.0.0.0', '1.0.0'))
->getMock();
}
}

Loading…
Cancel
Save