Unverified Commit 67944fce authored by Grégoire Paris's avatar Grégoire Paris Committed by GitHub

Merge pull request #4030 from morozov/remove-deprecations

Backport removal of some deprecated APIs
parents 179ab95b a48cad1e
# Upgrade to 3.0 # Upgrade to 3.0
## BC BREAK: Dropped handling of one-based numeric arrays of parameters in `Statement::execute()`
The statement implementations no longer detect whether `$params` is a zero- or one-based array. A zero-based numeric array is expected.
## BC BREAK `Statement::project()` has been removed
- The `Statement::project()` method has been removed. Use `::executeQuery()` and fetch the data from the statement using one of the `Statement::fetch*()` methods instead.
## BC BREAK `::errorCode()` and `::errorInfo()` removed from `Connection` and `Statement` APIs
The error information is available in `DriverException` thrown in case of an error.
## BC BREAK: Dropped support for `FetchMode::CUSTOM_OBJECT` and `::STANDARD_OBJECT` ## BC BREAK: Dropped support for `FetchMode::CUSTOM_OBJECT` and `::STANDARD_OBJECT`
Instead of fetching an object, fetch an array and map it to an object of the desired class. Instead of fetching an object, fetch an array and map it to an object of the desired class.
......
...@@ -27,7 +27,6 @@ parameters: ...@@ -27,7 +27,6 @@ parameters:
- '~^Method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint::onEvent\(\) should return string\|null but returns false\.\z~' - '~^Method Doctrine\\DBAL\\Schema\\ForeignKeyConstraint::onEvent\(\) should return string\|null but returns false\.\z~'
- '~^Method Doctrine\\DBAL\\Schema\\(Oracle|PostgreSql|SQLServer)SchemaManager::_getPortableTableDefinition\(\) should return array but returns string\.\z~' - '~^Method Doctrine\\DBAL\\Schema\\(Oracle|PostgreSql|SQLServer)SchemaManager::_getPortableTableDefinition\(\) should return array but returns string\.\z~'
- '~^Method Doctrine\\DBAL\\Driver\\OCI8\\OCI8Connection::lastInsertId\(\) should return string but returns (int|false)\.\z~' - '~^Method Doctrine\\DBAL\\Driver\\OCI8\\OCI8Connection::lastInsertId\(\) should return string but returns (int|false)\.\z~'
- '~^Method Doctrine\\DBAL\\Driver\\SQLSrv\\SQLSrvConnection::errorCode\(\) should return string\|null but returns false\.\z~'
# https://bugs.php.net/bug.php?id=78126 # https://bugs.php.net/bug.php?id=78126
- '~^Call to an undefined method PDO::sqliteCreateFunction\(\)\.\z~' - '~^Call to an undefined method PDO::sqliteCreateFunction\(\)\.\z~'
......
...@@ -1187,34 +1187,6 @@ class Connection implements DriverConnection ...@@ -1187,34 +1187,6 @@ class Connection implements DriverConnection
return $stmt; return $stmt;
} }
/**
* Executes an, optionally parametrized, SQL query and returns the result,
* applying a given projection/transformation function on each row of the result.
*
* @deprecated
*
* @param string $query The SQL query to execute.
* @param mixed[] $params The parameters, if any.
* @param Closure $function The transformation function that is applied on each row.
* The function receives a single parameter, an array, that
* represents a row of the result set.
*
* @return mixed[] The projected result of the query.
*/
public function project($query, array $params, Closure $function)
{
$result = [];
$stmt = $this->executeQuery($query, $params);
while ($row = $stmt->fetch()) {
$result[] = $function($row);
}
$stmt->closeCursor();
return $result;
}
public function query(string $sql) : ResultStatement public function query(string $sql) : ResultStatement
{ {
$connection = $this->getWrappedConnection(); $connection = $this->getWrappedConnection();
...@@ -1320,28 +1292,6 @@ class Connection implements DriverConnection ...@@ -1320,28 +1292,6 @@ class Connection implements DriverConnection
return $this->transactionNestingLevel; return $this->transactionNestingLevel;
} }
/**
* Fetches the SQLSTATE associated with the last database operation.
*
* @deprecated The error information is available via exceptions.
*
* @return string|null The last error code.
*/
public function errorCode()
{
return $this->getWrappedConnection()->errorCode();
}
/**
* {@inheritDoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return $this->getWrappedConnection()->errorInfo();
}
/** /**
* Returns the ID of the last inserted row, or the last value from a sequence object, * Returns the ID of the last inserted row, or the last value from a sequence object,
* depending on the underlying driver. * depending on the underlying driver.
......
...@@ -71,22 +71,4 @@ interface Connection ...@@ -71,22 +71,4 @@ interface Connection
* @return bool TRUE on success or FALSE on failure. * @return bool TRUE on success or FALSE on failure.
*/ */
public function rollBack(); public function rollBack();
/**
* Returns the error code associated with the last operation on the database handle.
*
* @deprecated The error information is available via exceptions.
*
* @return string|null The error code, or null if no operation has been run on the database handle.
*/
public function errorCode();
/**
* Returns extended error information associated with the last operation on the database handle.
*
* @deprecated The error information is available via exceptions.
*
* @return mixed[]
*/
public function errorInfo();
} }
...@@ -10,7 +10,6 @@ use stdClass; ...@@ -10,7 +10,6 @@ use stdClass;
use function assert; use function assert;
use function db2_autocommit; use function db2_autocommit;
use function db2_commit; use function db2_commit;
use function db2_conn_error;
use function db2_conn_errormsg; use function db2_conn_errormsg;
use function db2_connect; use function db2_connect;
use function db2_escape_string; use function db2_escape_string;
...@@ -166,27 +165,4 @@ class DB2Connection implements ServerInfoAwareConnection ...@@ -166,27 +165,4 @@ class DB2Connection implements ServerInfoAwareConnection
return $result; return $result;
} }
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
return db2_conn_error($this->conn);
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return [
0 => db2_conn_errormsg($this->conn),
1 => $this->errorCode(),
];
}
} }
...@@ -16,7 +16,6 @@ use function db2_fetch_both; ...@@ -16,7 +16,6 @@ use function db2_fetch_both;
use function db2_free_result; use function db2_free_result;
use function db2_num_fields; use function db2_num_fields;
use function db2_num_rows; use function db2_num_rows;
use function db2_stmt_error;
use function db2_stmt_errormsg; use function db2_stmt_errormsg;
use function error_get_last; use function error_get_last;
use function fclose; use function fclose;
...@@ -154,29 +153,6 @@ class DB2Statement implements IteratorAggregate, Statement ...@@ -154,29 +153,6 @@ class DB2Statement implements IteratorAggregate, Statement
return 0; return 0;
} }
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
return db2_stmt_error();
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return [
db2_stmt_errormsg(),
db2_stmt_error(),
];
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -193,26 +193,6 @@ class MysqliConnection implements PingableConnection, ServerInfoAwareConnection ...@@ -193,26 +193,6 @@ class MysqliConnection implements PingableConnection, ServerInfoAwareConnection
return $this->conn->rollback(); return $this->conn->rollback();
} }
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
return $this->conn->errno;
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return $this->conn->error;
}
/** /**
* Apply the driver options to the connection. * Apply the driver options to the connection.
* *
......
...@@ -463,24 +463,6 @@ class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatible ...@@ -463,24 +463,6 @@ class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatible
return FetchUtils::fetchAllAssociative($this); return FetchUtils::fetchAllAssociative($this);
} }
/**
* {@inheritdoc}
*/
public function errorCode()
{
return $this->_stmt->errno;
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return $this->_stmt->error;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -181,7 +181,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection ...@@ -181,7 +181,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
public function commit() public function commit()
{ {
if (! oci_commit($this->dbh)) { if (! oci_commit($this->dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo()); throw OCI8Exception::fromErrorInfo(oci_error($this->dbh));
} }
$this->executeMode = OCI_COMMIT_ON_SUCCESS; $this->executeMode = OCI_COMMIT_ON_SUCCESS;
...@@ -195,42 +195,11 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection ...@@ -195,42 +195,11 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection
public function rollBack() public function rollBack()
{ {
if (! oci_rollback($this->dbh)) { if (! oci_rollback($this->dbh)) {
throw OCI8Exception::fromErrorInfo($this->errorInfo()); throw OCI8Exception::fromErrorInfo(oci_error($this->dbh));
} }
$this->executeMode = OCI_COMMIT_ON_SUCCESS; $this->executeMode = OCI_COMMIT_ON_SUCCESS;
return true; return true;
} }
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
$error = oci_error($this->dbh);
if ($error !== false) {
$error = $error['code'];
}
return $error;
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
$error = oci_error($this->dbh);
if ($error === false) {
return [];
}
return $error;
}
} }
...@@ -10,7 +10,6 @@ use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatib ...@@ -10,7 +10,6 @@ use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatib
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use InvalidArgumentException; use InvalidArgumentException;
use IteratorAggregate; use IteratorAggregate;
use function array_key_exists;
use function assert; use function assert;
use function count; use function count;
use function implode; use function implode;
...@@ -356,46 +355,14 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe ...@@ -356,46 +355,14 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe
return 0; return 0;
} }
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
$error = oci_error($this->_sth);
if ($error !== false) {
$error = $error['code'];
}
return $error;
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
$error = oci_error($this->_sth);
if ($error === false) {
return [];
}
return $error;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function execute($params = null) public function execute($params = null)
{ {
if ($params !== null) { if ($params !== null) {
$hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) { foreach ($params as $key => $val) {
if ($hasZeroIndex && is_int($key)) { if (is_int($key)) {
$this->bindValue($key + 1, $val); $this->bindValue($key + 1, $val);
} else { } else {
$this->bindValue($key, $val); $this->bindValue($key, $val);
...@@ -405,7 +372,7 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe ...@@ -405,7 +372,7 @@ class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleRe
$ret = @oci_execute($this->_sth, $this->_conn->getExecuteMode()); $ret = @oci_execute($this->_sth, $this->_conn->getExecuteMode());
if (! $ret) { if (! $ret) {
throw OCI8Exception::fromErrorInfo($this->errorInfo()); throw OCI8Exception::fromErrorInfo(oci_error($this->_sth));
} }
$this->result = true; $this->result = true;
......
...@@ -138,22 +138,6 @@ class PDOConnection implements ServerInfoAwareConnection ...@@ -138,22 +138,6 @@ class PDOConnection implements ServerInfoAwareConnection
return $this->connection->rollBack(); return $this->connection->rollBack();
} }
/**
* {@inheritDoc}
*/
public function errorCode()
{
return $this->connection->errorCode();
}
/**
* {@inheritDoc}
*/
public function errorInfo()
{
return $this->connection->errorInfo();
}
public function getWrappedConnection() : PDO public function getWrappedConnection() : PDO
{ {
return $this->connection; return $this->connection;
......
...@@ -115,22 +115,6 @@ class PDOStatement implements IteratorAggregate, Statement, ForwardCompatibleRes ...@@ -115,22 +115,6 @@ class PDOStatement implements IteratorAggregate, Statement, ForwardCompatibleRes
return $this->stmt->columnCount(); return $this->stmt->columnCount();
} }
/**
* {@inheritdoc}
*/
public function errorCode()
{
return $this->stmt->errorCode();
}
/**
* {@inheritdoc}
*/
public function errorInfo()
{
return $this->stmt->errorInfo();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -15,8 +15,6 @@ use function is_string; ...@@ -15,8 +15,6 @@ use function is_string;
use function sasql_affected_rows; use function sasql_affected_rows;
use function sasql_commit; use function sasql_commit;
use function sasql_connect; use function sasql_connect;
use function sasql_error;
use function sasql_errorcode;
use function sasql_escape_string; use function sasql_escape_string;
use function sasql_insert_id; use function sasql_insert_id;
use function sasql_pconnect; use function sasql_pconnect;
...@@ -89,26 +87,6 @@ class SQLAnywhereConnection implements ServerInfoAwareConnection ...@@ -89,26 +87,6 @@ class SQLAnywhereConnection implements ServerInfoAwareConnection
return true; return true;
} }
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
return sasql_errorcode($this->connection);
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return sasql_error($this->connection);
}
public function exec(string $statement) : int public function exec(string $statement) : int
{ {
if (sasql_real_query($this->connection, $statement) === false) { if (sasql_real_query($this->connection, $statement) === false) {
......
...@@ -20,8 +20,6 @@ use function sasql_fetch_row; ...@@ -20,8 +20,6 @@ use function sasql_fetch_row;
use function sasql_prepare; use function sasql_prepare;
use function sasql_stmt_affected_rows; use function sasql_stmt_affected_rows;
use function sasql_stmt_bind_param_ex; use function sasql_stmt_bind_param_ex;
use function sasql_stmt_errno;
use function sasql_stmt_error;
use function sasql_stmt_execute; use function sasql_stmt_execute;
use function sasql_stmt_field_count; use function sasql_stmt_field_count;
use function sasql_stmt_reset; use function sasql_stmt_reset;
...@@ -138,26 +136,6 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement, ForwardCompa ...@@ -138,26 +136,6 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement, ForwardCompa
return sasql_stmt_field_count($this->stmt); return sasql_stmt_field_count($this->stmt);
} }
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
return sasql_stmt_errno($this->stmt);
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return sasql_stmt_error($this->stmt);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
......
...@@ -14,13 +14,11 @@ use function sqlsrv_begin_transaction; ...@@ -14,13 +14,11 @@ use function sqlsrv_begin_transaction;
use function sqlsrv_commit; use function sqlsrv_commit;
use function sqlsrv_configure; use function sqlsrv_configure;
use function sqlsrv_connect; use function sqlsrv_connect;
use function sqlsrv_errors;
use function sqlsrv_query; use function sqlsrv_query;
use function sqlsrv_rollback; use function sqlsrv_rollback;
use function sqlsrv_rows_affected; use function sqlsrv_rows_affected;
use function sqlsrv_server_info; use function sqlsrv_server_info;
use function str_replace; use function str_replace;
use const SQLSRV_ERR_ERRORS;
/** /**
* SQL Server implementation for the Connection interface. * SQL Server implementation for the Connection interface.
...@@ -173,29 +171,4 @@ class SQLSrvConnection implements ServerInfoAwareConnection ...@@ -173,29 +171,4 @@ class SQLSrvConnection implements ServerInfoAwareConnection
return true; return true;
} }
/**
* {@inheritDoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
if ($errors !== null) {
return $errors[0]['code'];
}
return false;
}
/**
* {@inheritDoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return (array) sqlsrv_errors(SQLSRV_ERR_ERRORS);
}
} }
...@@ -9,10 +9,8 @@ use Doctrine\DBAL\FetchMode; ...@@ -9,10 +9,8 @@ use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use IteratorAggregate; use IteratorAggregate;
use function array_key_exists;
use function is_int; use function is_int;
use function is_numeric; use function is_numeric;
use function sqlsrv_errors;
use function sqlsrv_execute; use function sqlsrv_execute;
use function sqlsrv_fetch; use function sqlsrv_fetch;
use function sqlsrv_fetch_array; use function sqlsrv_fetch_array;
...@@ -26,7 +24,6 @@ use function sqlsrv_rows_affected; ...@@ -26,7 +24,6 @@ use function sqlsrv_rows_affected;
use function SQLSRV_SQLTYPE_VARBINARY; use function SQLSRV_SQLTYPE_VARBINARY;
use function stripos; use function stripos;
use const SQLSRV_ENC_BINARY; use const SQLSRV_ENC_BINARY;
use const SQLSRV_ERR_ERRORS;
use const SQLSRV_FETCH_ASSOC; use const SQLSRV_FETCH_ASSOC;
use const SQLSRV_FETCH_BOTH; use const SQLSRV_FETCH_BOTH;
use const SQLSRV_FETCH_NUMERIC; use const SQLSRV_FETCH_NUMERIC;
...@@ -203,40 +200,14 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible ...@@ -203,40 +200,14 @@ class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatible
return 0; return 0;
} }
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
$errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
if ($errors !== null) {
return $errors[0]['code'];
}
return false;
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return (array) sqlsrv_errors(SQLSRV_ERR_ERRORS);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function execute($params = null) public function execute($params = null)
{ {
if ($params !== null) { if ($params !== null) {
$hasZeroIndex = array_key_exists(0, $params);
foreach ($params as $key => $val) { foreach ($params as $key => $val) {
if ($hasZeroIndex && is_int($key)) { if (is_int($key)) {
$this->bindValue($key + 1, $val); $this->bindValue($key + 1, $val);
} else { } else {
$this->bindValue($key, $val); $this->bindValue($key, $val);
......
...@@ -57,26 +57,6 @@ interface Statement extends ResultStatement ...@@ -57,26 +57,6 @@ interface Statement extends ResultStatement
*/ */
public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null); public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null);
/**
* Fetches the SQLSTATE associated with the last operation on the statement handle.
*
* @deprecated The error information is available via exceptions.
*
* @see Doctrine_Adapter_Interface::errorCode()
*
* @return string|int|bool The error code string.
*/
public function errorCode();
/**
* Fetches extended error information associated with the last operation on the statement handle.
*
* @deprecated The error information is available via exceptions.
*
* @return mixed[] The error info array.
*/
public function errorInfo();
/** /**
* Executes a prepared statement * Executes a prepared statement
* *
...@@ -86,7 +66,7 @@ interface Statement extends ResultStatement ...@@ -86,7 +66,7 @@ interface Statement extends ResultStatement
* if any, of their associated parameter markers or pass an array of input-only * if any, of their associated parameter markers or pass an array of input-only
* parameter values. * parameter values.
* *
* @param mixed[]|null $params An array of values with as many elements as there are * @param mixed[]|null $params A numeric array of values with as many elements as there are
* bound parameters in the SQL statement being executed. * bound parameters in the SQL statement being executed.
* *
* @return bool TRUE on success or FALSE on failure. * @return bool TRUE on success or FALSE on failure.
......
...@@ -79,30 +79,6 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -79,30 +79,6 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
return $this->stmt->columnCount(); return $this->stmt->columnCount();
} }
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorCode()
{
assert($this->stmt instanceof DriverStatement);
return $this->stmt->errorCode();
}
/**
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
assert($this->stmt instanceof DriverStatement);
return $this->stmt->errorInfo();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -196,28 +196,6 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible ...@@ -196,28 +196,6 @@ class Statement implements IteratorAggregate, DriverStatement, ForwardCompatible
return $this->stmt->columnCount(); return $this->stmt->columnCount();
} }
/**
* Fetches the SQLSTATE associated with the last operation on the statement.
*
* @deprecated The error information is available via exceptions.
*
* @return string|int|bool
*/
public function errorCode()
{
return $this->stmt->errorCode();
}
/**
* {@inheritDoc}
*
* @deprecated The error information is available via exceptions.
*/
public function errorInfo()
{
return $this->stmt->errorInfo();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
* *
......
...@@ -2,11 +2,9 @@ ...@@ -2,11 +2,9 @@
namespace Doctrine\DBAL\Tests\Driver\OCI8; namespace Doctrine\DBAL\Tests\Driver\OCI8;
use Doctrine\DBAL\Driver\OCI8\OCI8Connection;
use Doctrine\DBAL\Driver\OCI8\OCI8Exception; use Doctrine\DBAL\Driver\OCI8\OCI8Exception;
use Doctrine\DBAL\Driver\OCI8\OCI8Statement; use Doctrine\DBAL\Driver\OCI8\OCI8Statement;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use function extension_loaded; use function extension_loaded;
class OCI8StatementTest extends TestCase class OCI8StatementTest extends TestCase
...@@ -20,84 +18,6 @@ class OCI8StatementTest extends TestCase ...@@ -20,84 +18,6 @@ class OCI8StatementTest extends TestCase
parent::setUp(); parent::setUp();
} }
/**
* This scenario shows that when the first parameter is not null
* it properly sets $hasZeroIndex to 1 and calls bindValue starting at 1.
*
* This also verifies that the statement will check with the connection to
* see what the current execution mode is.
*
* The expected exception is due to oci_execute failing due to no valid connection.
*
* @param mixed[] $params
*
* @dataProvider executeDataProvider
*/
public function testExecute(array $params) : void
{
$statement = $this->getMockBuilder(OCI8Statement::class)
->onlyMethods(['bindValue', 'errorInfo'])
->disableOriginalConstructor()
->getMock();
$statement->expects(self::at(0))
->method('bindValue')
->with(
self::equalTo(1),
self::equalTo($params[0])
);
$statement->expects(self::at(1))
->method('bindValue')
->with(
self::equalTo(2),
self::equalTo($params[1])
);
$statement->expects(self::at(2))
->method('bindValue')
->with(
self::equalTo(3),
self::equalTo($params[2])
);
// the return value is irrelevant to the test
// but it has to be compatible with the method signature
$statement->method('errorInfo')
->willReturn(false);
// can't pass to constructor since we don't have a real database handle,
// but execute must check the connection for the executeMode
$conn = $this->getMockBuilder(OCI8Connection::class)
->onlyMethods(['getExecuteMode'])
->disableOriginalConstructor()
->getMock();
$conn->expects(self::once())
->method('getExecuteMode');
$reflProperty = new ReflectionProperty($statement, '_conn');
$reflProperty->setAccessible(true);
$reflProperty->setValue($statement, $conn);
$this->expectException(OCI8Exception::class);
$statement->execute($params);
}
/**
* @return array<int, array<int, mixed>>
*/
public static function executeDataProvider() : iterable
{
return [
// $hasZeroIndex = isset($params[0]); == true
[
[0 => 'test', 1 => null, 2 => 'value'],
],
// $hasZeroIndex = isset($params[0]); == false
[
[0 => null, 1 => 'test', 2 => 'value'],
],
];
}
/** /**
* @dataProvider nonTerminatedLiteralProvider * @dataProvider nonTerminatedLiteralProvider
*/ */
......
...@@ -80,28 +80,6 @@ class StatementTest extends TestCase ...@@ -80,28 +80,6 @@ class StatementTest extends TestCase
self::assertSame($columnCount, $this->stmt->columnCount()); self::assertSame($columnCount, $this->stmt->columnCount());
} }
public function testErrorCode() : void
{
$errorCode = '666';
$this->wrappedStmt->expects(self::once())
->method('errorCode')
->will(self::returnValue($errorCode));
self::assertSame($errorCode, $this->stmt->errorCode());
}
public function testErrorInfo() : void
{
$errorInfo = ['666', 'Evil error.'];
$this->wrappedStmt->expects(self::once())
->method('errorInfo')
->will(self::returnValue($errorInfo));
self::assertSame($errorInfo, $this->stmt->errorInfo());
}
public function testExecute() : void public function testExecute() : void
{ {
$params = [ $params = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment