StubPDO.php

Same filename and directory in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Database/Stub/StubPDO.php
  2. 10 core/tests/Drupal/Tests/Core/Database/Stub/StubPDO.php
  3. 11.x core/tests/Drupal/Tests/Core/Database/Stub/StubPDO.php

Namespace

Drupal\Tests\Core\Database\Stub

File

core/tests/Drupal/Tests/Core/Database/Stub/StubPDO.php

View source
<?php

namespace Drupal\Tests\Core\Database\Stub;


/**
 * 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.
 *
 * @see Drupal\Tests\Core\Database\ConnectionTest
 * @see Drupal\Core\Database\Connection
 * @see http://stackoverflow.com/questions/3138946/mocking-the-pdo-object-using-phpunit
 */
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.
    }

}

Classes

Title Deprecated Summary
StubPDO A stub of \PDO for testing purposes.

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