1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL\Tests\Cache; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Cache\ArrayStatement; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use function array_values; |
10
|
|
|
use function iterator_to_array; |
11
|
|
|
|
12
|
|
|
class ArrayStatementTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** @var array<int, array<string, mixed>> */ |
15
|
|
|
private $users = [ |
16
|
|
|
[ |
17
|
|
|
'username' => 'jwage', |
18
|
|
|
'active' => true, |
19
|
|
|
], |
20
|
|
|
[ |
21
|
|
|
'username' => 'romanb', |
22
|
|
|
'active' => false, |
23
|
|
|
], |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
public function testCloseCursor() : void |
27
|
|
|
{ |
28
|
|
|
$statement = $this->createTestArrayStatement(); |
29
|
|
|
|
30
|
|
|
self::assertSame(2, $statement->rowCount()); |
31
|
|
|
|
32
|
|
|
$statement->closeCursor(); |
33
|
|
|
|
34
|
|
|
self::assertSame(0, $statement->rowCount()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testColumnCount() : void |
38
|
|
|
{ |
39
|
|
|
$statement = $this->createTestArrayStatement(); |
40
|
|
|
|
41
|
|
|
self::assertSame(2, $statement->columnCount()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testRowCount() : void |
45
|
|
|
{ |
46
|
|
|
$statement = $this->createTestArrayStatement(); |
47
|
|
|
|
48
|
|
|
self::assertSame(2, $statement->rowCount()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetIterator() : void |
52
|
|
|
{ |
53
|
|
|
$statement = $this->createTestArrayStatement(); |
54
|
|
|
|
55
|
|
|
self::assertSame($this->users, iterator_to_array($statement->iterateAssociative())); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testFetchModeAssociative() : void |
59
|
|
|
{ |
60
|
|
|
$statement = $this->createTestArrayStatement(); |
61
|
|
|
|
62
|
|
|
self::assertSame($this->users[0], $statement->fetchAssociative()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testFetchModeNumeric() : void |
66
|
|
|
{ |
67
|
|
|
$statement = $this->createTestArrayStatement(); |
68
|
|
|
|
69
|
|
|
self::assertSame(array_values($this->users[0]), $statement->fetchNumeric()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testFetchModeColumn() : void |
73
|
|
|
{ |
74
|
|
|
$statement = $this->createTestArrayStatement(); |
75
|
|
|
|
76
|
|
|
self::assertSame('jwage', $statement->fetchColumn()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testFetchAllAssociative() : void |
80
|
|
|
{ |
81
|
|
|
$statement = $this->createTestArrayStatement(); |
82
|
|
|
|
83
|
|
|
self::assertSame($this->users, $statement->fetchAllAssociative()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testFetchColumn() : void |
87
|
|
|
{ |
88
|
|
|
$statement = $this->createTestArrayStatement(); |
89
|
|
|
|
90
|
|
|
self::assertSame('jwage', $statement->fetchColumn()); |
91
|
|
|
self::assertSame('romanb', $statement->fetchColumn()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
private function createTestArrayStatement() : ArrayStatement |
95
|
|
|
{ |
96
|
|
|
return new ArrayStatement($this->users); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|