mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
- 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
(cherry picked from commit 1c9cd7c243)
97 lines
2 KiB
PHP
97 lines
2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Sylius package.
|
|
*
|
|
* (c) Sylius Sp. z o.o.
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Sylius\Tests\Functional\Doctrine\Mock;
|
|
|
|
use BadMethodCallException;
|
|
use Doctrine\DBAL\Driver\Result;
|
|
|
|
/**
|
|
* This class is mostly copied from {@link https://github.com/doctrine/orm/blob/2.14.x/tests/Doctrine/Tests/Mocks/DriverResultMock.php}
|
|
*/
|
|
class DriverResultMock implements Result
|
|
{
|
|
/** @var list<array<string, mixed>> */
|
|
private array $resultSet;
|
|
|
|
/**
|
|
* Creates a new mock statement that will serve the provided fake result set to clients.
|
|
*
|
|
* @param list<array<string, mixed>> $resultSet The faked SQL result set.
|
|
*/
|
|
public function __construct(array $resultSet = [])
|
|
{
|
|
$this->resultSet = $resultSet;
|
|
}
|
|
|
|
public function fetchNumeric()
|
|
{
|
|
$row = $this->fetchAssociative();
|
|
|
|
return $row === false ? false : array_values($row);
|
|
}
|
|
|
|
public function fetchAssociative()
|
|
{
|
|
$current = current($this->resultSet);
|
|
next($this->resultSet);
|
|
|
|
return $current;
|
|
}
|
|
|
|
public function fetchOne()
|
|
{
|
|
$row = $this->fetchNumeric();
|
|
|
|
return $row ? $row[0] : false;
|
|
}
|
|
|
|
public function fetchAllNumeric(): array
|
|
{
|
|
$values = [];
|
|
while (($row = $this->fetchNumeric()) !== false) {
|
|
$values[] = $row;
|
|
}
|
|
|
|
return $values;
|
|
}
|
|
|
|
public function fetchAllAssociative(): array
|
|
{
|
|
$resultSet = $this->resultSet;
|
|
reset($resultSet);
|
|
|
|
return $resultSet;
|
|
}
|
|
|
|
public function fetchFirstColumn(): array
|
|
{
|
|
throw new BadMethodCallException('Not implemented');
|
|
}
|
|
|
|
public function rowCount(): int
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
public function columnCount(): int
|
|
{
|
|
$resultSet = $this->resultSet;
|
|
|
|
return count(reset($resultSet) ?: []);
|
|
}
|
|
|
|
public function free(): void
|
|
{
|
|
}
|
|
}
|