Fix DBAL 4.x mock compatibility in tests

- Update DriverMock::connect() signature for DBAL 4.x
- Add return types to DriverConnectionMock methods
- Add return types to StatementMock methods
- Add return types to DatabasePlatformMock methods
This commit is contained in:
Rafikooo 2026-02-06 17:37:49 +01:00 committed by TheMilek
parent a01e7ef1eb
commit 1c9cd7c243
No known key found for this signature in database
GPG key ID: A3F43F426B5286AA
5 changed files with 36 additions and 39 deletions

View file

@ -23,32 +23,39 @@ class DatabasePlatformMock extends AbstractPlatform
return true; return true;
} }
public function getBooleanTypeDeclarationSQL(array $field) public function getBooleanTypeDeclarationSQL(array $field): string
{ {
return 'BOOLEAN';
} }
public function getIntegerTypeDeclarationSQL(array $field) public function getIntegerTypeDeclarationSQL(array $field): string
{ {
return 'INT';
} }
public function getBigIntTypeDeclarationSQL(array $field) public function getBigIntTypeDeclarationSQL(array $field): string
{ {
return 'BIGINT';
} }
public function getSmallIntTypeDeclarationSQL(array $field) public function getSmallIntTypeDeclarationSQL(array $field): string
{ {
return 'SMALLINT';
} }
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef): string
{ {
return 'INT';
} }
public function getVarcharTypeDeclarationSQL(array $field) public function getVarcharTypeDeclarationSQL(array $field): string
{ {
return 'VARCHAR';
} }
public function getClobTypeDeclarationSQL(array $field) public function getClobTypeDeclarationSQL(array $field): string
{ {
return 'CLOB';
} }
public function getName(): string public function getName(): string

View file

@ -20,47 +20,43 @@ use Doctrine\DBAL\ParameterType;
class DriverConnectionMock implements Connection class DriverConnectionMock implements Connection
{ {
public function prepare($prepareString): Statement public function prepare(string $sql): Statement
{ {
return new StatementMock(); return new StatementMock();
} }
public function query(?string $sql = null): Result public function query(string $sql): Result
{ {
return new DriverResultMock(); return new DriverResultMock();
} }
public function quote($input, $type = ParameterType::STRING) public function quote($value, $type = ParameterType::STRING)
{ {
return (string) $input; return (string) $value;
} }
public function exec($statement): int public function exec(string $sql): int
{ {
throw new \BadMethodCallException('Not implemented'); throw new \BadMethodCallException('Not implemented');
} }
public function lastInsertId($name = null) public function lastInsertId($name = null): string|int|false
{ {
return false;
} }
public function beginTransaction() public function beginTransaction(): bool
{ {
return true;
} }
public function commit() public function commit(): bool
{ {
return true;
} }
public function rollBack() public function rollBack(): bool
{
}
public function errorCode()
{
}
public function errorInfo()
{ {
return true;
} }
} }

View file

@ -16,17 +16,18 @@ namespace Sylius\Tests\Functional\Doctrine\Mock;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\ExceptionConverter; use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\AbstractSchemaManager;
class DriverMock implements Driver class DriverMock implements Driver
{ {
public function connect(array $params, $username = null, $password = null, array $driverOptions = []) public function connect(array $params): DriverConnection
{ {
return new DriverConnectionMock(); return new DriverConnectionMock();
} }
public function getDatabasePlatform() public function getDatabasePlatform(): AbstractPlatform
{ {
throw new \BadMethodCallException('Not implemented'); throw new \BadMethodCallException('Not implemented');
} }
@ -40,14 +41,4 @@ class DriverMock implements Driver
{ {
throw new \BadMethodCallException('Not implemented'); throw new \BadMethodCallException('Not implemented');
} }
public function getName()
{
throw new \BadMethodCallException('Not implemented');
}
public function getDatabase(Connection $conn)
{
throw new \BadMethodCallException('Not implemented');
}
} }

View file

@ -21,12 +21,13 @@ use Doctrine\DBAL\Driver\Result;
*/ */
class DriverResultMock implements Result class DriverResultMock implements Result
{ {
/** @var list<array<string, mixed>> */
private array $resultSet; private array $resultSet;
/** /**
* Creates a new mock statement that will serve the provided fake result set to clients. * Creates a new mock statement that will serve the provided fake result set to clients.
* *
* @param array $resultSet The faked SQL result set. * @param list<array<string, mixed>> $resultSet The faked SQL result set.
*/ */
public function __construct(array $resultSet = []) public function __construct(array $resultSet = [])
{ {

View file

@ -21,12 +21,14 @@ use Traversable;
class StatementMock implements IteratorAggregate, Statement class StatementMock implements IteratorAggregate, Statement
{ {
public function bindValue($param, $value, $type = null) public function bindValue($param, $value, $type = null): bool
{ {
return true;
} }
public function bindParam($column, &$variable, $type = null, $length = null) public function bindParam($param, &$variable, $type = null, $length = null): bool
{ {
return true;
} }
public function execute($params = null): Result public function execute($params = null): Result