title: PHPUnit testing a protected static method that uses pdo
body: <p>I am very new to TDD.  I am using phpunit 7.4x-dev.  I have the following abstract class that I am trying to develop unit tests for.</p>
  
  <pre><code>use PDO;
  
  abstract class Model {
  
      protected static function getDB() {
          static $db = null;
          if ($db === null) {
  
                  $db = new PDO(ConfigDatabase::DSN, ConfigDatabase::USER, ConfigDatabase::PASSWORD);
                  $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
          }
          return $db;
      }
  
  
  }
  </code></pre>
  
  <p>I have created the following test to get around the need to deal with the static protected method. And it works if I provide "ConfigureDatabase" class.  </p>
  
  <pre><code>use PHPUnit\Framework\TestCase;
  
  class ModelTest extends TestCase {
  
      function newMockClass(){
          $stub = new class() extends Model{
              function getStaticMethod($methodName){
                  return self::$methodName();
              }
          };        
          return $stub;
  
      }
  
      public function testDatabaseExists() {
           $stub = $this-&gt;newMockClass();
           $db = $stub-&gt;getStaticMethod('getDB');
           $this-&gt;assertInstanceOf(PDO::class,$db);         
      }
  
  }
  </code></pre>
  
  <p>Since I do not want my tests to rely on any actual database, How would I fake the calls to PDO.</p>