class StubPDO

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Database/Stub/StubPDO.php \Drupal\Tests\Core\Database\Stub\StubPDO
  2. 8.9.x core/tests/Drupal/Tests/Core/Database/Stub/StubPDO.php \Drupal\Tests\Core\Database\Stub\StubPDO
  3. 11.x core/tests/Drupal/Tests/Core/Database/Stub/StubPDO.php \Drupal\Tests\Core\Database\Stub\StubPDO

A stub of \PDO for testing purposes.

We override the constructor method so that PHPUnit can mock the \PDO class. \PDO itself can't be mocked, so we have to create a subclass. This subclass is being used to unit test Connection, so we don't need a functional database but we do need a mock \PDO object.

Hierarchy

  • class \Drupal\Tests\Core\Database\Stub\StubPDO extends \Drupal\Tests\Core\Database\Stub\PDO

Expanded class hierarchy of StubPDO

See also

Drupal\Tests\Core\Database\ConnectionTest

Drupal\Core\Database\Connection

http://stackoverflow.com/questions/3138946/mocking-the-pdo-object-using…

12 files declare their use of StubPDO
CacheTest.php in core/tests/Drupal/Tests/Core/Cache/CacheTest.php
ConditionTest.php in core/tests/Drupal/Tests/Core/Database/ConditionTest.php
ConnectionTest.php in core/modules/sqlite/tests/src/Unit/ConnectionTest.php
ConnectionTest.php in core/tests/Drupal/Tests/Core/Database/ConnectionTest.php
DatabaseEventsTest.php in core/tests/Drupal/Tests/Core/Database/DatabaseEventsTest.php

... See full list

File

core/tests/Drupal/Tests/Core/Database/Stub/StubPDO.php, line 19

Namespace

Drupal\Tests\Core\Database\Stub
View source
class StubPDO extends \PDO {
    
    /**
     * Construction method.
     *
     * We override this construction method with a no-op in order to mock \PDO
     * under unit tests.
     *
     * @see http://stackoverflow.com/questions/3138946/mocking-the-pdo-object-using-phpunit
     */
    public function __construct() {
        // No-op.
    }

}

Members

Title Sort descending Modifiers Object type Summary
StubPDO::__construct public function Construction method.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.