Skip to content

Commit

Permalink
fix(script) Directory is the current working one.
Browse files Browse the repository at this point in the history
Explicitely use the current working directory the script directory.

This behavior was already present before, but a bug fix (see
#770) has revealed this other
bug.

The script directory must not rely on the script name (which is defined
in the `atoum` binary by the `atoum\scripts\runner` constant). The
script name points to the binary name most of the time (it is the case
right now), but the script directory is the user current working
directory, they are not related.
  • Loading branch information
Hywan authored and jubianchi committed Nov 6, 2017
1 parent 8d2c91d commit e5d77bb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 31 deletions.
6 changes: 1 addition & 5 deletions classes/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ public function __construct($name, adapter $adapter = null)

public function getDirectory()
{
$directory = $this->adapter->dirname($this->getName());

if ($this->adapter->is_dir($directory) === false) {
$directory = $this->adapter->getcwd();
}
$directory = $this->adapter->getcwd();

return rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
Expand Down
8 changes: 0 additions & 8 deletions tests/units/classes/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,6 @@ public function testGetDirectory()
$this
->given($script = new mock\script($name = uniqid()))
->and($script->setAdapter($adapter = new atoum\test\adapter()))
->and($adapter->is_dir = true)
->and($adapter->dirname = $directory = uniqid())
->then
->string($script->getDirectory())->isEqualTo($directory . DIRECTORY_SEPARATOR)
->if($adapter->dirname = $directory . DIRECTORY_SEPARATOR)
->then
->string($script->getDirectory())->isEqualTo($directory . DIRECTORY_SEPARATOR)
->if($adapter->is_dir = false)
->and($adapter->getcwd = $currentDirectory = uniqid())
->then
->string($script->getDirectory())->isEqualTo($currentDirectory . DIRECTORY_SEPARATOR)
Expand Down
9 changes: 0 additions & 9 deletions tests/units/classes/script/configurable.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,13 @@ public function testUseDefaultConfigFiles()
->and($this->calling($configurable)->useConfigFile = function () {
})
->and($configurable->setAdapter($adapter = new atoum\test\adapter()))
->and($adapter->is_dir = true)
->then
->object($configurable->useDefaultConfigFiles())->isIdenticalTo($configurable)
->mock($configurable)
->foreach(testedClass::getSubDirectoryPath($directory), function ($mock, $path) {
$mock->call('useConfigFile')->withArguments($path . testedClass::defaultConfigFile)->atLeastOnce();
})
->if($adapter->is_dir = false)
->and($adapter->getcwd = $workingDirectory = uniqid() . DIRECTORY_SEPARATOR . uniqid() . DIRECTORY_SEPARATOR . uniqid())
->then
->object($configurable->useDefaultConfigFiles())->isIdenticalTo($configurable)
->mock($configurable)
->foreach(testedClass::getSubDirectoryPath($workingDirectory), function ($mock, $path) {
$mock->call('useConfigFile')->withArguments($path . testedClass::defaultConfigFile)->atLeastOnce();
})
->if($adapter->is_dir = true)
->and($adapter->getcwd = $otherWorkingDirectory = uniqid() . DIRECTORY_SEPARATOR . uniqid() . DIRECTORY_SEPARATOR . uniqid())
->and($this->calling($configurable)->useConfigFile->throw = new atoum\includer\exception())
->then
Expand Down
4 changes: 2 additions & 2 deletions tests/units/classes/scripts/git/pusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function test__construct()
->if($pusher = new testedClass(__FILE__))
->then
->string($pusher->getRemote())->isEqualTo(testedClass::defaultRemote)
->string($pusher->getTagFile())->isEqualTo(__DIR__ . DIRECTORY_SEPARATOR . testedClass::defaultTagFile)
->string($pusher->getTagFile())->isEqualTo(getcwd() . DIRECTORY_SEPARATOR . testedClass::defaultTagFile)
->object($pusher->getTaggerEngine())->isEqualTo(new scripts\tagger\engine())
->string($pusher->getWorkingDirectory())->isEqualTo(getcwd())
->object($pusher->getGit())->isEqualTo(new commands\git())
Expand All @@ -58,7 +58,7 @@ public function testSetTagFile()
->object($pusher->setTagFile($tagFile = uniqid()))->isIdenticalTo($pusher)
->string($pusher->getTagFile())->isEqualTo($tagFile)
->object($pusher->setTagFile())->isIdenticalTo($pusher)
->string($pusher->getTagFile())->isEqualTo(__DIR__ . DIRECTORY_SEPARATOR . testedClass::defaultTagFile)
->string($pusher->getTagFile())->isEqualTo(getcwd() . DIRECTORY_SEPARATOR . testedClass::defaultTagFile)
;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/units/classes/scripts/phar/stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public function testSignature()
;
}

/**
* @engine inline
*/
public function testVersion()
{
$this
Expand Down
14 changes: 7 additions & 7 deletions tests/units/classes/scripts/runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,8 @@ public function testInit()
->withArguments('Default bootstrap file \'' . testedClass::defaultBootstrapFile . '\' was successfully created in ' . $runner->getDirectory())->once()
->adapter($adapter)
->call('copy')
->withArguments(atoum\directory . '/resources/configurations/runner/atoum.php.dist', __DIR__ . DIRECTORY_SEPARATOR . testedClass::defaultConfigFile)->once()
->withArguments(atoum\directory . '/resources/configurations/runner/bootstrap.php.dist', __DIR__ . DIRECTORY_SEPARATOR . testedClass::defaultBootstrapFile)->once()
->withArguments(atoum\directory . '/resources/configurations/runner/atoum.php.dist', getcwd() . DIRECTORY_SEPARATOR . testedClass::defaultConfigFile)->once()
->withArguments(atoum\directory . '/resources/configurations/runner/bootstrap.php.dist', getcwd() . DIRECTORY_SEPARATOR . testedClass::defaultBootstrapFile)->once()
->if($this->resetAdapter($adapter))
->and($this->resetMock($outputWriter))
->then
Expand Down Expand Up @@ -853,8 +853,8 @@ public function testInit()
->withArguments('Default bootstrap file \'' . testedClass::defaultBootstrapFile . '\' was successfully created in ' . $runner->getDirectory())->once()
->adapter($adapter)
->call('copy')
->withArguments(atoum\directory . '/resources/configurations/runner/atoum.php.dist', __DIR__ . DIRECTORY_SEPARATOR . testedClass::defaultConfigFile)->once()
->withArguments(atoum\directory . '/resources/configurations/runner/bootstrap.php.dist', __DIR__ . DIRECTORY_SEPARATOR . testedClass::defaultBootstrapFile)->once()
->withArguments(atoum\directory . '/resources/configurations/runner/atoum.php.dist', getcwd() . DIRECTORY_SEPARATOR . testedClass::defaultConfigFile)->once()
->withArguments(atoum\directory . '/resources/configurations/runner/bootstrap.php.dist', getcwd() . DIRECTORY_SEPARATOR . testedClass::defaultBootstrapFile)->once()
->if($this->resetAdapter($adapter))
->and($this->resetMock($outputWriter))
->and($this->resetMock($prompt))
Expand All @@ -872,8 +872,8 @@ public function testInit()
->withArguments('Default bootstrap file \'' . testedClass::defaultBootstrapFile . '\' was successfully created in ' . $runner->getDirectory())->never()
->adapter($adapter)
->call('copy')
->withArguments(atoum\directory . '/resources/configurations/runner/atoum.php.dist', __DIR__ . DIRECTORY_SEPARATOR . testedClass::defaultConfigFile)->never()
->withArguments(atoum\directory . '/resources/configurations/runner/bootstrap.php.dist', __DIR__ . DIRECTORY_SEPARATOR . testedClass::defaultBootstrapFile)->never()
->withArguments(atoum\directory . '/resources/configurations/runner/atoum.php.dist', getcwd() . DIRECTORY_SEPARATOR . testedClass::defaultConfigFile)->never()
->withArguments(atoum\directory . '/resources/configurations/runner/bootstrap.php.dist', getcwd() . DIRECTORY_SEPARATOR . testedClass::defaultBootstrapFile)->never()
->if($this->resetAdapter($adapter))
->and($this->resetMock($outputWriter))
->and($this->resetMock($prompt))
Expand All @@ -900,7 +900,7 @@ public function testInit()
$runner->init();
})
->isInstanceOf(atoum\exceptions\runtime::class)
->hasMessage('Unable to write \'' . atoum\directory . '/resources/configurations/runner/atoum.php.dist\' to \'' . __DIR__ . DIRECTORY_SEPARATOR . testedClass::defaultConfigFile . '\'')
->hasMessage('Unable to write \'' . atoum\directory . '/resources/configurations/runner/atoum.php.dist\' to \'' . getcwd() . DIRECTORY_SEPARATOR . testedClass::defaultConfigFile . '\'')
;
}

Expand Down

0 comments on commit e5d77bb

Please sign in to comment.