1
0
Fork 0
composer/tests/Composer/Test/Installer/MetapackageInstallerTest.php

120 lines
3.3 KiB
PHP
Raw Normal View History

2022-02-23 15:58:18 +00:00
<?php declare(strict_types=1);
2012-01-25 12:40:16 +00:00
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\Installer;
use Composer\Installer\MetapackageInstaller;
2020-02-07 03:18:45 +00:00
use Composer\Test\TestCase;
2012-01-25 12:40:16 +00:00
class MetapackageInstallerTest extends TestCase
2012-01-25 12:40:16 +00:00
{
2021-10-16 08:16:06 +00:00
/**
* @var \Composer\Repository\InstalledRepositoryInterface&\PHPUnit\Framework\MockObject\MockObject
*/
2012-01-25 12:40:16 +00:00
private $repository;
2021-10-16 08:16:06 +00:00
/**
* @var MetapackageInstaller
*/
2012-01-25 12:40:16 +00:00
private $installer;
2021-10-16 08:16:06 +00:00
/**
* @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject
*/
2012-01-25 12:40:16 +00:00
private $io;
2021-12-08 16:03:05 +00:00
protected function setUp(): void
2012-01-25 12:40:16 +00:00
{
$this->repository = $this->getMockBuilder('Composer\Repository\InstalledRepositoryInterface')->getMock();
2012-01-25 12:40:16 +00:00
$this->io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
2012-01-25 12:40:16 +00:00
$this->installer = new MetapackageInstaller($this->io);
2012-01-25 12:40:16 +00:00
}
public function testInstall(): void
2012-01-25 12:40:16 +00:00
{
$package = $this->createPackageMock();
$this->repository
->expects($this->once())
->method('addPackage')
->with($package);
2012-04-14 13:45:25 +00:00
$this->installer->install($this->repository, $package);
2012-01-25 12:40:16 +00:00
}
public function testUpdate(): void
2012-01-25 12:40:16 +00:00
{
$initial = $this->createPackageMock();
$initial->expects($this->once())
->method('getVersion')
->will($this->returnValue('1.0.0'));
2017-03-08 14:07:29 +00:00
$target = $this->createPackageMock();
$target->expects($this->once())
->method('getVersion')
->will($this->returnValue('1.0.1'));
2012-01-25 12:40:16 +00:00
$this->repository
->expects($this->exactly(2))
->method('hasPackage')
->with($initial)
->will($this->onConsecutiveCalls(true, false));
$this->repository
->expects($this->once())
->method('removePackage')
->with($initial);
$this->repository
->expects($this->once())
->method('addPackage')
->with($target);
2012-04-14 13:45:25 +00:00
$this->installer->update($this->repository, $initial, $target);
2012-01-25 12:40:16 +00:00
2021-12-09 19:55:26 +00:00
self::expectException('InvalidArgumentException');
2012-01-25 12:40:16 +00:00
2012-04-14 13:45:25 +00:00
$this->installer->update($this->repository, $initial, $target);
2012-01-25 12:40:16 +00:00
}
public function testUninstall(): void
2012-01-25 12:40:16 +00:00
{
$package = $this->createPackageMock();
$this->repository
->expects($this->exactly(2))
->method('hasPackage')
->with($package)
->will($this->onConsecutiveCalls(true, false));
$this->repository
->expects($this->once())
->method('removePackage')
->with($package);
2012-04-14 13:45:25 +00:00
$this->installer->uninstall($this->repository, $package);
2012-01-25 12:40:16 +00:00
2021-12-09 19:55:26 +00:00
self::expectException('InvalidArgumentException');
2012-01-25 12:40:16 +00:00
2012-04-14 13:45:25 +00:00
$this->installer->uninstall($this->repository, $package);
2012-01-25 12:40:16 +00:00
}
/**
* @return \Composer\Package\PackageInterface&\PHPUnit\Framework\MockObject\MockObject
*/
2012-01-25 12:40:16 +00:00
private function createPackageMock()
{
return $this->getMockBuilder('Composer\Package\Package')
->setConstructorArgs([bin2hex(random_bytes(5)), '1.0.0.0', '1.0.0'])
2012-01-25 12:40:16 +00:00
->getMock();
}
}