Skip to content

Commit

Permalink
Replace DirectoryLocator with ProjectDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
mallorydxw committed Apr 6, 2016
1 parent 195c58f commit 1d49987
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 74 deletions.
2 changes: 1 addition & 1 deletion src/Dependencies/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Installer
{
public function __construct(
\Dxw\Whippet\Factory $factory,
/* string */ $dir
\Dxw\Whippet\ProjectDirectory $dir
) {
$this->factory = $factory;
$this->dir = $dir;
Expand Down
2 changes: 1 addition & 1 deletion src/Dependencies/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Migration
{
public function __construct(
\Dxw\Whippet\Factory $factory,
/* string */ $dir
\Dxw\Whippet\ProjectDirectory $dir
) {
$this->factory = $factory;
$this->dir = $dir;
Expand Down
4 changes: 2 additions & 2 deletions src/Dependencies/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Updater
{
public function __construct(
\Dxw\Whippet\Factory $factory,
/* string */ $dir
\Dxw\Whippet\ProjectDirectory $dir
) {
$this->factory = $factory;
$this->dir = $dir;
Expand Down Expand Up @@ -75,7 +75,7 @@ private function updateHash()

private function loadGitignore()
{
$this->gitignore = $this->factory->newInstance('\\Dxw\\Whippet\\Git\\Gitignore', $this->dir);
$this->gitignore = $this->factory->newInstance('\\Dxw\\Whippet\\Git\\Gitignore', (string) $this->dir);

$this->ignores = [];
if (is_file($this->dir.'/.gitignore')) {
Expand Down
25 changes: 0 additions & 25 deletions src/DirectoryLocator.php

This file was deleted.

9 changes: 4 additions & 5 deletions src/Modules/Dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public function __construct()
parent::__construct();

$this->factory = new \Dxw\Whippet\Factory();
$this->directoryLocator = new \Dxw\Whippet\DirectoryLocator(getcwd());
$this->projectDirectory = \Dxw\Whippet\ProjectDirectory::find(getcwd());
}

public function commands()
Expand All @@ -29,10 +29,9 @@ private function exitIfError(\Result\Result $result)

private function getDirectory()
{
$dirResult = $this->directoryLocator->getDirectory();
$this->exitIfError($dirResult);
$this->exitIfError($this->projectDirectory);

return $dirResult->unwrap();
return $this->projectDirectory->unwrap();
}

public function install()
Expand All @@ -55,7 +54,7 @@ public function update()

public function migrate()
{
$dir = getcwd();
$dir = new \Dxw\Whippet\ProjectDirectory(getcwd());
$migration = new \Dxw\Whippet\Dependencies\Migration($this->factory, $dir);
$this->exitIfError($migration->migrate());
}
Expand Down
30 changes: 30 additions & 0 deletions src/ProjectDirectory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Dxw\Whippet;

class ProjectDirectory
{
public static function find(/* string */ $cwd)
{
$path = $cwd;
while (dirname($path) !== $path) {
if (is_file($path.'/whippet.json')) {
return \Result\Result::ok(new self($path));
}

$path = dirname($path);
}

return \Result\Result::err('whippet.json not found');
}

public function __construct(/* string */ $path)
{
$this->path = $path;
}

public function __toString()
{
return $this->path;
}
}
16 changes: 8 additions & 8 deletions tests/dependencies/installer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testInstall()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->install();
Expand Down Expand Up @@ -83,7 +83,7 @@ public function testInstallThemeAlreadyCloned()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->install();
Expand All @@ -100,7 +100,7 @@ public function testInstallMissingWhippetJson()

$factory = $this->getNullFactory();

$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->install();
Expand All @@ -121,7 +121,7 @@ public function testInstallMissingWhippetLock()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::err('file not found')],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->install();
Expand All @@ -145,7 +145,7 @@ public function testInstallWrongHash()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->install();
Expand Down Expand Up @@ -182,7 +182,7 @@ public function testInstallCloneFails()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->install();
Expand Down Expand Up @@ -219,7 +219,7 @@ public function testInstallCheckoutFails()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->install();
Expand Down Expand Up @@ -247,7 +247,7 @@ public function testInstallBlankLockfile()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Installer($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->install();
Expand Down
10 changes: 5 additions & 5 deletions tests/dependencies/migration_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function testMigrate()
['\\Dxw\\Whippet\\Git\\Git', 'ls_remote', 'git@git.dxw.net:wordpress-plugins/my-plugin', 'v1.6', \Result\Result::ok('d961c3d')],
]);

$migration = new \Dxw\Whippet\Dependencies\Migration($factory, $dir);
$migration = new \Dxw\Whippet\Dependencies\Migration($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $migration->migrate();
Expand All @@ -109,7 +109,7 @@ public function testMigrateDeprecatedComment()

$factory = $this->getNullFactory();

$migration = new \Dxw\Whippet\Dependencies\Migration($factory, $dir);
$migration = new \Dxw\Whippet\Dependencies\Migration($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $migration->migrate();
Expand All @@ -133,7 +133,7 @@ public function testMigrateMissingSource()

$factory = $this->getNullFactory();

$migration = new \Dxw\Whippet\Dependencies\Migration($factory, $dir);
$migration = new \Dxw\Whippet\Dependencies\Migration($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $migration->migrate();
Expand All @@ -153,7 +153,7 @@ public function testMigrateMissingPluginsFile()

$factory = $this->getNullFactory();

$migration = new \Dxw\Whippet\Dependencies\Migration($factory, $dir);
$migration = new \Dxw\Whippet\Dependencies\Migration($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $migration->migrate();
Expand All @@ -179,7 +179,7 @@ public function testMigratePreExistingWhippetJson()

$factory = $this->getNullFactory();

$migration = new \Dxw\Whippet\Dependencies\Migration($factory, $dir);
$migration = new \Dxw\Whippet\Dependencies\Migration($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $migration->migrate();
Expand Down
24 changes: 12 additions & 12 deletions tests/dependencies/updater_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testUpdate()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand Down Expand Up @@ -158,7 +158,7 @@ public function testUpdateWithExistingGitignore()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand Down Expand Up @@ -212,7 +212,7 @@ public function testUpdateWithExistingGitignoreNoDuplication()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand Down Expand Up @@ -255,7 +255,7 @@ public function testUpdateFailedGitCommand()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand Down Expand Up @@ -302,7 +302,7 @@ public function testUpdateWithExplicitSrc()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand Down Expand Up @@ -346,7 +346,7 @@ public function testUpdateWithoutRef()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand Down Expand Up @@ -376,7 +376,7 @@ public function testUpdateBlankJsonfile()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand Down Expand Up @@ -431,7 +431,7 @@ public function testUpdateNoGitignore()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand Down Expand Up @@ -488,7 +488,7 @@ public function testUpdateRemoveFromGitignore()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand All @@ -508,7 +508,7 @@ public function testUpdateBubbleErrors()
['\\Dxw\\Whippet\\Files\\WhippetJson', 'fromFile', $dir.'/whippet.json', \Result\Result::err('a WhippetJson error')],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand Down Expand Up @@ -565,7 +565,7 @@ public function testUpdateNoExistingWhippetLock()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::err('file not found')],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand Down Expand Up @@ -616,7 +616,7 @@ public function testUpdateWithBrokenJson()
['\\Dxw\\Whippet\\Files\\WhippetLock', 'fromFile', $dir.'/whippet.lock', \Result\Result::ok($whippetLock)],
]);

$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, $dir);
$dependencies = new \Dxw\Whippet\Dependencies\Updater($factory, new \Dxw\Whippet\ProjectDirectory($dir));

ob_start();
$result = $dependencies->update();
Expand Down
Loading

0 comments on commit 1d49987

Please sign in to comment.