Unverified Commit 66b1f3d2 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #4058 from morozov/portability-result-tests

Add tests for fetch*() methods of Portability\Result
parents 3710903b dded5346
......@@ -11,6 +11,86 @@ use PHPUnit\Framework\TestCase;
class ResultTest extends TestCase
{
/**
* @param mixed $return
*
* @dataProvider fetchProvider
*/
public function testFetch(string $source, callable $fetch, $return): void
{
$driverResult = $this->createMock(DriverResult::class);
$driverResult->expects(self::once())
->method($source)
->willReturn($return);
$result = $this->newResult($driverResult);
self::assertSame($return, $fetch($result));
}
/**
* @return iterable<string,array<int,mixed>>
*/
public static function fetchProvider(): iterable
{
yield 'numeric' => [
'fetchNumeric',
static function (Result $result): array {
return $result->fetchNumeric();
},
['bar'],
];
yield 'associative' => [
'fetchAssociative',
static function (Result $result): array {
return $result->fetchAssociative();
},
['foo' => 'bar'],
];
yield 'one' => [
'fetchOne',
static function (Result $result) {
return $result->fetchOne();
},
'bar',
];
yield 'all-numeric' => [
'fetchAllNumeric',
static function (Result $result): array {
return $result->fetchAllNumeric();
},
[
['bar'],
['baz'],
],
];
yield 'all-associative' => [
'fetchAllAssociative',
static function (Result $result): array {
return $result->fetchAllAssociative();
},
[
['foo' => 'bar'],
['foo' => 'baz'],
],
];
yield 'first-column' => [
'fetchFirstColumn',
static function (Result $result): array {
return $result->fetchFirstColumn();
},
[
'bar',
'baz',
],
];
}
public function testRowCount(): void
{
$driverResult = $this->createMock(DriverResult::class);
......
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