Commits

Thomas Weinert  committed d8661cf

Code Cleanup, fix execptions, fix Deferred\MySQL tests

  • Participants
  • Parent commits e9df078

Comments (0)

Files changed (9)

File src/Carica/Io/Deferred/MySQL.php

 
     use Event\Loop\Aggregation;
 
+    /**
+     * @var \mysqli
+     */
     private $_mysqli = NULL;
 
     public function __construct($mysqli) {

File src/Carica/Io/Event/Emitter.php

     public function removeListener($event, $listener) {
       if (isset($this->_events[$event])) {
         foreach ($this->_events[$event] as $key => $eventListener) {
+          /**
+           * @var Emitter\Listener $eventListener
+           */
           if ($eventListener === $listener || $eventListener->getCallback() == $listener) {
             unset($this->_events[$event][$key]);
           }

File src/Carica/Io/Event/Loop.php

 
   use Carica\Io;
 
-  interface Loop {
+  interface Loop extends \Countable {
 
     function setTimeout(Callable $callback, $milliseconds);
 

File src/Carica/Io/Network/Http/Request/Query.php

 
     public function offsetSet($name, $value) {
       if (empty($name)) {
-        throw \InvalidArgumentException('Query string parameter name can not be empty.');
+        throw new \InvalidArgumentException('Query string parameter name can not be empty.');
       }
       $this->_data[$name] = $value;
     }

File src/Carica/Io/Network/Http/Response.php

   use Carica\Io;
 
   /**
+   * An HTTP response encapsulation to answer the request. It does no contain the
+   * content but the general data.
+   *
    * @property string $version
    * @property integer $status
-   * @property Connection $connection
    * @property Headers $headers
    * @property Response\Content $content
+   * @property Connection $connection
    */
   class Response {
 
-    public $_version = '1.0';
+    private $_version = '1.0';
 
     private $_status = 200;
 
       if (in_array($version, array('1.0', '1.1'))) {
         $this->_version = $version;
       } else {
-        throw \InvalidArgumentException(
+        throw new \InvalidArgumentException(
           sprintf('Invalid http version string %s', $version)
         );
       }
       if (isset($this->_statusStrings[$status])) {
         $this->_status = $status;
       } else {
-        throw \InvalidArgumentException(
+        throw new \InvalidArgumentException(
           sprintf('Invalid http status code %d', $status)
         );
       }

File src/Carica/Io/Network/Http/Response/Content/Html.php

   use Carica\Io\Network;
   use Carica\Io\Network\Http\Response;
 
-  /**
-   * @property \DOMDocument $document
-   */
-  class Html extends Response\Content {
-
-    private $_document = NULL;
+  class Html extends Dom {
 
     public function __construct($type = 'text/html; charset=utf-8') {
       parent::__construct($type);
-      $this->_document = new \DOMDocument('1.0', 'utf-8');
-    }
-
-    public function __get($name) {
-      switch ($name) {
-      case 'document' :
-        return $this->{'_'.$name};
-      }
-      return parent::__get($name);
     }
 
     public function sendTo(Network\Connection $connection) {
-      $connection->write($this->_document->saveHtml());
+      $connection->write($this->document->saveHtml());
       return TRUE;
     }
 
     public function getLength() {
-      return strlen($this->_document->saveXml());
+      return strlen($this->document->saveXml());
     }
   }
 }

File src/Carica/Io/Network/Http/Response/Content/Xml.php

   use Carica\Io\Network\Http\Response;
 
   /**
+   * An xml response content
+   *
    * @property \DOMDocument $document
    */
-  class Xml extends Response\Content {
-
-    private $_document = NULL;
+  class Xml extends Dom {
 
     public function __construct($type = 'application/xml; charset=utf-8') {
       parent::__construct($type);
-      $this->_document = new \DOMDocument('1.0', 'utf-8');
-    }
-
-    public function __get($name) {
-      switch ($name) {
-      case 'document' :
-        return $this->{'_'.$name};
-      }
-      return parent::__get($name);
     }
 
     public function sendTo(Network\Connection $connection) {
-      $connection->write($this->_document->saveXml());
+      $connection->write($this->document->saveXml());
       return TRUE;
     }
 
     public function getLength() {
-      return strlen($this->_document->saveXml());
+      return strlen($this->document->saveXml());
     }
   }
 }

File src/Carica/Io/Network/Http/Route/File.php

       return call_user_func_array(array($this, 'call'), func_get_args());
     }
 
-    public function call(Http\Request $request, array $parameters) {
+    public function call(Http\Request $request) {
       if ($file = $this->getFileInfo($request)) {
         if ($file->isFile() && $file->isReadable()) {
           $response = $request->createResponse();

File tests/Carica/Io/Deferred/MySQLTest.php

     }
 
     public function getMySQLConnectionFixture($result = FALSE) {
+      // seems that mysqli is not completly mockable, we use a pseudo class
       $mysqli = $this
-        ->getMockBuilder('Carica\Io\Deferred\MySQL')
+        ->getMockBuilder('mysqli_just_for_mocking')
         ->disableOriginalConstructor()
         ->setMethods(array('query', 'poll', 'reap_async_query'))
         ->getMock();
           0
         )
         ->will($this->returnValue(TRUE));
-      if ($result) {
-        $mysqli
-          ->expects($this->once())
-          ->method('reap_async_query')
-          ->will($this->returnValue($result));
-      }
+      $mysqli
+        ->expects($this->once())
+        ->method('reap_async_query')
+        ->will($this->returnValue($result));
       return $mysqli;
     }
   }