Skip to content

Commit 923a6d7

Browse files
author
Bartłomiej Nowak
committed
tests adjustments
1 parent 90fbfae commit 923a6d7

File tree

4 files changed

+65
-12
lines changed

4 files changed

+65
-12
lines changed

tests/default/DbaInferenceTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public function dataFileAsserts(): iterable
1818
}
1919

2020
yield from $this->gatherAssertTypes(__DIR__ . '/data/doctrine-dbal-union-result.php');
21+
if (InstalledVersions::satisfies(new VersionParser(), 'doctrine/dbal', '3.*')) {
22+
yield from $this->gatherAssertTypes(__DIR__ . '/data/doctrine-dbal3.php');
23+
}
2124
yield from $this->gatherAssertTypes(__DIR__ . '/data/doctrine-dbal.php');
2225
yield from $this->gatherAssertTypes(__DIR__ . '/data/inference-placeholder.php');
2326

tests/default/data/doctrine-dbal-union-result.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,4 @@ public function doFoo(Connection $conn)
2626
assertType('array{adaid: int<-32768, 32767>}|array{email: string}|false', $fetch);
2727
}
2828
}
29-
30-
public function doBar(Connection $conn)
31-
{
32-
$queries = ['SELECT adaid FROM ada', 'SELECT email FROM ada'];
33-
34-
foreach ($queries as $query) {
35-
$result = $conn->query($query);
36-
assertType('array{adaid: int<-32768, 32767>}|array{email: string}|false', $result->fetchAssociative());
37-
}
38-
}
3929
}

tests/default/data/doctrine-dbal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
class Foo
1212
{
13-
public function foo(Connection $conn)
13+
public function resultFetching(Connection $conn)
1414
{
15-
$result = $conn->query('SELECT email, adaid FROM ada');
15+
$result = $conn->executeQuery('SELECT email, adaid FROM ada');
1616

1717
$columnCount = $result->columnCount();
1818
assertType('2', $columnCount);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace DoctrineDbal3Test;
4+
5+
use Doctrine\DBAL\Connection;
6+
use function PHPStan\Testing\assertType;
7+
8+
class Foo
9+
{
10+
public function resultFetching(Connection $conn)
11+
{
12+
$result = $conn->query('SELECT email, adaid FROM ada');
13+
14+
$columnCount = $result->columnCount();
15+
assertType('2', $columnCount);
16+
17+
$fetch = $result->fetchOne();
18+
assertType('string|false', $fetch);
19+
20+
$fetch = $result->fetchNumeric();
21+
assertType('array{string, int<-32768, 32767>}|false', $fetch);
22+
23+
$fetch = $result->fetchFirstColumn();
24+
assertType('list<string>', $fetch);
25+
26+
$fetch = $result->fetchAssociative();
27+
assertType('array{email: string, adaid: int<-32768, 32767>}|false', $fetch);
28+
29+
$fetch = $result->fetchAllNumeric();
30+
assertType('list<array{string, int<-32768, 32767>}>', $fetch);
31+
32+
$fetch = $result->fetchAllAssociative();
33+
assertType('list<array{email: string, adaid: int<-32768, 32767>}>', $fetch);
34+
35+
$fetch = $result->fetchAllKeyValue();
36+
assertType('array<string, int<-32768, 32767>>', $fetch);
37+
38+
$fetch = $result->iterateNumeric();
39+
assertType('Traversable<int, array{string, int<-32768, 32767>}>', $fetch);
40+
41+
$fetch = $result->iterateAssociative();
42+
assertType('Traversable<int, array{email: string, adaid: int<-32768, 32767>}>', $fetch);
43+
44+
$fetch = $result->iterateColumn();
45+
assertType('Traversable<int, string>', $fetch);
46+
47+
$fetch = $result->iterateKeyValue();
48+
assertType('Traversable<string, int<-32768, 32767>>', $fetch);
49+
}
50+
51+
public function unionQueriesResult(Connection $conn)
52+
{
53+
$queries = ['SELECT adaid FROM ada', 'SELECT email FROM ada'];
54+
55+
foreach ($queries as $query) {
56+
$result = $conn->query($query);
57+
assertType('array{adaid: int<-32768, 32767>}|array{email: string}|false', $result->fetchAssociative());
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)