title: phpunit setup class testing
body: <p>I have an abstract class:</p>
  
  <pre><code>abstract class Base {
      /**
       * @var \PDO
       */
      protected $_dbh;
      protected $_logFile;
  
      public function __construct($dbh, $logFile) {
          $this-&gt;_dbh = $dbh;
          $this-&gt;_logFile = $logFile;
      }
  }
  
  .............
  
  class bbb extends Base {
  
  
  public function smth() {
      $this-&gt;_addTracToDB([....]);
  }
  
  private function _addTracToDB($data) {
      $sql = "INSERT INTO table1 (t_time, t_priority)
              VALUES(:t_time, :t_priority)";
  
      $query = $this-&gt;_dbh-&gt;prepare($sql);
      $query-&gt;execute([
          ':t_time' =&gt; $data['timestamp'],
          ':t_priority' =&gt; $data['priority'],
      ]);
  }
  
  public function smth2() {
      $sql = 'selct * from table2';
      $query = $this-&gt;_dbh-&gt;query($sql);
          return $query-&gt;fetchAll();
  }
  
  }
  </code></pre>
  
  <p>Tan i try to test it with:</p>
  
  <pre><code>class mockPDO extends \PDO
  {
      public function __construct ()
      {}
  
  }
  
  class ChinaBaseTest extends DbTestAbstract {
      protected $pdo;
  
      protected function setUp() {
          $this-&gt;pdo = $this-&gt;getMock('mockPDO', array('query'), array('sqlite:memory')); // *&lt;-- error here*
  //      $this-&gt;pdo-&gt;expects($this-&gt;any())
  //          -&gt;method('query')
  //          -&gt;will($this-&gt;returnValue(new \PDOStatement()));
          $this-&gt;pdo-&gt;expects($this-&gt;any())
              -&gt;method('prepare')
              -&gt;will($this-&gt;returnValue(new \PDOStatement()));
  
  //      $foo-&gt;query('SELECT * FROM users;'); // instantiated PDOStatement class will be returned
  //      var_dump($foo-&gt;getAvailableDrivers()); // take note that methods originally declared in PDO class is available too
  
          $tableNames = array('guestbook');
          $dataSet = $this-&gt;getConnection()-&gt;createDataSet($tableNames);
      }
  
      protected function getDataSet() {
          return $this-&gt;createFlatXmlDataSet(__DIR__ . '/_data/myFlatXmlFixture.xml');
      }
  
      protected function _getDataFile($fileName) {
          return file_get_contents(__DIR__ . '/_data/' . $fileName);
      }
  
      public function testParseSingle() {
          $bbb  = new bbb ($this-&gt;pdo, LOG_DIR . 'common.log');
          $result = $bbb-&gt;smth($this-&gt;_getDataFile('787.log'));
          $this-&gt;assertEquals(1, count($result));
          $this-&gt;assertArrayHasKey(0, $result);
          $result = $result[0];
  
          $this-&gt;assertEquals(mktime(11, 39, 24, 9, 10, 2014), $result['timestamp']);
          ......
      }
  
  
  }
  </code></pre>
  
  <p>But receivean error:</p>
  
  <pre><code>ReflectionException : Class Mock_mockPDO_b630d3bd does not have a constructor, so you cannot pass any constructor arguments
   D:\........\myTest.php:26
  </code></pre>
  
  <p>This line: $this->pdo = $this->getMock('mockPDO',</p>
  
  <p>So may be i`m on wrong way? </p>