diff --git a/system/libraries/network/class.streamsocket.inc.php b/system/libraries/network/class.streamsocket.inc.php
new file mode 100644
index 0000000000000000000000000000000000000000..721d44c0494d9bb37a0af81274cfece2e0b88ced
--- /dev/null
+++ b/system/libraries/network/class.streamsocket.inc.php
@@ -0,0 +1,450 @@
+<?php
+
+/**
+ * This file contains an abstract stream socket wrapper class.
+ *
+ * PHP Version 5.3
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Libraries
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ * @copyright  2012, M2Mobi BV, Amsterdam, The Netherlands
+ * @license    http://lunr.nl/LICENSE MIT License
+ */
+
+namespace Lunr\Libraries\Network;
+
+/**
+ * abstract stream socket wrapper class.
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Libraries
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ */
+abstract class StreamSocket
+{
+    /**
+     * Stream socket context options array
+     * @var array
+     */
+    protected $context_options;
+
+    /**
+     * Stream socket context
+     * @var resource
+     */
+    protected $context;
+
+    /**
+     * Stream socket resource handle
+     * @var resource
+     */
+    protected $handle;
+
+    /**
+     * Informations about the request
+     * @var array
+     */
+    protected $meta_data;
+
+    /**
+     * Stream socket error number
+     * @var Integer
+     */
+    protected $errno;
+
+    /**
+     * Stream socket error message
+     * @var String
+     */
+    protected $errmsg;
+
+    /**
+     * Blocking mode of the stream
+     * @var Boolean
+     */
+    protected $blocking;
+
+    /**
+     * Notification callback function name
+     * @var String
+     */
+    protected $notification;
+
+    /**
+     * flag values for the stream creation
+     * @var array
+     */
+    protected $flags;
+
+    /**
+     * Time out for read/write transactions in seconds.
+     * @var Integer
+     */
+    protected $timeout_seconds;
+
+    /**
+     * Time out for read/write transactions in microseconds.
+     * @var Integer
+     */
+    protected $timeout_microseconds;
+
+    /**
+     * Conctructor.
+     *
+     * @param array  $context_options The options to create this stream stream context.context with,
+     *                                default empty array
+     */
+    public function __construct()
+    {
+        $this->context_options = array();
+
+        // default: no error
+        $this->errno   = 0;
+        $this->errmsg  = '';
+
+        // default no callback function
+        $this->notification = '';
+
+        // default: no meta_data
+        $this->meta_data  = array();
+        // flags are empty as from abstract class
+        $this->flags = array();
+
+        // pre-initialization
+        $this->handle  = NULL;
+        $this->context = NULL;
+
+        // default blocking stream
+        $this->blocking = TRUE;
+
+        // default stream timeout
+        $this->timeout_seconds = 60;
+        $this->timeout_microseconds = 0;
+    }
+
+    /**
+     * Destructor.
+     */
+    public function __destruct()
+    {
+        unset($this->context_options);
+        unset($this->meta_data);
+        unset($this->errno);
+        unset($this->errmsg);
+        unset($this->blocking);
+        unset($this->notification);
+        unset($this->flag);
+        unset($this->timeout_seconds);
+        unset($this->timeout_microseconds);
+        if( is_resource($this->handle))
+        {
+            fclose($this->handle);
+        }
+        unset($this->handle);
+        unset($this->context);
+    }
+
+    /**
+     * Get access to certain private attributes.
+     *
+     * This gives access to errno, errmsg and meta_data.
+     *
+     * @param String $name Attribute name
+     *
+     * @return mixed $return Value of the chosen attribute
+     */
+    public function __get($name)
+    {
+        switch ($name)
+        {
+            case 'meta_data':
+            case 'errno':
+            case 'errmsg':
+                return $this->{$name};
+            default:
+                return NULL;
+        }
+    }
+
+    /**
+     * Set an option for the stream stream context.in the given wrapper.
+     *
+     * @param String $wrapper The wrapper of the option.
+     * @param String $option  The option name
+     * @param mixed  $value   The value of the option
+     *
+     * @return StreamSocket $self Self-reference
+     */
+    public function set_context_option($wrapper, $option, $value)
+    {
+        if(! is_string($wrapper))
+        {
+            return $this;
+        }
+
+        if(! in_array($wrapper, stream_get_wrappers() )  &&
+               ! in_array($wrapper, stream_get_transports()))
+        {
+            return $this;
+        }
+
+        if(! array_key_exists($wrapper, $this->context_options))
+        {
+            $this->context_options[$wrapper] = array() ;
+        }
+
+        $this->context_options[$wrapper][$option] = $value;
+
+        return $this;
+    }
+
+    /**
+     * Set the options for the stream stream context.
+     *
+     * @param array $option The options array
+     *
+     * @return StreamSocket $self Self-reference
+     */
+    public function set_context_options($options)
+    {
+        if(! is_array($options))
+        {
+            return $this;
+        }
+
+        foreach($options as $wrapper => $pair)
+        {
+            foreach($pair as $option => $value)
+            {
+                $this->set_context_option($wrapper, $option, $value);
+            }
+        }
+
+        return $this;
+    }
+
+    /**
+     * Set the blocking mode for the stream.
+     *
+     * @param Boolean $blocking Wether the stream is set to blocking mode or not
+     *
+     * @return StreamSocket $self Self-reference
+     */
+    public function set_blocking($blocking)
+    {
+        if(is_bool($blocking))
+        {
+            $this->blocking = $blocking;
+        }
+        return $this;
+    }
+
+    /**
+     * Set the timeout in seconds for the stream for read/write purpose.
+     *
+     * @param Integer $seconds The part in seconds of the timeout
+     * @param Integer $micros  The part in seconds of the timeout
+     *
+     * @return StreamSocket $self Self-reference
+     */
+    public function set_timeout_seconds($seconds)
+    {
+        if(is_int($seconds) && $seconds >= 0)
+        {
+            $this->timeout_seconds = $seconds;
+        }
+        return $this;
+    }
+
+    /**
+     * Set the timeout in micro seconds for the stream for read/write purpose.
+     *
+     * @param Integer $seconds The part in seconds of the timeout
+     * @param Integer $micros  The part in seconds of the timeout
+     *
+     * @return StreamSocket $self Self-reference
+     */
+    public function set_timeout_microseconds($microseconds)
+    {
+        if(is_int($microseconds) && $microseconds >= 0)
+        {
+            $this->timeout_microseconds = $microseconds;
+        }
+        return $this;
+    }
+
+    /**
+     * Set the notification callback function of this stream stream context.
+     * For implementing the callback function see:
+     * http://www.php.net/manual/en/function.stream-notification-callback.php
+     *
+     * @param String $notification The notification function name
+     *
+     * @return StreamSocket $self Self-reference
+     */
+    public function set_notification_callback($notification)
+    {
+        $this->notification = $notification;
+        return $this;
+    }
+
+    /**
+     * Tells wether the stream has data to read or not.
+     *
+     * @param Integer $tv_sec  Time out in seconds
+     * @param Integer $tv_usec Time out in micro seconds
+     *
+     * @return Boolean $return TRUE if the socket has data to read, FALSE otherwise and
+     *                         NULL if the stream is closed or if an error occured
+     */
+    public function is_readable()
+    {
+        return $this->changed(TRUE, FALSE, FALSE) ;
+    }
+
+    /**
+     * Tells wether the stream is available for writing.
+     *
+     * @param Integer $tv_sec  Time out in seconds
+     * @param Integer $tv_usec Time out in micro seconds
+     *
+     * @return Boolean $return TRUE if the socket is ready for writing, FALSE otherwise and
+     *                         NULL if the stream is closed or if an error occured
+     */
+    public function is_writable()
+    {
+        return $this->changed(FALSE, TRUE, FALSE) ;
+    }
+
+    /**
+     * Tells wether the stream threw an exception.
+     *
+     * @param Integer $tv_sec  Time out in seconds
+     * @param Integer $tv_usec Time out in micro seconds
+     *
+     * @return mixed Boolean TRUE if the socket has thrown an exception, FALSE otherwise and
+     *                       NULL if the stream is closed or if an error occured
+     */
+    public function is_exception_thrown()
+    {
+        return $this->changed(FALSE, FALSE, TRUE) ;
+    }
+
+    /**
+     * Returns the changed state of this stream,
+     * e.g if it is readable and/or writable and/or if it has thrown exception.
+     *
+     * @param boolean $read       Set to TRUE for testing read availability of the stream purpose
+     * @param boolean $write      Set to TRUE for testing write availability of the stream purpose
+     * @param boolean $exception  Set to TRUE for testing exception thrown by the stream purpose
+     *
+     * @return Boolean $return TRUE state has change or launched an exception, FALSE otherwise and
+     *                         NULL if the stream is closed or if an error occured
+     */
+    protected function changed($read, $write, $exception)
+    {
+        if(!is_resource($this->handle))
+        {
+            return NULL;
+        }
+
+        $NULL = NULL;
+
+        $read_array   = $read      ? array($this->handle) : $NULL;
+        $write_array  = $write     ? array($this->handle) : $NULL;
+        $except_array = $exception ? array($this->handle) : $NULL;
+
+        $changed = stream_select($read_array, $write_array, $except_array, $this->timeout_seconds, $this->timeout_microseconds);
+
+        if($changed === FALSE)
+        {
+            return NULL;
+        }
+        else
+        {
+            return ($changed > 0);
+        }
+    }
+
+    /**
+     * Create the context of this stream with the options passed
+     * callback function if set.
+     *
+     * @return resource $return The created context resource
+     */
+    protected function create_context()
+    {
+        $this->context = stream_context_create($this->context_options);
+
+        if(!empty($this->notification))
+        {
+            stream_context_set_params($this->context, array("notification" => $this->notification));
+        }
+
+        return $this->context;
+    }
+
+    /**
+     * Add the flag for stream resource creation.
+     *
+     * @param String $flag the flag identifier of the flag to add
+     *
+     * @return StreamSocket $self Self-reference
+     */
+    public abstract function add_flag($flag);
+
+    /**
+     * Removes the flag for stream resource creation.
+     *
+     * @param String $flag The flag identifier of the flag to remove
+     *
+     * @return StreamSocket $self Self-reference
+     */
+    public abstract function remove_flag($flag);
+
+    /**
+     * Create the resource handle of this stream socket
+     *
+     * @return resource $return The created handle
+     */
+    protected abstract function create_handle();
+
+    /**
+     * Write the given data on the stream.
+     *
+     * @param mixed $data the data to write
+     *
+     * @return mixed $return the count of written bytes or FALSE if an error occurs
+     */
+    public abstract function write($data);
+
+    /**
+     * Read the data from the string.
+     *
+     * @param Integer $lenght The requested length of byte to read
+     *
+     * @return String $return The n byte read from the stream, FALSE if an error occured
+     */
+    public abstract function read($length);
+
+    /**
+     * Open the stream if not already opened.
+     *
+     * @return Boolean $return TRUE if the stream is open, FALSE otherwise
+     */
+    public abstract function open();
+
+    /**
+     * Close the stream if not already closed,
+     * optional call cause the call of read or write opens the stream as well.
+     *
+     * @return Boolean $return TRUE if stream properly closed, FALSE om error
+     */
+    public abstract function close();
+
+}
+
+?>
\ No newline at end of file
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index 5a10e3313edb361043c378cfeb923c82a7032077..b1591ffc0a3c3ceb299ec5c7ca706dd9b965458d 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -56,6 +56,10 @@
             <file>tests/system/libraries/network/class.curl.setget.test.php</file>
             <file>tests/system/libraries/network/class.curl.execute.test.php</file>
             <file>tests/system/libraries/network/class.curl.request.test.php</file>
+            <file>tests/system/libraries/network/class.streamsocket.base.test.php</file>
+            <file>tests/system/libraries/network/class.streamsocket.context.test.php</file>
+            <file>tests/system/libraries/network/class.streamsocket.setget.test.php</file>
+            <file>tests/system/libraries/network/class.streamsocket.state.test.php</file>
             <file>tests/system/libraries/dataaccess/class.mysqlqueryresult.base.test.php</file>
             <file>tests/system/libraries/dataaccess/class.mysqlqueryresult.failed.test.php</file>
             <file>tests/system/libraries/dataaccess/class.mysqlqueryresult.success.test.php</file>
diff --git a/tests/system/libraries/network/class.curl.base.test.php b/tests/system/libraries/network/class.curl.base.test.php
index f4f1590c57a14fd7d6ba5fb78f0c59f1827aac1d..6fe6af796a33227faf1b15f5b0b5af9a9901f6c4 100644
--- a/tests/system/libraries/network/class.curl.base.test.php
+++ b/tests/system/libraries/network/class.curl.base.test.php
@@ -6,7 +6,7 @@
  * PHP Version 5.3
  *
  * @category   Libraries
- * @package    Core
+ * @package    Network
  * @subpackage Tests
  * @author     Heinz Wiesinger <heinz@m2mobi.com>
  * @copyright  2012, M2Mobi BV, Amsterdam, The Netherlands
@@ -21,7 +21,7 @@ use ReflectionClass;
  * This class contains basic test methods for the Curl class.
  *
  * @category   Libraries
- * @package    Core
+ * @package    Network
  * @subpackage Tests
  * @author     Heinz Wiesinger <heinz@m2mobi.com>
  * @covers     Lunr\Libraries\Network\Curl
diff --git a/tests/system/libraries/network/class.curl.execute.test.php b/tests/system/libraries/network/class.curl.execute.test.php
index 7e0ef1ee7c0f56c64ffef673609d5d2d7ca175df..10fef4027e0faa16eeaf8bd6834c17f51822a698 100644
--- a/tests/system/libraries/network/class.curl.execute.test.php
+++ b/tests/system/libraries/network/class.curl.execute.test.php
@@ -6,7 +6,7 @@
  * PHP Version 5.3
  *
  * @category   Libraries
- * @package    Core
+ * @package    Network
  * @subpackage Tests
  * @author     Heinz Wiesinger <heinz@m2mobi.com>
  * @copyright  2012, M2Mobi BV, Amsterdam, The Netherlands
@@ -21,7 +21,7 @@ use ReflectionClass;
  * This class contains test methods for init and execution in Curl class.
  *
  * @category   Libraries
- * @package    Core
+ * @package    Network
  * @subpackage Tests
  * @author     Heinz Wiesinger <heinz@m2mobi.com>
  * @covers     Lunr\Libraries\Network\Curl
diff --git a/tests/system/libraries/network/class.curl.request.test.php b/tests/system/libraries/network/class.curl.request.test.php
index bad7ea508157e93c11ac4f7bb33ac755df7a5ca5..26f9b51f747d37131ec9aa21ad94b0527b81133a 100644
--- a/tests/system/libraries/network/class.curl.request.test.php
+++ b/tests/system/libraries/network/class.curl.request.test.php
@@ -6,7 +6,7 @@
  * PHP Version 5.3
  *
  * @category   Libraries
- * @package    Core
+ * @package    Network
  * @subpackage Tests
  * @author     Heinz Wiesinger <heinz@m2mobi.com>
  * @copyright  2012, M2Mobi BV, Amsterdam, The Netherlands
@@ -21,7 +21,7 @@ use ReflectionClass;
  * This class contains test methods for requests in Curl class.
  *
  * @category   Libraries
- * @package    Core
+ * @package    Network
  * @subpackage Tests
  * @author     Heinz Wiesinger <heinz@m2mobi.com>
  * @covers     Lunr\Libraries\Network\Curl
diff --git a/tests/system/libraries/network/class.curl.setget.test.php b/tests/system/libraries/network/class.curl.setget.test.php
index 1324e2d858de758cc29bb9fc8a5fc586d52554fa..1e0e891e4e5ae75644949dc166e3f242a01591d5 100644
--- a/tests/system/libraries/network/class.curl.setget.test.php
+++ b/tests/system/libraries/network/class.curl.setget.test.php
@@ -6,7 +6,7 @@
  * PHP Version 5.3
  *
  * @category   Libraries
- * @package    Core
+ * @package    Network
  * @subpackage Tests
  * @author     Heinz Wiesinger <heinz@m2mobi.com>
  * @copyright  2012, M2Mobi BV, Amsterdam, The Netherlands
@@ -21,7 +21,7 @@ use ReflectionClass;
  * This class contains test methods for the getters and setters of the Curl class.
  *
  * @category   Libraries
- * @package    Core
+ * @package    Network
  * @subpackage Tests
  * @author     Heinz Wiesinger <heinz@m2mobi.com>
  * @covers     Lunr\Libraries\Network\Curl
diff --git a/tests/system/libraries/network/class.curl.test.php b/tests/system/libraries/network/class.curl.test.php
index fe7776ae888406a772ca841f0c9c228a3c1cf16f..881ebbb8d6b42840b7df0a72f12005682152ec2b 100644
--- a/tests/system/libraries/network/class.curl.test.php
+++ b/tests/system/libraries/network/class.curl.test.php
@@ -6,7 +6,7 @@
  * PHP Version 5.3
  *
  * @category   Libraries
- * @package    Core
+ * @package    Network
  * @subpackage Tests
  * @author     Heinz Wiesinger <heinz@m2mobi.com>
  * @copyright  2012, M2Mobi BV, Amsterdam, The Netherlands
@@ -21,7 +21,7 @@ use ReflectionClass;
  * This class contains test methods for the Curl class.
  *
  * @category   Libraries
- * @package    Core
+ * @package    Network
  * @subpackage Tests
  * @author     Heinz Wiesinger <heinz@m2mobi.com>
  * @covers     Lunr\Libraries\Network\Curl
diff --git a/tests/system/libraries/network/class.streamsocket.base.test.php b/tests/system/libraries/network/class.streamsocket.base.test.php
new file mode 100644
index 0000000000000000000000000000000000000000..097b7756c4ac113bf1a4af94d709bf7877da81fc
--- /dev/null
+++ b/tests/system/libraries/network/class.streamsocket.base.test.php
@@ -0,0 +1,165 @@
+<?php
+
+/**
+ * This file contains the StreamSocketBaseTest class.
+ *
+ * PHP Version 5.3
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Tests
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ * @copyright  2012, M2Mobi BV, Amsterdam, The Netherlands
+ * @license    http://lunr.nl/LICENSE MIT License
+ */
+
+namespace Lunr\Libraries\Network;
+use PHPUnit_Framework_TestCase;
+use ReflectionClass;
+
+/**
+ * This class contains basic test methods for the StreamSocket class.
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Tests
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ * @covers     Lunr\Libraries\Network\StreamSocket
+ */
+class StreamSocketBaseTest extends StreamSocketTest
+{
+
+    /**
+     * Tests that context_options is an empty array by default.
+     */
+    public function testContextOptionsIsEmptyArray()
+    {
+        $property = $this->stream_socket_reflection->getProperty('context_options');
+        $property->setAccessible(TRUE);
+
+        $value = $property->getValue($this->stream_socket);
+
+        $this->assertInternalType('array', $value);
+        $this->assertEmpty($value);
+    }
+
+    /**
+     * Tests that meta data info is an empty array by default.
+     */
+    public function testMetaDataIsEmptyArray()
+    {
+        $property = $this->stream_socket_reflection->getProperty('meta_data');
+        $property->setAccessible(TRUE);
+
+        $value = $property->getValue($this->stream_socket);
+
+        $this->assertInternalType('array', $value);
+        $this->assertEmpty($value);
+    }
+
+    /**
+     * Tests that flags is an empty array by default.
+     */
+    public function testFlagsIsEmptyArray()
+    {
+        $property = $this->stream_socket_reflection->getProperty('flags');
+        $property->setAccessible(TRUE);
+
+        $value = $property->getValue($this->stream_socket);
+
+        $this->assertInternalType('array', $value);
+        $this->assertEmpty($value);
+    }
+
+    /**
+     * Tests that errno equals 0 by default.
+     */
+    public function testErrnoIsZero()
+    {
+        $property = $this->stream_socket_reflection->getProperty('errno');
+        $property->setAccessible(TRUE);
+
+        $this->assertEquals(0, $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that blocking equals TRUE by default.
+     */
+    public function testBlockingIsOne()
+    {
+        $property = $this->stream_socket_reflection->getProperty('blocking');
+        $property->setAccessible(TRUE);
+
+        $this->assertTrue($property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that errmsg is an empty string by default.
+     */
+    public function testErrmsgIsEmptyString()
+    {
+        $property = $this->stream_socket_reflection->getProperty('errno');
+        $property->setAccessible(TRUE);
+
+        $this->assertEquals(0, $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that notification is an empty string by default.
+     */
+    public function testNotificationIsEmptyString()
+    {
+        $property = $this->stream_socket_reflection->getProperty('notification');
+        $property->setAccessible(TRUE);
+
+        $this->assertEquals('', $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that handle is NULL by default.
+     */
+    public function testHandleIsNull()
+    {
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+
+        $this->assertNull($property->getValue($this->stream_socket));
+    }
+
+
+    /**
+     * Tests that context is NULL by default.
+     */
+    public function testContextIsNull()
+    {
+        $property = $this->stream_socket_reflection->getProperty('context');
+        $property->setAccessible(TRUE);
+
+        $this->assertNull($property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that timeout_seconds equals 60 by default
+     */
+    public function testTimeoutSecondsInitValue()
+    {
+        $property = $this->stream_socket_reflection->getProperty('timeout_seconds');
+        $property->setAccessible(TRUE);
+
+        $this->assertEquals(60, $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that timeout_micros equals 0 by default
+     */
+    public function testTimeoutMicrosEqualsZero()
+    {
+        $property = $this->stream_socket_reflection->getProperty('timeout_microseconds');
+        $property->setAccessible(TRUE);
+
+        $this->assertEquals(0, $property->getValue($this->stream_socket));
+    }
+
+}
+
+?>
\ No newline at end of file
diff --git a/tests/system/libraries/network/class.streamsocket.context.test.php b/tests/system/libraries/network/class.streamsocket.context.test.php
new file mode 100644
index 0000000000000000000000000000000000000000..884540f868f1978ba69be207cf5ef136f0f5561d
--- /dev/null
+++ b/tests/system/libraries/network/class.streamsocket.context.test.php
@@ -0,0 +1,137 @@
+<?php
+
+/**
+ * This file contains the StreamSocketExecuteTest class.
+ *
+ * PHP Version 5.3
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Tests
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ * @copyright  2012, M2Mobi BV, Amsterdam, The Netherlands
+ * @license    http://lunr.nl/LICENSE MIT License
+ */
+
+namespace Lunr\Libraries\Network;
+use PHPUnit_Framework_TestCase;
+use ReflectionClass;
+
+/**
+ * This class contains test methods for stream context of the StreamSocket class.
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Tests
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ * @covers     Lunr\Libraries\Network\StreamSocket
+ */
+class StreamSocketContextTest extends StreamSocketTest
+{
+
+    /**
+     * Tests that create_context() methods sets the stream context options
+     *
+     * @covers  Lunr\Libraries\Network\StreamSocket::create_context
+     */
+    public function testCreateContextSetsContextOptionsIfContextOptionsNotEmpty()
+    {
+        $property = $this->stream_socket_reflection->getProperty('context');
+        $property->setAccessible(TRUE);
+
+        $value = array( 'http' => array('method' => ' POST'));
+
+        $this->stream_socket->set_context_options($value);
+
+        $method = $this->stream_socket_reflection->getMethod('create_context');
+        $method->setAccessible(TRUE);
+
+        $method->invoke($this->stream_socket);
+
+        $options = stream_context_get_options($property->getValue($this->stream_socket));
+
+        $this->assertArrayHasKey('http', $options);
+        $this->assertEquals($value['http'], $options['http']);
+    }
+
+    /**
+     * Tests that create_context() methods sets nothing if no context options set.
+     *
+     * @covers  Lunr\Libraries\Network\StreamSocket::create_context
+     */
+    public function testCreateContextDoesNotSetContextOptionsIfContextOptionsEmpty()
+    {
+        $property = $this->stream_socket_reflection->getProperty('context');
+        $property->setAccessible(TRUE);
+
+        $method = $this->stream_socket_reflection->getMethod('create_context');
+        $method->setAccessible(TRUE);
+
+        $method->invoke($this->stream_socket);
+
+        $this->assertEmpty(stream_context_get_options($property->getValue($this->stream_socket)));
+    }
+
+    /**
+     * Tests that create_context() methods sets the notification callback method.
+     *
+     * @covers  Lunr\Libraries\Network\StreamSocket::create_context
+     */
+    public function testCreateContextSetsNotificationCallbackIfNotificationNotEmpty()
+    {
+        $property = $this->stream_socket_reflection->getProperty('context');
+        $property->setAccessible(TRUE);
+
+        $notification = 'notification';
+
+        $this->stream_socket->set_notification_callback($notification);
+
+        $method = $this->stream_socket_reflection->getMethod('create_context');
+        $method->setAccessible(TRUE);
+
+        $method->invoke($this->stream_socket);
+
+        $params = stream_context_get_params($property->getValue($this->stream_socket));
+
+        $this->assertArrayHasKey('notification', $params);
+        $this->assertEquals($notification, $params['notification']);
+    }
+
+    /**
+     * Tests that create_context() methods does not set notification callback method
+     * if notification is empty.
+     *
+     * @covers  Lunr\Libraries\Network\StreamSocket::create_context
+     */
+    public function testCreateContextDoesNotSetNotificationCallbackIfNotificationEmpty()
+    {
+        $property = $this->stream_socket_reflection->getProperty('context');
+        $property->setAccessible(TRUE);
+
+        $method = $this->stream_socket_reflection->getMethod('create_context');
+        $method->setAccessible(TRUE);
+
+        $method->invoke($this->stream_socket);
+
+        $this->assertArrayNotHasKey('notification', stream_context_get_params($property->getValue($this->stream_socket)));
+    }
+
+    /**
+     * Tests that create_context() method returns a context resource.
+     *
+     * @covers  Lunr\Libraries\Network\StreamSocket::create_context
+     */
+    public function testCreateContextReturnsResource()
+    {
+        $method = $this->stream_socket_reflection->getMethod('create_context');
+        $method->setAccessible(TRUE);
+
+        $return = $method->invoke($this->stream_socket);
+
+        $this->assertTrue(is_resource($return));
+        $this->assertEquals('stream-context', get_resource_type($return));
+    }
+
+}
+
+?>
diff --git a/tests/system/libraries/network/class.streamsocket.setget.test.php b/tests/system/libraries/network/class.streamsocket.setget.test.php
new file mode 100644
index 0000000000000000000000000000000000000000..6d848a1df6c86500fee79cb774c826090e509ce9
--- /dev/null
+++ b/tests/system/libraries/network/class.streamsocket.setget.test.php
@@ -0,0 +1,333 @@
+<?php
+
+/**
+ * This file contains the StreamSocketSetGetTest class.
+ *
+ * PHP Version 5.3
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Tests
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ * @copyright  2012, M2Mobi BV, Amsterdam, The Netherlands
+ * @license    http://lunr.nl/LICENSE MIT License
+ */
+
+namespace Lunr\Libraries\Network;
+use PHPUnit_Framework_TestCase;
+use ReflectionClass;
+
+/**
+ * This class contains test methods for the getters and setters of the StreamSocket class.
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Tests
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ * @covers     Lunr\Libraries\Network\StreamSocket
+ */
+class StreamSocketSetGetTest extends StreamSocketTest
+{
+
+    /**
+     * Tests that the value of valid properties can be retrieved correctly.
+     *
+     * @param String $property Property name
+     * @param mixed  $value    Property value
+     *
+     * @dataProvider validPropertyProvider
+     * @covers       Lunr\Libraries\Network\StreamSocket::__get
+     */
+    public function testGetReturnsValuesForValidProperties($property, $value)
+    {
+        $this->assertEquals($value, $this->stream_socket->$property);
+    }
+
+    /**
+     * Tests that the value of invalid properties is retrieved as NULL.
+     *
+     * @covers Lunr\Libraries\Network\StreamSocket::__get
+     */
+    public function testGetReturnsNullForInvalidProperties()
+    {
+        $this->assertNull($this->stream_socket->invalid_property);
+    }
+
+    /**
+     * Tests that the set_context_option() method sets properly the option
+     * in the correct wrapper with the proper value.
+     *
+     * @param array $wrapper The wrapper to set the option in
+     * @param array $option  The option to set within the wrapper
+     * @param mixed $value   The value of the set option
+     *
+     * @dataProvider validWrapperProvider
+     * @covers       Lunr\Libraries\Network\StreamSocket::set_context_option
+     */
+    public function testSetContextOptionWithValidWrapper($wrapper, $option, $value)
+    {
+        $property = $this->stream_socket_reflection->getProperty('context_options');
+        $property->setAccessible(TRUE);
+
+        $this->stream_socket->set_context_option($wrapper, $option, $value);
+
+        $context = $property->getValue($this->stream_socket);
+
+        $this->assertArrayHasKey($wrapper, $context);
+
+        $this->assertArrayHasKey($option, $context[$wrapper]);
+        $this->assertEquals($value, $context[$wrapper][$option]);
+    }
+
+    /**
+     * Tests that the context_options property is not modified if
+     * attempted to provide illegal or invalid wrapper
+     *
+     * @param array $wrapper The wrapper to set the option in
+     * @param array $option  The option to set within the wrapper
+     * @param mixed $value   The value of the set option
+     *
+     * @dataProvider invalidWrapperProvider
+     * @depends      Lunr\Libraries\Network\StreamSocketSetGetTest::testSetContextOptionWithValidWrapper
+     * @covers       Lunr\Libraries\Network\StreamSocket::set_context_option
+     */
+    public function testSetContextOptionWithInvalidWrapper($wrapper, $option, $value)
+    {
+        $property = $this->stream_socket_reflection->getProperty('context_options');
+        $property->setAccessible(TRUE);
+
+        $previous = $property->getValue($this->stream_socket);
+
+        $this->stream_socket->set_context_option($wrapper, $option, $value);
+
+        $this->assertEquals($previous, $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that the set_context_option() method sets properly the context option
+     * in the correct wrapper with the proper value.
+     *
+     * @depends Lunr\Libraries\Network\StreamSocketSetGetTest::testSetContextOptionWithValidWrapper
+     * @covers  Lunr\Libraries\Network\StreamSocket::set_context_options
+     */
+    public function testSetContextOptionsWithValidInput()
+    {
+        $options = array
+                   (
+                    'http' => array('method' => 'POST'),
+                    'ftp'  => array('overwrite' => FALSE),
+                    'tcp'  => array('bindto' => '127.0.0.1:4321'),
+                   );
+
+        $property = $this->stream_socket_reflection->getProperty('context_options');
+        $property->setAccessible(TRUE);
+
+        $this->stream_socket->set_context_options($options);
+
+        $context = $property->getValue($this->stream_socket);
+
+        foreach($options as $wrapper_key => $wrapper)
+        {
+            $this->assertArrayHasKey($wrapper_key, $context);
+
+            foreach($wrapper as $option => $value)
+            {
+                $this->assertArrayHasKey($option, $wrapper);
+                $this->assertEquals($value,$wrapper[$option]);
+            }
+        }
+    }
+
+    /**
+     * Tests that set_options() does not do anything if input is not an array
+     *
+     * @param mixed $value The non-array invalid input
+     *
+     * @dataProvider invalidOptionsProvider
+     * @covers       Lunr\Libraries\Network\StreamSocket::set_context_options
+     */
+    public function testSetContextOptionsIfInputIsNotArray($value)
+    {
+        $property = $this->stream_socket_reflection->getProperty('context_options');
+        $property->setAccessible(TRUE);
+
+        $previous = $property->getValue($this->stream_socket);
+
+        $this->stream_socket->set_context_options($value);
+
+        $this->assertEquals($previous, $property->getValue($this->stream_socket));
+    }
+
+
+    /**
+     * Tests that the blocking property is properly set with valid values.
+     *
+     * @param Boolean $value A valid value for blocking property
+     *
+     * @dataProvider validBlockingProvider
+     * @covers       Lunr\Libraries\Network\StreamSocket::set_blocking
+     */
+    public function testSetBlockingWithValidInput($value)
+    {
+        $property = $this->stream_socket_reflection->getProperty('blocking');
+        $property->setAccessible(TRUE);
+
+        $this->stream_socket->set_blocking($value);
+
+        $this->assertEquals($value, $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that blocking property is not modified if invalid input provided
+     *
+     * @param mixed $value A invalid value for blocking property
+     *
+     * @dataProvider invalidBlockingProvider
+     * @covers       Lunr\Libraries\Network\StreamSocket::set_blocking
+     */
+    public function testSetBlockingWithInvalidInput($value)
+    {
+        $property = $this->stream_socket_reflection->getProperty('blocking');
+        $property->setAccessible(TRUE);
+
+        $previous = $property->getValue($this->stream_socket);
+
+        $this->stream_socket->set_blocking($value);
+
+        $this->assertEquals($previous, $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that notification property is properly set
+     *
+     * @covers Lunr\Libraries\Network\StreamSocket::set_notification_callback
+     */
+    public function testSetNotificationCallBack()
+    {
+        $value = 'notification';
+
+        $property = $this->stream_socket_reflection->getProperty('notification');
+        $property->setAccessible(TRUE);
+
+        $this->stream_socket->set_notification_callback($value);
+
+        $this->assertEquals($value, $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that timeout_seconds is properly set with valid value
+     *
+     * @dataProvider validTimeoutProvider
+     * @covers       Lunr\Libraries\Network\StreamSocket::set_timeout_seconds
+     */
+    public function testSetTimeoutSecondsWithValidValue($value)
+    {
+        $property = $this->stream_socket_reflection->getProperty('timeout_seconds');
+        $property->setAccessible(TRUE);
+
+        $this->stream_socket->set_timeout_seconds($value);
+
+        $this->assertEquals($value, $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that timeout_microseconds is properly set with valid value
+     *
+     * @dataProvider validTimeoutProvider
+     * @covers       Lunr\Libraries\Network\StreamSocket::set_timeout_microseconds
+     */
+    public function testSetTimeoutMicrosecondsWithValidValue($value)
+    {
+        $property = $this->stream_socket_reflection->getProperty('timeout_microseconds');
+        $property->setAccessible(TRUE);
+
+        $this->stream_socket->set_timeout_microseconds($value);
+
+        $this->assertEquals($value, $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that timeout_seconds is not set with invalid value
+     *
+     * @dataProvider invalidTimeoutProvider
+     * @covers       Lunr\Libraries\Network\StreamSocket::set_timeout_seconds
+     */
+    public function testSetTimeoutSecondsWithInvalidValue($value)
+    {
+        $property = $this->stream_socket_reflection->getProperty('timeout_seconds');
+        $property->setAccessible(TRUE);
+
+        $this->stream_socket->set_timeout_seconds($value);
+
+        $this->assertFalse($value === $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Tests that timeout_microseconds is not set with invalid value
+     *
+     * @dataProvider invalidTimeoutProvider
+     * @covers       Lunr\Libraries\Network\StreamSocket::set_timeout_microseconds
+     */
+    public function testSetTimeoutMicrosecondsWithInvalidValue($value)
+    {
+        $property = $this->stream_socket_reflection->getProperty('timeout_microseconds');
+        $property->setAccessible(TRUE);
+
+        $this->stream_socket->set_timeout_microseconds($value);
+
+        $this->assertFalse($value === $property->getValue($this->stream_socket));
+    }
+
+    /**
+     * Test the fluid interface of the set_context_option() method.
+     *
+     * @covers Lunr\Libraries\Network\StreamSocket::set_context_option
+     */
+    public function testSetContextOptionReturnsSelfReference()
+    {
+        $return = $this->stream_socket->set_context_option('http', 'method', 'POST');
+
+        $this->assertEquals($return, $this->stream_socket);
+    }
+
+    /**
+     * Test the fluid interface of the set_context_options() method.
+     *
+     * @covers Lunr\Libraries\Network\StreamSocket::set_context_options
+     */
+    public function testSetContextOptionsReturnsSelfReference()
+    {
+        $value = array('http' => array('method' => 'POST'));
+
+        $return = $this->stream_socket->set_context_options($value);
+
+        $this->assertEquals($return, $this->stream_socket);
+    }
+
+    /**
+     * Test the fluid interface of the set_blocking() method.
+     *
+     * @covers Lunr\Libraries\Network\StreamSocket::set_blocking
+     */
+    public function testSetBlockingReturnsSelfReference()
+    {
+        $return = $this->stream_socket->set_blocking(0);
+
+        $this->assertEquals($return, $this->stream_socket);
+    }
+
+    /**
+     * Test the fluid interface of the set_notification_callback() method.
+     *
+     * @covers Lunr\Libraries\Network\StreamSocket::set_notification_callback
+     */
+    public function testSetNotificationCallbackReturnsSelfReference()
+    {
+        $return = $this->stream_socket->set_notification_callback('notification');
+
+        $this->assertEquals($return, $this->stream_socket);
+    }
+
+}
+
+?>
diff --git a/tests/system/libraries/network/class.streamsocket.state.test.php b/tests/system/libraries/network/class.streamsocket.state.test.php
new file mode 100644
index 0000000000000000000000000000000000000000..c1d66293ba369a9a945b8360750dac5af7ab13ed
--- /dev/null
+++ b/tests/system/libraries/network/class.streamsocket.state.test.php
@@ -0,0 +1,519 @@
+<?php
+
+/**
+ * This file contains the StreamSocketStateTest class.
+ *
+ * PHP Version 5.3
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Tests
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ * @copyright  2012, M2Mobi BV, Amsterdam, The Netherlands
+ * @license    http://lunr.nl/LICENSE MIT License
+ */
+
+namespace Lunr\Libraries\Network;
+use PHPUnit_Framework_TestCase;
+use ReflectionClass;
+
+/**
+ * This class contains test methods for state change StreamSocket class.
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Tests
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ * @covers     Lunr\Libraries\Network\StreamSocket
+ */
+class StreamSocketStateTest extends StreamSocketTest
+{
+    /**
+     * Tests that changed() method returns TRUE if the stream can be read.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @covers  Lunr\Libraries\Network\StreamSocket::changed
+     */
+    public function testChangedReturnsTrueOnReadWatchOfTheStreamIfChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ONE);
+
+        $method = $this->stream_socket_reflection->getMethod('changed');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(TRUE, FALSE, FALSE));
+
+        $this->assertTrue($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that changed() method returns FALSE if the stream cannot be read.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @covers  Lunr\Libraries\Network\StreamSocket::changed
+     */
+    public function testChangedReturnsFalseOnReadWatchOfTheStreamIfNotChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ZERO);
+
+        $method = $this->stream_socket_reflection->getMethod('changed');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(TRUE, FALSE, FALSE));
+
+        $this->assertFalse($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that changed() method returns NULL if error occurs
+     * while watching read availability of the stream.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @covers  Lunr\Libraries\Network\StreamSocket::changed
+     */
+    public function testChangedReturnsNullOnReadWatchOfTheStreamIfError()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_FALSE);
+
+        $method = $this->stream_socket_reflection->getMethod('changed');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(TRUE, FALSE, FALSE));
+
+        $this->assertNull($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that changed() method returns TRUE if the stream can be written.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @covers  Lunr\Libraries\Network\StreamSocket::changed
+     */
+    public function testChangedReturnsTrueOnWriteWatchOfTheStreamIfChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ONE);
+
+        $method = $this->stream_socket_reflection->getMethod('changed');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(FALSE, TRUE, FALSE));
+
+        $this->assertTrue($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that changed() method returns FALSE if the stream cannot be written.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @covers  Lunr\Libraries\Network\StreamSocket::changed
+     */
+    public function testChangedReturnsFalseOnWriteWatchOfTheStreamIfNotChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ZERO);
+
+        $method = $this->stream_socket_reflection->getMethod('changed');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(FALSE, TRUE, FALSE));
+
+        $this->assertFalse($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that changed() method returns NULL if error occurs
+     * while watching write availability of the stream.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @covers  Lunr\Libraries\Network\StreamSocket::changed
+     */
+    public function testChangedReturnsNullOnWriteWatchOfTheStreamIfError()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_FALSE);
+
+        $method = $this->stream_socket_reflection->getMethod('changed');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(FALSE, TRUE, FALSE));
+
+        $this->assertNull($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that changed() method returns TRUE if the stream has thrown an exception.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @covers  Lunr\Libraries\Network\StreamSocket::changed
+     */
+    public function testChangedReturnsTrueOnExceptionWatchOfTheStreamIfChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ONE);
+
+        $method = $this->stream_socket_reflection->getMethod('changed');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(FALSE, FALSE, TRUE));
+
+        $this->assertTrue($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that changed() method returns FALSE if the stream has not thrown an exception.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @covers  Lunr\Libraries\Network\StreamSocket::changed
+     */
+    public function testChangedReturnsFalseOnExceptionWatchOfTheStreamIfNotChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ZERO);
+
+        $method = $this->stream_socket_reflection->getMethod('changed');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(FALSE, FALSE, TRUE));
+
+        $this->assertFalse($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that changed() method returns NULL if error occurs
+     * while watching exception purpose of the stream.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @covers  Lunr\Libraries\Network\StreamSocket::changed
+     */
+    public function testChangedReturnsNullOnexceptionWatchOfTheStreamIfError()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_FALSE);
+
+        $method = $this->stream_socket_reflection->getMethod('changed');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(FALSE, FALSE, TRUE));
+
+        $this->assertNull($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that changed() method returns NULL if stream is not open
+     * for all type of watch.
+     *
+     * @covers  Lunr\Libraries\Network\StreamSocket::changed
+     */
+    public function testChangedReturnsNullIfStreamNotOpened()
+    {
+        $method = $this->stream_socket_reflection->getMethod('changed');
+        $method->setAccessible(TRUE);
+
+        $return = $method->invokeArgs($this->stream_socket, array(TRUE, FALSE, FALSE));
+        $this->assertNull($return);
+
+        $return = $method->invokeArgs($this->stream_socket, array(FALSE, TRUE, FALSE));
+        $this->assertNull($return);
+
+        $return = $method->invokeArgs($this->stream_socket, array(FALSE, FALSE, TRUE));
+        $this->assertNull($return);
+    }
+
+    /**
+     * Tests that is_readable() returns TRUE if the stream can be read.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @depends Lunr\Libraries\Network\StreamSocketStateTest::testChangedReturnsTrueOnReadWatchOfTheStreamIfChanged
+     * @covers  Lunr\Libraries\Network\StreamSocket::is_readable
+     */
+    public function testIsReadableReturnsTrueIfStreamChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ONE);
+
+        $method = $this->stream_socket_reflection->getMethod('is_readable');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invoke($this->stream_socket);
+
+        $this->assertTrue($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that is_readable() method returns FALSE if the stream cannot be read.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @depends Lunr\Libraries\Network\StreamSocketStateTest::testChangedReturnsFalseOnReadWatchOfTheStreamIfNotChanged
+     * @covers  Lunr\Libraries\Network\StreamSocket::is_readable
+     */
+    public function testIsReadableReturnsFalseIfStreamNotChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ZERO);
+
+        $method = $this->stream_socket_reflection->getMethod('is_readable');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invoke($this->stream_socket);
+
+        $this->assertFalse($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that is_readable() method returns NULL if error occurs
+     * while watching read availability of the stream.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @depends Lunr\Libraries\Network\StreamSocketStateTest::testChangedReturnsNullOnReadWatchOfTheStreamIfError
+     * @covers  Lunr\Libraries\Network\StreamSocket::is_readable
+     */
+    public function testIsReadableReturnsNullIfError()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_FALSE);
+
+        $method = $this->stream_socket_reflection->getMethod('is_readable');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invoke($this->stream_socket);
+
+        $this->assertNull($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that is_writable() method returns TRUE if the stream can be written.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @depends Lunr\Libraries\Network\StreamSocketStateTest::testChangedReturnsTrueOnWriteWatchOfTheStreamIfChanged
+     * @covers  Lunr\Libraries\Network\StreamSocket::is_writable
+     */
+    public function testIsWritableReturnsTrueIfStreamChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ONE);
+
+        $method = $this->stream_socket_reflection->getMethod('is_writable');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invoke($this->stream_socket);
+
+        $this->assertTrue($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that is_writable() method returns FALSE if the stream cannot be written.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @depends Lunr\Libraries\Network\StreamSocketStateTest::testChangedReturnsFalseOnWriteWatchOfTheStreamIfNotChanged
+     * @covers  Lunr\Libraries\Network\StreamSocket::is_writable
+     */
+    public function testIsWritableReturnsFalseIfStreamNotChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ZERO);
+
+        $method = $this->stream_socket_reflection->getMethod('is_writable');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invoke($this->stream_socket);
+
+        $this->assertFalse($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that is_writable() method returns NULL if error occurs
+     * while watching write availability of the stream.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @depends Lunr\Libraries\Network\StreamSocketStateTest::testChangedReturnsNullOnWriteWatchOfTheStreamIfError
+     * @covers  Lunr\Libraries\Network\StreamSocket::is_writable
+     */
+    public function testIsWritableReturnsNullIfError()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_FALSE);
+
+        $method = $this->stream_socket_reflection->getMethod('is_writable');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invoke($this->stream_socket);
+
+        $this->assertNull($return);
+
+        unlink('./test.txt');
+    }
+    /*--------------------------------------------------------------------------------------------------------------------------*/
+    /**
+     * Tests that is_exception_thrown() method returns TRUE if the stream has thrown an exception.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @depends Lunr\Libraries\Network\StreamSocketStateTest::testChangedReturnsTrueOnExceptionWatchOfTheStreamIfChanged
+     * @covers  Lunr\Libraries\Network\StreamSocket::is_exception_thrown
+     */
+    public function testIsExceptionThrownReturnsTrueIfStreamChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ONE);
+
+        $method = $this->stream_socket_reflection->getMethod('is_exception_thrown');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(FALSE, FALSE, TRUE));
+
+        $this->assertTrue($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that is_exception_thrown() method returns FALSE if the stream has not thrown an exception.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @depends Lunr\Libraries\Network\StreamSocketStateTest::testChangedReturnsFalseOnExceptionWatchOfTheStreamIfNotChanged
+     * @covers  Lunr\Libraries\Network\StreamSocket::is_exception_thrown
+     */
+    public function testIsExceptionThrownReturnsFalseIfStreamNotChanged()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_ZERO);
+
+        $method = $this->stream_socket_reflection->getMethod('is_exception_thrown');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(FALSE, FALSE, TRUE));
+
+        $this->assertFalse($return);
+
+        unlink('./test.txt');
+    }
+
+    /**
+     * Tests that is_exception_thrown() method returns NULL if error occurs
+     * while watching exception purpose of the stream.
+     *
+     * @depends Lunr\EnvironmentTest::testRunkit
+     * @depends Lunr\Libraries\Network\StreamSocketStateTest::testChangedReturnsNullOnexceptionWatchOfTheStreamIfError
+     * @covers  Lunr\Libraries\Network\StreamSocket::is_exception_thrown
+     */
+    public function testIsExceptionThrownReturnsNullIfError()
+    {
+        runkit_function_redefine('stream_select', '', self::STREAM_SOCKET_RETURN_FALSE);
+
+        $method = $this->stream_socket_reflection->getMethod('is_exception_thrown');
+        $method->setAccessible(TRUE);
+
+        $property = $this->stream_socket_reflection->getProperty('handle');
+        $property->setAccessible(TRUE);
+        //to prevent the method to try to create the handle
+        $property->setValue($this->stream_socket, fopen('./test.txt', 'a'));
+
+        $return = $method->invokeArgs($this->stream_socket, array(FALSE, FALSE, TRUE));
+
+        $this->assertNull($return);
+
+        unlink('./test.txt');
+    }
+
+}
+
+?>
\ No newline at end of file
diff --git a/tests/system/libraries/network/class.streamsocket.test.php b/tests/system/libraries/network/class.streamsocket.test.php
new file mode 100644
index 0000000000000000000000000000000000000000..f4475575e044fdd2276a1dfeb0a0feda16202d84
--- /dev/null
+++ b/tests/system/libraries/network/class.streamsocket.test.php
@@ -0,0 +1,233 @@
+<?php
+/**
+ * This file contains the StreamSocketTest class.
+ *
+ * PHP Version 5.3
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Tests
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ * @copyright  2012, M2Mobi BV, Amsterdam, The Netherlands
+ * @license    http://lunr.nl/LICENSE MIT License
+ */
+
+namespace Lunr\Libraries\Network;
+use PHPUnit_Framework_TestCase;
+use ReflectionClass;
+
+/**
+ * This class contains test methods for the StreamSocket class.
+ *
+ * @category   Libraries
+ * @package    Network
+ * @subpackage Tests
+ * @author     Olivier Wizen <olivier@m2mobi.com>
+ * @covers     Lunr\Libraries\Network\StreamSocket
+ */
+abstract class StreamSocketTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * Instance of the StreamSocket class.
+     * @var StreamSocket
+     */
+    protected $stream_socket;
+
+    /**
+     * Reflection instance of the StreamSocket class.
+     * @var ReflectionClass
+     */
+    protected $stream_socket_reflection;
+
+    /**
+     * Runkit simulation code for returning FALSE.
+     * @var string
+     */
+    const STREAM_SOCKET_RETURN_FALSE = 'return FALSE;';
+
+    /**
+     * Runkit simulation code for returning TRUE.
+     * @var string
+     */
+    const STREAM_SOCKET_RETURN_TRUE = 'return TRUE;';
+
+    /**
+     * Runkit simulation code for returning NULL.
+     * @var string
+     */
+    const STREAM_SOCKET_RETURN_NULL = 'return NULL;';
+
+    /**
+     * Runkit simulation code for returning 1.
+     * @var string
+     */
+    const STREAM_SOCKET_RETURN_ONE = 'return 1;';
+
+    /**
+     * Runkit simulation code for returning 0.
+     * @var string
+     */
+    const STREAM_SOCKET_RETURN_ZERO = 'return 0;';
+
+    /**
+     * TestCase Constructor.
+     */
+    public function setUp()
+    {
+        $this->stream_socket_reflection = new ReflectionClass('Lunr\Libraries\Network\StreamSocket');
+
+        $this->stream_socket = $this->getMockForAbstractClass('Lunr\Libraries\Network\StreamSocket');
+    }
+
+    /**
+     * TestCase Destructor.
+     */
+    public function tearDown()
+    {
+        unset($this->stream_socket_reflection);
+        unset($this->stream_socket);
+    }
+
+    /**
+     * Unit Test Data Provider for valid property values.
+     *
+     * @return array $properties Array of valid properties of the StreamSocket class
+     */
+    public function validPropertyProvider()
+    {
+        $properties   = array();
+        $properties[] = array('errno', 0);
+        $properties[] = array('errmsg', '');
+        $properties[] = array('meta_data', array());
+
+        return $properties;
+    }
+
+
+    /**
+     * Unit Test data Provider for valid wrapper values.
+     *
+     * @return array $wrappers Array of valid wrappers of the stream socket class
+     *                         with option and value
+     */
+    public function validWrapperProvider()
+    {
+        $wrappers   = array();
+        $wrappers[] = array('http', 'method'   , 'POST');
+        $wrappers[] = array('ftp' , 'overwrite', FALSE);
+        $wrappers[] = array('tcp' , 'bla', '127.0.0.1:4321');
+
+        return $wrappers;
+    }
+
+    /**
+     * Unit Test Data Provider for valid wrapper values.
+     *
+     * @return array $wrappers Array of valid wrappers of the stream socket class
+     *                         with option and value
+     */
+    public function invalidWrapperProvider()
+    {
+        $wrappers   = array();
+        $wrappers[] = array('beuh', 'method'   , 'POST');
+        $wrappers[] = array('hein' , 'overwrite', FALSE);
+        $wrappers[] = array('quoi' , 'bla', '127.0.0.1:4321');
+        $wrappers[] = array(1 , 1, 1);
+        $wrappers[] = array(0 , 1, 1);
+        $wrappers[] = array(TRUE , 'TRUE', 'TRUE');
+        $wrappers[] = array(FALSE , 'FALSE', 'FALSE');
+        $wrappers[] = array(NULL , 'NULL', 'NULL');
+
+        return $wrappers;
+    }
+
+    /**
+     * Unit Test Data Provider for invalid context options values.
+     *
+     * @return array $options The invalid options values
+     */
+    public function invalidOptionsProvider()
+    {
+        $option    = array();
+        $options[] = array('str');
+        $options[] = array(0);
+        $options[] = array(1);
+        $options[] = array(-1);
+        $options[] = array(37);
+        $options[] = array(NULL);
+        $options[] = array(FALSE);
+        $options[] = array(TRUE);
+
+        return $options;
+    }
+
+    /**
+     * Unit Test Data Povider for valid blocking values
+     */
+    public function validBlockingProvider()
+    {
+        $blockings   = array() ;
+        $blockings[] = array(TRUE);
+        $blockings[] = array(FALSE);
+
+        return $blockings;
+    }
+
+    /**
+     * Unit Test Data Povider for invalid blocking values
+     */
+    public function invalidBlockingProvider()
+    {
+        $blockings   = array() ;
+        $blockings[] = array(0);
+        $blockings[] = array(1);
+        $blockings[] = array(-1);
+        $blockings[] = array(2);
+        $blockings[] = array(1000);
+        $blockings[] = array(39);
+        $blockings[] = array('1');
+        $blockings[] = array('str');
+        $blockings[] = array(0.5);
+        $blockings[] = array(3.9);
+        $blockings[] = array(-4.7);
+        $blockings[] = array(NULL);
+
+        return $blockings;
+    }
+
+    /**
+     * Unit Test Data Provider for valid timeout values
+     */
+    public function validTimeoutProvider()
+    {
+        $timeouts  = array();
+        $timeouts[] = array(0);
+        $timeouts[] = array(1);
+        $timeouts[] = array(10);
+        $timeouts[] = array(100);
+        $timeouts[] = array(1000);
+
+        return $timeouts;
+    }
+
+    /**
+     * Unit Test Data Provider for invalid timeout values
+     */
+    public function invalidTimeoutProvider()
+    {
+        $timeouts  = array();
+        $timeouts[] = array("0");
+        $timeouts[] = array(-1);
+        $timeouts[] = array(-10);
+        $timeouts[] = array("100");
+        $timeouts[] = array(26.87);
+        $timeouts[] = array(NULL);
+        $timeouts[] = array(FALSE);
+        $timeouts[] = array(TRUE);
+
+        return $timeouts;
+    }
+
+}
+
+?>
\ No newline at end of file
