2011-10-01 12:32:56 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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\Package;
|
|
|
|
|
|
|
|
use Composer\Package\Locker;
|
2013-08-10 00:43:40 +00:00
|
|
|
use Composer\IO\NullIO;
|
2011-10-01 12:32:56 +00:00
|
|
|
|
|
|
|
class LockerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testIsLocked()
|
|
|
|
{
|
|
|
|
$json = $this->createJsonFileMock();
|
2013-08-10 00:43:40 +00:00
|
|
|
$locker = new Locker(new NullIO, $json, $this->createRepositoryManagerMock(), $this->createInstallationManagerMock(), 'md5');
|
2011-10-01 12:32:56 +00:00
|
|
|
|
|
|
|
$json
|
2012-04-15 17:05:50 +00:00
|
|
|
->expects($this->any())
|
2011-10-01 12:32:56 +00:00
|
|
|
->method('exists')
|
|
|
|
->will($this->returnValue(true));
|
2012-04-15 17:05:50 +00:00
|
|
|
$json
|
|
|
|
->expects($this->any())
|
|
|
|
->method('read')
|
|
|
|
->will($this->returnValue(array('packages' => array())));
|
2011-10-01 12:32:56 +00:00
|
|
|
|
|
|
|
$this->assertTrue($locker->isLocked());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetNotLockedPackages()
|
|
|
|
{
|
|
|
|
$json = $this->createJsonFileMock();
|
|
|
|
$repo = $this->createRepositoryManagerMock();
|
2012-06-20 10:05:18 +00:00
|
|
|
$inst = $this->createInstallationManagerMock();
|
2011-10-01 12:32:56 +00:00
|
|
|
|
2013-08-10 00:43:40 +00:00
|
|
|
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5');
|
2011-10-01 12:32:56 +00:00
|
|
|
|
|
|
|
$json
|
|
|
|
->expects($this->once())
|
|
|
|
->method('exists')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
$this->setExpectedException('LogicException');
|
|
|
|
|
2012-09-14 14:43:56 +00:00
|
|
|
$locker->getLockedRepository();
|
2011-10-01 12:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetLockedPackages()
|
|
|
|
{
|
|
|
|
$json = $this->createJsonFileMock();
|
|
|
|
$repo = $this->createRepositoryManagerMock();
|
2012-06-20 10:05:18 +00:00
|
|
|
$inst = $this->createInstallationManagerMock();
|
2011-10-01 12:32:56 +00:00
|
|
|
|
2013-08-10 00:43:40 +00:00
|
|
|
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5');
|
2011-10-01 12:32:56 +00:00
|
|
|
|
|
|
|
$json
|
|
|
|
->expects($this->once())
|
|
|
|
->method('exists')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
$json
|
|
|
|
->expects($this->once())
|
|
|
|
->method('read')
|
|
|
|
->will($this->returnValue(array(
|
2011-12-24 14:28:12 +00:00
|
|
|
'packages' => array(
|
2013-03-28 19:42:25 +00:00
|
|
|
array('name' => 'pkg1', 'version' => '1.0.0-beta'),
|
|
|
|
array('name' => 'pkg2', 'version' => '0.1.10')
|
2011-12-24 14:28:12 +00:00
|
|
|
)
|
2011-10-01 12:32:56 +00:00
|
|
|
)));
|
|
|
|
|
2013-03-28 19:42:25 +00:00
|
|
|
$repo = $locker->getLockedRepository();
|
|
|
|
$this->assertNotNull($repo->findPackage('pkg1', '1.0.0-beta'));
|
|
|
|
$this->assertNotNull($repo->findPackage('pkg2', '0.1.10'));
|
2011-10-01 12:32:56 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 15:44:49 +00:00
|
|
|
public function testSetLockData()
|
2011-10-01 12:32:56 +00:00
|
|
|
{
|
|
|
|
$json = $this->createJsonFileMock();
|
|
|
|
$repo = $this->createRepositoryManagerMock();
|
2012-06-20 10:05:18 +00:00
|
|
|
$inst = $this->createInstallationManagerMock();
|
2011-10-01 12:32:56 +00:00
|
|
|
|
2013-08-10 00:43:40 +00:00
|
|
|
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5');
|
2011-10-01 12:32:56 +00:00
|
|
|
|
|
|
|
$package1 = $this->createPackageMock();
|
|
|
|
$package2 = $this->createPackageMock();
|
|
|
|
|
|
|
|
$package1
|
2012-09-14 14:43:56 +00:00
|
|
|
->expects($this->atLeastOnce())
|
2011-11-20 14:46:15 +00:00
|
|
|
->method('getPrettyName')
|
2011-10-01 12:32:56 +00:00
|
|
|
->will($this->returnValue('pkg1'));
|
|
|
|
$package1
|
2012-09-14 14:43:56 +00:00
|
|
|
->expects($this->atLeastOnce())
|
2011-11-20 14:46:15 +00:00
|
|
|
->method('getPrettyVersion')
|
2011-10-01 12:32:56 +00:00
|
|
|
->will($this->returnValue('1.0.0-beta'));
|
2012-09-14 14:43:56 +00:00
|
|
|
$package1
|
|
|
|
->expects($this->atLeastOnce())
|
|
|
|
->method('getVersion')
|
|
|
|
->will($this->returnValue('1.0.0.0-beta'));
|
2011-10-01 12:32:56 +00:00
|
|
|
|
|
|
|
$package2
|
2012-09-14 14:43:56 +00:00
|
|
|
->expects($this->atLeastOnce())
|
2011-11-20 14:46:15 +00:00
|
|
|
->method('getPrettyName')
|
2011-10-01 12:32:56 +00:00
|
|
|
->will($this->returnValue('pkg2'));
|
|
|
|
$package2
|
2012-09-14 14:43:56 +00:00
|
|
|
->expects($this->atLeastOnce())
|
2011-11-20 14:46:15 +00:00
|
|
|
->method('getPrettyVersion')
|
2011-10-01 12:32:56 +00:00
|
|
|
->will($this->returnValue('0.1.10'));
|
2012-09-14 14:43:56 +00:00
|
|
|
$package2
|
|
|
|
->expects($this->atLeastOnce())
|
|
|
|
->method('getVersion')
|
|
|
|
->will($this->returnValue('0.1.10.0'));
|
2011-10-01 12:32:56 +00:00
|
|
|
|
|
|
|
$json
|
|
|
|
->expects($this->once())
|
|
|
|
->method('write')
|
|
|
|
->with(array(
|
2014-03-06 18:15:59 +00:00
|
|
|
'_readme' => array('This file locks the dependencies of your project to a known state',
|
|
|
|
'Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file',
|
|
|
|
'This file is @gener'.'ated automatically'),
|
2011-12-24 14:28:12 +00:00
|
|
|
'hash' => 'md5',
|
|
|
|
'packages' => array(
|
2012-09-14 14:43:56 +00:00
|
|
|
array('name' => 'pkg1', 'version' => '1.0.0-beta'),
|
|
|
|
array('name' => 'pkg2', 'version' => '0.1.10')
|
2011-12-24 14:28:12 +00:00
|
|
|
),
|
2012-04-14 13:45:25 +00:00
|
|
|
'packages-dev' => array(),
|
2012-02-21 15:44:49 +00:00
|
|
|
'aliases' => array(),
|
2012-05-11 15:20:10 +00:00
|
|
|
'minimum-stability' => 'dev',
|
|
|
|
'stability-flags' => array(),
|
2013-03-03 19:05:46 +00:00
|
|
|
'platform' => array(),
|
|
|
|
'platform-dev' => array(),
|
2011-10-01 12:32:56 +00:00
|
|
|
));
|
|
|
|
|
2013-03-03 19:05:46 +00:00
|
|
|
$locker->setLockData(array($package1, $package2), array(), array(), array(), array(), 'dev', array());
|
2011-10-01 12:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLockBadPackages()
|
|
|
|
{
|
|
|
|
$json = $this->createJsonFileMock();
|
|
|
|
$repo = $this->createRepositoryManagerMock();
|
2012-06-20 10:05:18 +00:00
|
|
|
$inst = $this->createInstallationManagerMock();
|
2011-10-01 12:32:56 +00:00
|
|
|
|
2013-08-10 00:43:40 +00:00
|
|
|
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5');
|
2011-10-01 12:32:56 +00:00
|
|
|
|
|
|
|
$package1 = $this->createPackageMock();
|
|
|
|
$package1
|
|
|
|
->expects($this->once())
|
2011-11-20 14:46:15 +00:00
|
|
|
->method('getPrettyName')
|
2011-10-01 12:32:56 +00:00
|
|
|
->will($this->returnValue('pkg1'));
|
|
|
|
|
|
|
|
$this->setExpectedException('LogicException');
|
|
|
|
|
2013-03-03 19:05:46 +00:00
|
|
|
$locker->setLockData(array($package1), array(), array(), array(), array(), 'dev', array());
|
2011-10-01 12:32:56 +00:00
|
|
|
}
|
|
|
|
|
2012-01-06 12:26:25 +00:00
|
|
|
public function testIsFresh()
|
|
|
|
{
|
|
|
|
$json = $this->createJsonFileMock();
|
|
|
|
$repo = $this->createRepositoryManagerMock();
|
2012-06-20 10:05:18 +00:00
|
|
|
$inst = $this->createInstallationManagerMock();
|
2012-01-06 12:26:25 +00:00
|
|
|
|
2013-08-10 00:43:40 +00:00
|
|
|
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5');
|
2012-01-06 12:26:25 +00:00
|
|
|
|
|
|
|
$json
|
|
|
|
->expects($this->once())
|
|
|
|
->method('read')
|
|
|
|
->will($this->returnValue(array('hash' => 'md5')));
|
|
|
|
|
|
|
|
$this->assertTrue($locker->isFresh());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsFreshFalse()
|
|
|
|
{
|
|
|
|
$json = $this->createJsonFileMock();
|
|
|
|
$repo = $this->createRepositoryManagerMock();
|
2012-06-20 10:05:18 +00:00
|
|
|
$inst = $this->createInstallationManagerMock();
|
2012-01-06 12:26:25 +00:00
|
|
|
|
2013-08-10 00:43:40 +00:00
|
|
|
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5');
|
2012-01-06 12:26:25 +00:00
|
|
|
|
|
|
|
$json
|
|
|
|
->expects($this->once())
|
|
|
|
->method('read')
|
|
|
|
->will($this->returnValue(array('hash' => 'oldmd5')));
|
|
|
|
|
|
|
|
$this->assertFalse($locker->isFresh());
|
|
|
|
}
|
|
|
|
|
2011-10-01 12:32:56 +00:00
|
|
|
private function createJsonFileMock()
|
|
|
|
{
|
|
|
|
return $this->getMockBuilder('Composer\Json\JsonFile')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createRepositoryManagerMock()
|
|
|
|
{
|
2011-10-30 19:29:52 +00:00
|
|
|
$mock = $this->getMockBuilder('Composer\Repository\RepositoryManager')
|
2011-10-01 12:32:56 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2011-10-30 19:29:52 +00:00
|
|
|
|
|
|
|
$mock->expects($this->any())
|
|
|
|
->method('getLocalRepository')
|
|
|
|
->will($this->returnValue($this->getMockBuilder('Composer\Repository\ArrayRepository')->getMock()));
|
|
|
|
|
|
|
|
return $mock;
|
2011-10-01 12:32:56 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 10:05:18 +00:00
|
|
|
private function createInstallationManagerMock()
|
|
|
|
{
|
|
|
|
$mock = $this->getMockBuilder('Composer\Installer\InstallationManager')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
return $mock;
|
|
|
|
}
|
|
|
|
|
2011-10-01 12:32:56 +00:00
|
|
|
private function createPackageMock()
|
|
|
|
{
|
|
|
|
return $this->getMockBuilder('Composer\Package\PackageInterface')
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
}
|