Skip to content

Commit

Permalink
WIP: Clear whippet.lock before adding new dependencies
Browse files Browse the repository at this point in the history
Fixes: #78
  • Loading branch information
mallorydxw committed Aug 10, 2016
1 parent 54774f4 commit 99a5c75
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Dependencies/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ private function loadWhippetFiles()
$this->lockFile = $result->unwrap();
}

$this->newLockFile = $this->factory->newInstance('\\Dxw\\Whippet\\Files\\WhippetLock', []);

return \Result\Result::ok();
}

private function updateHash()
{
$jsonHash = sha1(file_get_contents($this->dir.'/whippet.json'));
$this->lockFile->setHash($jsonHash);
$this->newLockFile->setHash($jsonHash);
}

private function loadGitignore()
Expand Down
57 changes: 54 additions & 3 deletions tests/dependencies/updater_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ private function getWhippetLockWritable(array $addDependency, /* string */ $hash
$addDependency
);

$whippetLock->expects($this->exactly(1))
->method('setHash')
->with($hash);
if ($hash !== null) {
$whippetLock->expects($this->exactly(1))
->method('setHash')
->with($hash);
} else {
$whippetLock->expects($this->exactly(0))
->method('setHash');
}

$whippetLock->expects($this->exactly($path === null ? 0 : 1))
->method('saveToPath')
Expand Down Expand Up @@ -613,4 +618,50 @@ public function testUpdateWithBrokenJson()
$this->assertEquals('missing sources', $result->getErr());
$this->assertEquals("[Updating themes/my-theme]\n", $output);
}

public function testUpdateRemovingDeps()
{
$dir = $this->getDir();

$whippetJson = $this->getWhippetJson([
'src' => [
'plugins' => '[email protected]:wordpress-plugins/',
],
'plugins' => [
['name' => 'my-plugin', 'ref' => 'v1.6'],
],
]);
$this->addFactoryCallStatic('\\Dxw\\Whippet\\Files\\WhippetJson', 'fromFile', $dir.'/whippet.json', \Result\Result::ok($whippetJson));

file_put_contents($dir.'/whippet.json', 'foobar');

$gitignore = $this->getGitignore([], [
"/wp-content/plugins/my-plugin\n",
], true, false);
$this->addFactoryNewInstance('\\Dxw\\Whippet\\Git\\Gitignore', $dir, $gitignore);

$oldWhippetLock = $this->getWhippetLockWritable([], null, $dir.'/whippet.lock', []);
$this->addFactoryCallStatic('\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($oldWhippetLock));

$newWhippetLock = $this->getWhippetLockWritable([
['plugins', 'my-plugin', '[email protected]:wordpress-plugins/my-plugin', 'd961c3d'],
], sha1('foobar'), $dir.'/whippet.lock', []);
$this->addFactoryNewInstance('\\Dxw\\Whippet\\Files\\WhippetLock', [], $newWhippetLock);

$this->addFactoryCallStatic('\\Dxw\\Whippet\\Git\\Git', 'ls_remote', '[email protected]:wordpress-themes/my-theme', 'v1.4', \Result\Result::ok('27ba906'));
$this->addFactoryCallStatic('\\Dxw\\Whippet\\Git\\Git', 'ls_remote', '[email protected]:wordpress-plugins/my-plugin', 'v1.6', \Result\Result::ok('d961c3d'));

$dependencies = new \Dxw\Whippet\Dependencies\Updater(
$this->getFactory(),
$this->getProjectDirectory($dir)
);

ob_start();
$result = $dependencies->update();
$output = ob_get_clean();

$this->assertFalse($result->isErr());
// $this->assertEquals("[Updating plugins/my-plugin]\n[Removing plugins/my-other-plugin]\n", $output);
$this->assertEquals("[Updating plugins/my-plugin]\n", $output);
}
}

0 comments on commit 99a5c75

Please sign in to comment.