From 53a8bc4e30b41c982babf1573b3474dece4f2831 Mon Sep 17 00:00:00 2001 From: siad007 Date: Mon, 18 May 2015 00:45:27 +0200 Subject: [PATCH] Added socket assumption. --- src/Assume.php | 1 + src/Assumptions.php | 15 +++++++++++++++ src/Extensions/Network.php | 39 ++++++++++++++++++++++++++++++++++++++ src/Extensions/System.php | 4 ++++ tests/AssumeTest.php | 4 ++-- 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/Extensions/Network.php diff --git a/src/Assume.php b/src/Assume.php index 1d43d3a..27bd33b 100644 --- a/src/Assume.php +++ b/src/Assume.php @@ -25,6 +25,7 @@ */ class Assume { + use Extensions\Network; use Extensions\System; /** diff --git a/src/Assumptions.php b/src/Assumptions.php index dd0f01f..527f16f 100644 --- a/src/Assumptions.php +++ b/src/Assumptions.php @@ -104,3 +104,18 @@ function assumeExtensionLoaded() ); } } + +if (!function_exists('assumeSocket')) { + /** + * Make an assumption and throw + * {@link MehrAlsNix\Assumptions\AssumptionViolatedException} if it fails. + */ + function assumeSocket() + { + $args = func_get_args(); + call_user_func_array( + array('MehrAlsNix\Assumptions\Assume', 'assumeSocket'), + $args + ); + } +} diff --git a/src/Extensions/Network.php b/src/Extensions/Network.php new file mode 100644 index 0000000..5d26182 --- /dev/null +++ b/src/Extensions/Network.php @@ -0,0 +1,39 @@ +='), $message); } + /** + * @param string $extension + * @param string $message + */ public static function assumeExtensionLoaded($extension, $message = '') { assumeTrue(extension_loaded($extension), $message); diff --git a/tests/AssumeTest.php b/tests/AssumeTest.php index 054975d..9e6c9ca 100644 --- a/tests/AssumeTest.php +++ b/tests/AssumeTest.php @@ -29,7 +29,7 @@ class AssumeTest extends TestCase /** * @test * @expectedException \MehrAlsNix\Assumptions\AssumptionViolatedException - * @expectedExceptionMessage Should stop here... + * @expectedExceptionMessage Unable to connect */ public function throwExceptionWithWrongAssumption() { @@ -40,6 +40,6 @@ public function throwExceptionWithWrongAssumption() assumeNotNull(1, 2, 3); assumeTrue(true, 'Assume "true" failed.'); assumeFalse(false, 'Assume "false" failed.'); - assumeFalse(true, 'Should stop here...'); + assumeSocket('127.0.0.1', 123); } }