Drupal Test Helpers module API documentation - release 1.5.0

Connection extends Connection
in package

A stub of the Drupal's default Connection class.

@package TestHelpers\DrupalServiceStubs

Tags
todo

Consider extending the StubConnection instead of Connection.

Table of Contents

Constants

STUB_RESULT_DELETE  = 1
STUB_RESULT_INSERTS  = 1

Properties

$pdoMock  : MockObject
The static storage for execute functions.
$stubExecuteHandlers  : array<string|int, mixed>
The static storage for execute functions.

Methods

__construct()  : mixed
{@inheritdoc}
createDatabase()  : mixed
{@inheritdoc}
databaseType()  : mixed
{@inheritdoc}
delete()  : mixed
{@inheritdoc}
driver()  : mixed
{@inheritdoc}
insert()  : mixed
{@inheritdoc}
mapConditionOperator()  : mixed
{@inheritdoc}
nextId()  : mixed
{@inheritdoc}
open()  : mixed
{@inheritdoc}
popTransaction()  : mixed
A stub of original function to do nothing.
queryRange()  : mixed
{@inheritdoc}
queryTemporary()  : mixed
A stub of original function to do nothing.
schema()  : mixed
{@inheritdoc}
select()  : mixed
{@inheritdoc}
stubAddConnection()  : void
Adds a new database connection with auto-generated info for the stub.
stubGetConnection()  : Connection
Gets a database connection and initiates a new stub if missing.
stubSetExecuteHandler()  : void
Sets the function to handle execute calls.
upsert()  : mixed
{@inheritdoc}
driverTransactionManager()  : TransactionManagerInterface
{@inheritdoc}
getNamespace()  : string
Returns the namespace of the class.
mockExecuteForMethod()  : MockObject
Mocks the execute function for a method.

Constants

STUB_RESULT_DELETE

public mixed STUB_RESULT_DELETE = 1

STUB_RESULT_INSERTS

public mixed STUB_RESULT_INSERTS = 1

Properties

$pdoMock

The static storage for execute functions.

protected MockObject $pdoMock

$stubExecuteHandlers

The static storage for execute functions.

protected array<string|int, mixed> $stubExecuteHandlers = []

Methods

__construct()

{@inheritdoc}

public __construct([PDO|null $connection = NULL ][, array<string|int, mixed> $connection_options = [] ]) : mixed
Parameters
$connection : PDO|null = NULL
$connection_options : array<string|int, mixed> = []

createDatabase()

{@inheritdoc}

public createDatabase(mixed $database) : mixed
Parameters
$database : mixed

databaseType()

{@inheritdoc}

public databaseType() : mixed

delete()

{@inheritdoc}

public delete(mixed $table[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$table : mixed
$options : array<string|int, mixed> = []

insert()

{@inheritdoc}

public insert(mixed $table[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$table : mixed
$options : array<string|int, mixed> = []

mapConditionOperator()

{@inheritdoc}

public mapConditionOperator(mixed $operator) : mixed
Parameters
$operator : mixed

nextId()

{@inheritdoc}

public nextId([mixed $existing_id = 0 ]) : mixed
Parameters
$existing_id : mixed = 0

open()

{@inheritdoc}

public static open([array<string|int, mixed> &$connection_options = [] ]) : mixed
Parameters
$connection_options : array<string|int, mixed> = []

popTransaction()

A stub of original function to do nothing.

public popTransaction(mixed $name) : mixed
Parameters
$name : mixed

queryRange()

{@inheritdoc}

public queryRange(mixed $query, mixed $from, mixed $count[, array<string|int, mixed> $args = [] ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$query : mixed
$from : mixed
$count : mixed
$args : array<string|int, mixed> = []
$options : array<string|int, mixed> = []

queryTemporary()

A stub of original function to do nothing.

public queryTemporary(mixed $query[, array<string|int, mixed> $args = [] ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$query : mixed
$args : array<string|int, mixed> = []
$options : array<string|int, mixed> = []

select()

{@inheritdoc}

public select(mixed $table[, mixed $alias = NULL ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$table : mixed
$alias : mixed = NULL
$options : array<string|int, mixed> = []

stubAddConnection()

Adds a new database connection with auto-generated info for the stub.

public static stubAddConnection([string|null $key = NULL ][, string $target = 'default' ][, array<string|int, mixed>|null $connectionInfo = NULL ]) : void
Parameters
$key : string|null = NULL

(optional) The key for the connection.

$target : string = 'default'

(optional) The target connection.

$connectionInfo : array<string|int, mixed>|null = NULL

(optional) The connection info.

stubGetConnection()

Gets a database connection and initiates a new stub if missing.

public static stubGetConnection([string $target = 'default' ][, string|null $key = NULL ]) : Connection
Parameters
$target : string = 'default'

(optional) The target connection.

$key : string|null = NULL

(optional) The key for the connection.

Return values
Connection

The database connection.

stubSetExecuteHandler()

Sets the function to handle execute calls.

public stubSetExecuteHandler(Closure $executeFunction[, string $method = 'all' ]) : void

You can call $this->stubExecuteBase() in your custom callback function to execute the base stub behavior for the query.

Parameters
$executeFunction : Closure

The execute function.

$method : string = 'all'

The exact method to set (insert, select, delete), all methods by default.

upsert()

{@inheritdoc}

public upsert(mixed $table[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
$table : mixed
$options : array<string|int, mixed> = []

driverTransactionManager()

{@inheritdoc}

protected driverTransactionManager() : TransactionManagerInterface
Return values
TransactionManagerInterface

getNamespace()

Returns the namespace of the class.

private static getNamespace(string $fqcn) : string
Parameters
$fqcn : string

The full qualified class name.

Return values
string

The namespace of the class.

mockExecuteForMethod()

Mocks the execute function for a method.

private mockExecuteForMethod(string $method, array<string|int, mixed> $methodArguments) : MockObject
Parameters
$method : string

The method name.

$methodArguments : array<string|int, mixed>

The list of arguments of the method.

Return values
MockObject

The mocked method.


        
On this page

Search results