-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Clear whippet.lock before adding new dependencies
Fixes: #78
- Loading branch information
1 parent
54774f4
commit 99a5c75
Showing
2 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') | ||
|
@@ -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); | ||
} | ||
} |