title: PHPUnit 4.8 Mock mysql database interface
body: <p>Good afternoon,</p>
  
  <p>I have a bunch of legacy code that uses the old <code>mysql</code> library (<code>mysql_query($sql)</code> for example) and am trying to test it with PHPUnit (4.8 is the latest that will run on the server for various reasons). </p>
  
  <p>Does anyone know how to mock this database connection so that it can return predetermined results when predetermined queries are run? I have tried using getConnection() (as per the docs here: <a href="http://devdocs.io/phpunit~4/database" rel="nofollow noreferrer">http://devdocs.io/phpunit~4/database</a>) to no avail.</p>
  
  <p>For example I have this class:</p>
  
  <pre><code>class Raffle {
      ...
      public static function loadAll($filter=""){
          //$filter = mysql_real_escape_string($filter); // protect against SQL injection
          $raffles = []; // the array to return
  
          $sql = "SELECT * FROM raffles $filter;"; // include the user filter in the query
          $query = mysql_query($sql);
  
          //echo mysql_error();
  
          while($row = mysql_fetch_assoc($query)){
              $raffles[] = Raffle::loadFromRow($row); // generate the raffe instance and add it to the array
          }
          return $raffles; // return the array
      }
      ...
  }
  </code></pre>
  
  <p>(The <code>mysql_connect()</code> call is done in a file called <code>db.php</code> which is loaded on every page that it is needed and not in the class file itself.)</p>
  
  <p>Thanks in advance.</p>