diff --git a/apachesolr.info b/apachesolr.info
index b398e11..7aa3f95 100644
--- a/apachesolr.info
+++ b/apachesolr.info
@@ -22,3 +22,4 @@ files[] = tests/solr_index_and_search.test
 files[] = tests/solr_base_query.test
 files[] = tests/solr_base_subquery.test
 files[] = tests/solr_document.test
+files[] = tests/apachesolr_entityapi.test
diff --git a/tests/Dummy_Solr.php b/tests/Dummy_Solr.php
index fbd8566..b8fdb59 100644
--- a/tests/Dummy_Solr.php
+++ b/tests/Dummy_Solr.php
@@ -239,3 +239,137 @@ class DummySolr {
   }
 }
 
+/**
+ * Mock class. This can be used to replace an object for the purposes
+ * of a unit test. Functions called on this object can be inspected
+ * in the Unit test to see if they are expected.
+ */
+class Mock {
+
+  /**
+   * @var array $functions_called
+   *   An array of functions which were called on this mock object keyed
+   *   with int in the order the functions were called.
+   */
+  public $functions_called = array();
+
+  /**
+   * @var array $functions_called_by_name
+   *   An array of functions which were called on this mock object
+   *   this time keyed by the name of the function. Each element
+   *   is an array of each time the function was called with its
+   *   values the arguments used.
+   */
+  public $functions_called_by_name = array();
+
+  /**
+   * @var array $expects
+   *   An array of functions expected to be run on the Mock.
+   *   Each key is the mock function name and the value is
+   *   an array of return values, one for each call to the function
+   *   in the order that the function gets called.
+   */
+  public $expects = array();
+
+  /**
+   * This captures all function calls on the mock object. The
+   * name of the function called is recorded for future checking
+   * during the unit test. If the function is expected to return
+   * a value or throw an exception, or execute a callback
+   * then this will then happen.
+   */
+  public function __call($name, $arguments) {
+    // Find out how many times this function has been called.
+    $function_call_count = isset($this->functions_called_by_name[$name]) ? count($this->functions_called_by_name[$name]) : 0;
+
+    // Log that the function was called.
+    $this->functions_called[] = array('name' => $name, 'arguments' => $arguments);
+    $this->functions_called_by_name[$name][] = $arguments;
+
+    // See if there is a return for this function.
+    if (isset($this->expects[$name]) && isset($this->expects[$name][$function_call_count])) {
+      $return = $this->expects[$name][$function_call_count];
+      if ($return instanceof Exception) {
+        // The return is an Exception so throw it.
+        throw $return;
+      }
+      if (is_callable($return)) {
+        // The return is a callback, execute it with the functions parameters.
+        return call_user_func_array($return, $arguments);
+      }
+      // The return is just a function.
+      return $return;
+    }
+    else {
+      // The call to this function was not expected, return NULL.
+      return NULL;
+    }
+  }
+
+  /**
+   * Set a return value for a specified function.
+   *
+   * @param string $name
+   *   The name of the function that when called on this mock object
+   *   will return a specified value.
+   * @param mixed $value
+   *   The value which the function will return or a callback function
+   *   which will be run when the Mock function is called.
+   *
+   * @return Mock
+   *   A reference to this mock object.
+   */
+  public function returns($name, $value) {
+    return $this->expects($name, $value);
+  }
+
+  /**
+   * Set an exception to be thrown when a specified function is called.
+   *
+   * @param string $name
+   *   The name of the function that when called on this mock object
+   *   will throw the specified exception.
+   * @param Exception $exception
+   *   The exception which will be thrown when the function is called.
+   *
+   * @return Mock
+   *   A reference to this mock object.
+   */
+  public function throws($name, Exception $exception) {
+    return $this->expects($name, $exception);
+  }
+
+  /**
+   * Set an expected function to be called on the mock object
+   * and specify it's return value.
+   *
+   * @param string $name
+   *   The name of the function that when called on this mock object
+   * @param mixed $result
+   *   What the function will return when called.
+   *   If this is an Exception, it will be thrown when called.
+   *   If this is a callback function, it will be run when the
+   *   function is called with the arguments sent to the Mock
+   *   function.
+   *   If it is anything else, it will be retuned by the Mock
+   *   function.
+   *
+   * @return Mock
+   *   A reference to this mock object.
+   */
+  public function expects($name, $result = NULL) {
+    $this->expects[$name][] = $result;
+    return $this;
+  }
+
+  /**
+   * Reset this mock object for reuse in another test.
+   */
+  public function mockReset() {
+    $this->functions_called = array();
+    $this->functions_called_by_name = array();
+    $this->expects = array();
+    return $this;
+  }
+
+}
