Skip to content

Commit

Permalink
refactor Environment::getWorkingDirectory()
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianheuer committed Apr 8, 2016
1 parent c9c96d7 commit 5a93594
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Factory.php
Expand Up @@ -133,7 +133,7 @@ private function getConfig() {
* @return PhiveXmlConfig
*/
private function getPhiveXmlConfig() {
return new PhiveXmlConfig($this->getEnvironment()->getWorkingDirectory()->parent()->file('phive.xml'));
return new PhiveXmlConfig($this->getEnvironment()->getWorkingDirectory()->file('phive.xml'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/commands/install/InstallCommand.php
Expand Up @@ -50,7 +50,7 @@ public function execute() {
if ($this->config->installGlobally()) {
$targetDirectory = dirname($this->environment->getBinaryName());
} else {
$targetDirectory = $this->config->getWorkingDirectory();
$targetDirectory = $this->config->getTargetDirectory();
}

foreach ($this->config->getRequestedPhars() as $requestedPhar) {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/install/InstallCommandConfig.php
Expand Up @@ -34,8 +34,8 @@ public function __construct(CLI\Options $options, Config $config, PhiveXmlConfig
/**
* @return Directory
*/
public function getWorkingDirectory() {
return $this->config->getWorkingDirectory();
public function getTargetDirectory() {
return $this->config->getWorkingDirectory()->child('tools');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/commands/remove/RemoveCommand.php
Expand Up @@ -41,7 +41,7 @@ public function __construct(
}

public function execute() {
$destination = $this->config->getWorkingDirectory() . '/' . $this->config->getPharName();
$destination = $this->config->getTargetDirectory() . '/' . $this->config->getPharName();
$phar = $this->repository->getByUsage($destination);
$this->output->writeInfo(
sprintf('Removing Phar %s %s', $phar->getName(), $phar->getVersion()->getVersionString())
Expand Down
4 changes: 2 additions & 2 deletions src/commands/remove/RemoveCommandConfig.php
Expand Up @@ -29,8 +29,8 @@ public function __construct(CLI\Options $options, Config $config) {
/**
* @return Directory
*/
public function getWorkingDirectory() {
return $this->config->getWorkingDirectory();
public function getTargetDirectory() {
return $this->config->getWorkingDirectory()->child('tools');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/shared/Environment.php
Expand Up @@ -36,7 +36,7 @@ public function hasHomeDirectory() {
* @return Directory
*/
public function getWorkingDirectory() {
return (new Directory(getcwd()))->child('tools');
return new Directory(getcwd());
}

/**
Expand Down
10 changes: 8 additions & 2 deletions tests/unit/commands/install/InstallCommandConfigTest.php
Expand Up @@ -10,16 +10,22 @@ class InstallCommandConfigTest extends \PHPUnit_Framework_TestCase {

use ScalarTestDataProvider;

public function testGetWorkingDirectory() {
public function testGetTargetDirectory() {
$childDirectory = $this->getDirectoryMock();
$directory = $this->getDirectoryMock();
$directory->expects($this->once())
->method('child')
->willReturn($childDirectory);

$config = $this->getConfigMock();

$config->expects($this->once())
->method('getWorkingDirectory')
->willReturn($directory);

$commandConfig = new InstallCommandConfig($this->getOptionsMock(), $config, $this->getPhiveXmlConfigMock());
$this->assertSame($directory, $commandConfig->getWorkingDirectory());

$this->assertSame($childDirectory, $commandConfig->getTargetDirectory());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/commands/install/InstallCommandTest.php
Expand Up @@ -15,8 +15,8 @@ public function testInvokesPharService() {
$requestedPhar2 = $this->getRequestedPharMock();

$config->expects($this->any())
->method('getWorkingDirectory')
->willReturn('/foo');
->method('getTargetDirectory')
->willReturn(new Directory(__DIR__));

$config->expects($this->once())
->method('getRequestedPhars')
Expand All @@ -26,11 +26,11 @@ public function testInvokesPharService() {

$pharService->expects($this->at(0))
->method('install')
->with($requestedPhar1, '/foo');
->with($requestedPhar1, new Directory(__DIR__));

$pharService->expects($this->at(1))
->method('install')
->with($requestedPhar2, '/foo');
->with($requestedPhar2, new Directory(__DIR__));

$command->execute();

Expand Down

0 comments on commit 5a93594

Please sign in to comment.