Skip to content

Commit

Permalink
Fixed #3 - Added assumeFreeDiskSpace()
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 committed May 23, 2015
1 parent 6bc49d5 commit 41a43c7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Assumptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,15 @@ function assumeEnvironment(...$args)
call_user_func_array(['MehrAlsNix\Assumptions\Assume', 'assumeEnvironment'], $args);
}
}

if (!function_exists('assumeFreeDiskSpace')) {
/**
* Make an assumption and throw
* {@link MehrAlsNix\Assumptions\AssumptionViolatedException} if it fails.
* @param ...$args
*/
function assumeFreeDiskSpace(...$args)
{
call_user_func_array(['MehrAlsNix\Assumptions\Assume', 'assumeFreeDiskSpace'], $args);
}
}
13 changes: 13 additions & 0 deletions src/Extensions/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,17 @@ public static function assumeEnvironment($varname, $message = '')
{
assumeTrue((bool) getenv($varname), $message);
}

/**
* @param string $directory
* @param string $message
*/
public static function assumeFreeDiskSpace($directory, $available = null, $message = '')
{
if ($available === null) {
assumeThat(disk_free_space($directory), is(not(false)), $message);
} else {
assumeThat(disk_free_space($directory), is(greaterThanOrEqualTo($available)), $message);
}
}
}
11 changes: 11 additions & 0 deletions tests/AssumeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,15 @@ public function assumeEnvironment()
assumeEnvironment('PATH');
assumeEnvironment('THIS_IS_NOT_AN_ENV', 'Environment not set.');
}

/**
* @test
* @expectedException \MehrAlsNix\Assumptions\AssumptionViolatedException
* @expectedExceptionMessage No free disc space.
*/
public function assumeFreeDiskSpace()
{
assumeFreeDiskSpace(__DIR__);
assumeFreeDiskSpace(__DIR__, 9999999999999999.0, 'No free disc space.');
}
}

0 comments on commit 41a43c7

Please sign in to comment.