Skip to content

Commit

Permalink
Related to issue #49 again, again and again.
Browse files Browse the repository at this point in the history
  • Loading branch information
mageekguy committed Jun 15, 2012
1 parent 86cb7ae commit afd633b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
16 changes: 5 additions & 11 deletions classes/mock/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __call($method, $arguments)
throw new logic('Argument 0 is not set for function ' . $method . '()');
}

$stream = self::cleanStreamName($arguments[0]);
$stream = self::slashize($arguments[0]);

if (isset(self::$streams[$stream]) === false)
{
Expand All @@ -64,7 +64,7 @@ public static function setAdapter(adapter $adapter)

public static function get($stream)
{
$stream = self::cleanStreamName($stream);
$stream = self::slashize($stream);

$adapter = self::getAdapter();

Expand Down Expand Up @@ -112,17 +112,11 @@ public static function getProtocol($stream)
return $scheme;
}

public static function cleanStreamName($stream)
public static function slashize($stream)
{
$directorySeparator = self::getAdapter()->constant('DIRECTORY_SEPARATOR');
$path = preg_replace('#^[^:]+://#', '', $stream);

if ($directorySeparator != '/')
{
$path = preg_replace('#^[^:]+://#', '', $stream);
$stream = substr($stream, 0, strlen($stream) - strlen($path)) . str_replace($directorySeparator, '/', $path);
}

return $stream;
return substr($stream, 0, strlen($stream) - strlen($path)) . str_replace('\\', '/', $path);
}
}

Expand Down
12 changes: 2 additions & 10 deletions tests/units/classes/mock/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,8 @@ public function testGetProtocol()
public function testCleanStream()
{
$this
->if($adapter = new test\adapter())
->and($adapter->constant = '/')
->and(mock\stream::setAdapter($adapter))
->then
->string(mock\stream::cleanStreamName('foo/bar'))->isEqualTo('foo/bar')
->string(mock\stream::cleanStreamName('foo\bar'))->isEqualTo('foo\bar')
->if($adapter->constant = '\\')
->then
->string(mock\stream::cleanStreamName('foo/bar'))->isEqualTo('foo/bar')
->string(mock\stream::cleanStreamName('foo\bar'))->isEqualTo('foo/bar')
->string(mock\stream::slashize('foo/bar'))->isEqualTo('foo/bar')
->string(mock\stream::slashize('foo\bar'))->isEqualTo('foo/bar')
;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/units/classes/report/fields/runner/coverage/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ protected static function uniformizeStream($stream)
if (DIRECTORY_SEPARATOR != '/')
{
$path = preg_replace('#^[^:]+://#', '', $stream);
$stream = substr($stream, 0, strlen($stream) - strlen($path)) . str_replace('/', '\\', $path);
$stream = substr($stream, 0, strlen($stream) - strlen($path)) . str_replace('/', DIRECTORY_SEPARATOR, $path);
}

return $stream;
Expand Down
26 changes: 16 additions & 10 deletions tests/units/classes/scripts/builder/vcs/svn.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,21 +382,27 @@ public function testCleanWorkingDirectory()
->when(function() use ($svn) { $svn->setWorkingDirectory('atoum://workingDirectory'); })
->object($svn->cleanWorkingDirectory())->isIdenticalTo($svn)
->adapter($adapter)
->call('unlink')->withArguments(self::cleanPath('atoum://workingDirectory/aDirectory/firstFile'))->once()
->call('unlink')->withArguments(self::cleanPath('atoum://workingDirectory/aDirectory/secondFile'))->once()
->call('rmdir')->withArguments(self::cleanPath('atoum://workingDirectory/aDirectory'))->once()
->call('rmdir')->withArguments(self::cleanPath('atoum://workingDirectory/emptyDirectory'))->once()
->call('unlink')->withArguments(self::cleanPath('atoum://workingDirectory/anOtherDirectory/anOtherFirstFile'))->once()
->call('unlink')->withArguments(self::cleanPath('atoum://workingDirectory/anOtherDirectory/anOtherSecondFile'))->once()
->call('rmdir')->withArguments(self::cleanPath('atoum://workingDirectory/anOtherDirectory'))->once()
->call('unlink')->withArguments(self::cleanPath('atoum://workingDirectory/aFile'))->once()
->call('unlink')->withArguments(self::uniformizeStream('atoum://workingDirectory/aDirectory/firstFile'))->once()
->call('unlink')->withArguments(self::uniformizeStream('atoum://workingDirectory/aDirectory/secondFile'))->once()
->call('rmdir')->withArguments(self::uniformizeStream('atoum://workingDirectory/aDirectory'))->once()
->call('rmdir')->withArguments(self::uniformizeStream('atoum://workingDirectory/emptyDirectory'))->once()
->call('unlink')->withArguments(self::uniformizeStream('atoum://workingDirectory/anOtherDirectory/anOtherFirstFile'))->once()
->call('unlink')->withArguments(self::uniformizeStream('atoum://workingDirectory/anOtherDirectory/anOtherSecondFile'))->once()
->call('rmdir')->withArguments(self::uniformizeStream('atoum://workingDirectory/anOtherDirectory'))->once()
->call('unlink')->withArguments(self::uniformizeStream('atoum://workingDirectory/aFile'))->once()
->call('rmdir')->withArguments('atoum://workingDirectory')->never()
;
}

protected static function cleanPath($path)
protected static function uniformizeStream($stream)
{
return (DIRECTORY_SEPARATOR == '/' ? $path : str_replace('/', '\\', $path));
if (DIRECTORY_SEPARATOR != '/')
{
$path = preg_replace('#^[^:]+://#', '', $stream);
$stream = substr($stream, 0, strlen($stream) - strlen($path)) . str_replace('/', DIRECTORY_SEPARATOR, $path);
}

return $stream;
}
}

Expand Down

0 comments on commit afd633b

Please sign in to comment.