From 56e43e439717144102233158e1049307786e4054 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 6 Jan 2012 13:26:25 +0100 Subject: [PATCH] Add tests --- src/Composer/Package/Locker.php | 17 +++++++----- tests/Composer/Test/Package/LockerTest.php | 30 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index 0c375b8b5..f25bf0595 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -29,9 +29,9 @@ class Locker /** * Initializes packages locker. * - * @param JsonFile $lockFile lockfile loader - * @param RepositoryManager $repositoryManager repository manager instance - * @param string $hash unique hash of the current composer configuration + * @param JsonFile $lockFile lockfile loader + * @param RepositoryManager $repositoryManager repository manager instance + * @param string $hash unique hash of the current composer configuration */ public function __construct(JsonFile $lockFile, RepositoryManager $repositoryManager, $hash) { @@ -43,13 +43,18 @@ class Locker /** * Checks whether locker were been locked (lockfile found). * - * @return Boolean + * @return Boolean */ public function isLocked() { return $this->lockFile->exists(); } + /** + * Checks whether the lock file is still up to date with the current hash + * + * @return Boolean + */ public function isFresh() { $lock = $this->lockFile->read(); @@ -60,7 +65,7 @@ class Locker /** * Searches and returns an array of locked packages, retrieved from registered repositories. * - * @return array + * @return array */ public function getLockedPackages() { @@ -93,7 +98,7 @@ class Locker /** * Locks provided packages into lockfile. * - * @param array $packages array of packages + * @param array $packages array of packages */ public function lockPackages(array $packages) { diff --git a/tests/Composer/Test/Package/LockerTest.php b/tests/Composer/Test/Package/LockerTest.php index 884a1e69e..8feeabeaf 100644 --- a/tests/Composer/Test/Package/LockerTest.php +++ b/tests/Composer/Test/Package/LockerTest.php @@ -174,6 +174,36 @@ class LockerTest extends \PHPUnit_Framework_TestCase $locker->lockPackages(array($package1)); } + public function testIsFresh() + { + $json = $this->createJsonFileMock(); + $repo = $this->createRepositoryManagerMock(); + + $locker = new Locker($json, $repo, 'md5'); + + $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(); + + $locker = new Locker($json, $repo, 'md5'); + + $json + ->expects($this->once()) + ->method('read') + ->will($this->returnValue(array('hash' => 'oldmd5'))); + + $this->assertFalse($locker->isFresh()); + } + private function createJsonFileMock() { return $this->getMockBuilder('Composer\Json\JsonFile')