title: PHPUnit - How to instantiate my pdo class in PHPUnit_Framework_TestCase?
body: <p>How can I instantiate my pdo class in PHPUnit_Framework_TestCase?</p>
  
  <p>for instance, this is my <code>\test\SuitTest.php</code>,</p>
  
  <pre><code>namespace Test;
  
  use PHPUnit_Framework_TestCase;
  
  class SuiteTest extends PHPUnit_Framework_TestCase
  {
      protected $PDO = null;
  
      public function __construct()
      {
          parent::__construct();
          $this-&gt;PDO = new \Foo\Adaptor\PdoAdaptor(); // the pdo is not instantiated at all - I think!
      }
  
      protected function truncateTables ($tables)
      {
          foreach ($tables as $table) {
              $this-&gt;PDO-&gt;truncateTable($table);
          }
      }
  
      /**
       * DO NOT DELETE, REQUIRED TO AVOID FAILURE OF NO TESTS IN FILE
       * PHPUnit is ignoring the exclude in the phpunit.xml config file
       */
      public function testDummyTest()
      {
      }
  }
  </code></pre>
  
  <p>I want to use the pdo class that I use it for development and production, which is in, <code>\app\source\Adaptor\PdoAdaptor.php</code>,</p>
  
  <pre><code>&lt;?php
  
  namespace Foo\Adaptor;
  
  use PDO;
  
  class PdoAdaptor
  {
      protected $PDO = null;
      protected $dsn = 'mysql:host=localhost;dbname=phpunit', $username = 'root', $password = 'xxxx';
  
      /*
       * Make the pdo connection.
       * @return object $PDO
       */
      public function connect()
      {
          try {
              $this-&gt;PDO = new PDO($this-&gt;dsn, $this-&gt;username, $this-&gt;password, array(PDO::MYSQL_ATTR_INIT_COMMAND =&gt; "SET NAMES utf8"));
              $this-&gt;PDO-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
              // Unset props.
              unset($this-&gt;dsn);
              unset($this-&gt;username);
              unset($this-&gt;password);
          } catch (PDOException $error) {
              // Call the getError function
              $this-&gt;getError($error);
          }
      }
  
      public function truncateTable($table)
      {
          $sql = "TRUNCATE TABLE $table";
          $command = $this-&gt;PDO-&gt;prepare($sql);
          $command-&gt;execute();
      }
  }
  </code></pre>
  
  <p>I get this error when I run <code>phpunit</code> for testing my codes,</p>
  
  <blockquote>
    <p>Fatal error: Call to a member function prepare() on null</p>
  </blockquote>
  
  <p>The pdo is not instantiated at all inside the <code>construct</code> method in <code>SuiteTes</code>t - I think!</p>
  
  <p>This is my dir structure,</p>
  
  <p><img src="https://i.stack.imgur.com/1XFkc.png" alt="enter image description here"></p>