@ -20,7 +20,8 @@ class LockerTest extends \PHPUnit_Framework_TestCase
public function testIsLocked()
{
$json = $this->createJsonFileMock();
$locker = new Locker(new NullIO, $json, $this->createRepositoryManagerMock(), $this->createInstallationManagerMock(), 'md5', 'contentMd5');
$locker = new Locker(new NullIO, $json, $this->createRepositoryManagerMock(), $this->createInstallationManagerMock(),
$this->getJsonContent());
$json
->expects($this->any())
@ -40,7 +41,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase
$repo = $this->createRepositoryManagerMock();
$inst = $this->createInstallationManagerMock();
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5', 'contentMd5' );
$locker = new Locker(new NullIO, $json, $repo, $inst, $this->getJsonContent() );
$json
->expects($this->once())
@ -58,7 +59,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase
$repo = $this->createRepositoryManagerMock();
$inst = $this->createInstallationManagerMock();
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5', 'contentMd5' );
$locker = new Locker(new NullIO, $json, $repo, $inst, $this->getJsonContent() );
$json
->expects($this->once())
@ -85,7 +86,8 @@ class LockerTest extends \PHPUnit_Framework_TestCase
$repo = $this->createRepositoryManagerMock();
$inst = $this->createInstallationManagerMock();
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5', 'contentMd5');
$jsonContent = $this->getJsonContent() . ' ';
$locker = new Locker(new NullIO, $json, $repo, $inst, $jsonContent);
$package1 = $this->createPackageMock();
$package2 = $this->createPackageMock();
@ -116,6 +118,9 @@ class LockerTest extends \PHPUnit_Framework_TestCase
->method('getVersion')
->will($this->returnValue('0.1.10.0'));
$hash = md5($jsonContent);
$contentHash = md5(trim($jsonContent));
$json
->expects($this->once())
->method('write')
@ -123,8 +128,8 @@ class LockerTest extends \PHPUnit_Framework_TestCase
'_readme' => array('This file locks the dependencies of your project to a known state',
'Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file',
'This file is @gener'.'ated automatically'),
'hash' => 'md5' ,
'content-hash' => 'contentMd5' ,
'hash' => $hash ,
'content-hash' => $contentHash ,
'packages' => array(
array('name' => 'pkg1', 'version' => '1.0.0-beta'),
array('name' => 'pkg2', 'version' => '0.1.10')
@ -149,7 +154,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase
$repo = $this->createRepositoryManagerMock();
$inst = $this->createInstallationManagerMock();
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5', 'md5' );
$locker = new Locker(new NullIO, $json, $repo, $inst, $this->getJsonContent() );
$package1 = $this->createPackageMock();
$package1
@ -168,12 +173,13 @@ class LockerTest extends \PHPUnit_Framework_TestCase
$repo = $this->createRepositoryManagerMock();
$inst = $this->createInstallationManagerMock();
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5', 'contentMd5');
$jsonContent = $this->getJsonContent();
$locker = new Locker(new NullIO, $json, $repo, $inst, $jsonContent);
$json
->expects($this->once())
->method('read')
->will($this->returnValue(array('hash' => 'md5' )));
->will($this->returnValue(array('hash' => md5($jsonContent) )));
$this->assertTrue($locker->isFresh());
}
@ -184,12 +190,12 @@ class LockerTest extends \PHPUnit_Framework_TestCase
$repo = $this->createRepositoryManagerMock();
$inst = $this->createInstallationManagerMock();
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5', 'contentMd5' );
$locker = new Locker(new NullIO, $json, $repo, $inst, $this->getJsonContent() );
$json
->expects($this->once())
->method('read')
->will($this->returnValue(array('hash' => 'oldmd5' )));
->will($this->returnValue(array('hash' => $this->getJsonContent(array('name' => 'test2')) )));
$this->assertFalse($locker->isFresh());
}
@ -200,12 +206,13 @@ class LockerTest extends \PHPUnit_Framework_TestCase
$repo = $this->createRepositoryManagerMock();
$inst = $this->createInstallationManagerMock();
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5', 'contentMd5');
$jsonContent = $this->getJsonContent();
$locker = new Locker(new NullIO, $json, $repo, $inst, $jsonContent);
$json
->expects($this->once())
->method('read')
->will($this->returnValue(array('hash' => 'oldMd5', 'content-hash' => 'contentMd5' )));
->will($this->returnValue(array('hash' => md5($jsonContent . ' '), 'content-hash' => md5($jsonContent) )));
$this->assertTrue($locker->isFresh());
}
@ -216,12 +223,14 @@ class LockerTest extends \PHPUnit_Framework_TestCase
$repo = $this->createRepositoryManagerMock();
$inst = $this->createInstallationManagerMock();
$locker = new Locker(new NullIO, $json, $repo, $inst, 'md5', 'contentMd5');
$locker = new Locker(new NullIO, $json, $repo, $inst, $this->getJsonContent());
$differentHash = md5($this->getJsonContent(['name' => 'test2']));
$json
->expects($this->once())
->method('read')
->will($this->returnValue(array('hash' => 'md5', 'content-hash' => 'oldMd5' )));
->will($this->returnValue(array('hash' => $differentHash, 'content-hash' => $differentHash )));
$this->assertFalse($locker->isFresh());
}
@ -260,4 +269,16 @@ class LockerTest extends \PHPUnit_Framework_TestCase
return $this->getMockBuilder('Composer\Package\PackageInterface')
->getMock();
}
private function getJsonContent(array $customData = array())
{
$data = array_merge(array(
'minimum-stability' => 'beta',
'name' => 'test',
), $customData);
ksort($data);
return json_encode($data);
}
}