From 8d476034a3bed148b4ff3fefd38b9a95958424e2 Mon Sep 17 00:00:00 2001 From: Rob Skilling Date: Fri, 3 Feb 2017 11:38:45 +0000 Subject: [PATCH] (Refactor): Move updateHash() and loadGitignore() to update() To minimise duplication. --- src/Dependencies/Updater.php | 4 ++-- tests/dependencies/updater_test.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Dependencies/Updater.php b/src/Dependencies/Updater.php index 5e55618..c851931 100644 --- a/src/Dependencies/Updater.php +++ b/src/Dependencies/Updater.php @@ -59,6 +59,8 @@ public function updateAll() private function update(array $dependencies) { + $this->updateHash(); + $this->loadGitignore(); $count = 0; foreach ($dependencies as $type => $typeDependencies) { foreach ($typeDependencies as $dep) { @@ -84,8 +86,6 @@ private function prepareForUpdate() if ($result->isErr()) { return $result; } - $this->updateHash(); - $this->loadGitignore(); return \Result\Result::ok(); } diff --git a/tests/dependencies/updater_test.php b/tests/dependencies/updater_test.php index cfa3f09..e6f3785 100644 --- a/tests/dependencies/updater_test.php +++ b/tests/dependencies/updater_test.php @@ -26,7 +26,7 @@ private function getGitignore(array $get, array $save, /* bool */ $saveIgnores, return $gitignore; } - private function getWhippetLockWritable(array $addDependency, /* string */ $hash, /* string */ $path, array $getDependencies) + private function getWhippetLockWritable(array $addDependency, /* string */ $hash, /* string */ $path, array $getDependencies, /* boolean */ $setHash = true) { $whippetLock = $this->getMockBuilder('\\Dxw\\Whippet\\Files\\WhippetLock') ->disableOriginalConstructor() @@ -41,7 +41,7 @@ private function getWhippetLockWritable(array $addDependency, /* string */ $hash $addDependency ); - $whippetLock->expects($this->exactly(1)) + $whippetLock->expects($this->exactly($setHash === true ? 1 : 0)) ->method('setHash') ->with($hash); @@ -683,7 +683,7 @@ public function testUpdateSingleNoMatch() $this->addFactoryCallStatic('\\Dxw\\Whippet\\Files\\WhippetJson', 'fromFile', $dir.'/whippet.json', \Result\Result::ok($whippetJson)); - $whippetLock = $this->getWhippetLockWritable([], sha1('foobar'), null, []); + $whippetLock = $this->getWhippetLockWritable([], sha1('foobar'), null, [], false); $this->addFactoryCallStatic('\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)); $dependencies = new \Dxw\Whippet\Dependencies\Updater(