Skip to content

Commit

Permalink
Fixed #2 : Added assumeCfgVar()
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 committed May 23, 2015
1 parent 41a43c7 commit 86cc4ad
Show file tree
Hide file tree
Showing 3 changed files with 32 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 @@ -119,3 +119,15 @@ function assumeFreeDiskSpace(...$args)
call_user_func_array(['MehrAlsNix\Assumptions\Assume', 'assumeFreeDiskSpace'], $args);
}
}

if (!function_exists('assumeCfgVar')) {
/**
* Make an assumption and throw
* {@link MehrAlsNix\Assumptions\AssumptionViolatedException} if it fails.
* @param ...$args
*/
function assumeCfgVar(...$args)
{
call_user_func_array(['MehrAlsNix\Assumptions\Assume', 'assumeCfgVar'], $args);
}
}
9 changes: 9 additions & 0 deletions src/Extensions/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,13 @@ public static function assumeFreeDiskSpace($directory, $available = null, $mess
assumeThat(disk_free_space($directory), is(greaterThanOrEqualTo($available)), $message);
}
}

/**
* @param string $name
* @param string $message
*/
public static function assumeCfgVar($name, $message = '')
{
assumeThat(get_cfg_var($name), is(not(false)), $message);
}
}
11 changes: 11 additions & 0 deletions tests/AssumeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,15 @@ public function assumeFreeDiskSpace()
assumeFreeDiskSpace(__DIR__);
assumeFreeDiskSpace(__DIR__, 9999999999999999.0, 'No free disc space.');
}

/**
* @test
* @expectedException \MehrAlsNix\Assumptions\AssumptionViolatedException
* @expectedExceptionMessage Not found in php.ini
*/
public function assumeCfgVar()
{
assumeCfgVar('memory_limit');
assumeCfgVar('does_not_exist', 'Not found in php.ini');
}
}

0 comments on commit 86cc4ad

Please sign in to comment.