Skip to content

Commit 091f86d

Browse files
committed
Improve type declaration of tests files
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent 2383b1e commit 091f86d

File tree

11 files changed

+81
-227
lines changed

11 files changed

+81
-227
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,11 +1755,6 @@ parameters:
17551755
count: 4
17561756
path: tests/Builder/CreateStatementTest.php
17571757

1758-
-
1759-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Builder\\\\CreateStatementTest\\:\\:partitionQueriesProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
1760-
count: 1
1761-
path: tests/Builder/CreateStatementTest.php
1762-
17631758
-
17641759
message: "#^Parameter \\#1 \\$component of static method PhpMyAdmin\\\\SqlParser\\\\Components\\\\CreateDefinition\\:\\:build\\(\\) expects array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\CreateDefinition\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\CreateDefinition, array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\CreateDefinition\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|null given\\.$#"
17651760
count: 2
@@ -1780,16 +1775,6 @@ parameters:
17801775
count: 2
17811776
path: tests/Components/ArrayObjTest.php
17821777

1783-
-
1784-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Components\\\\ArrayObjTest\\:\\:parseProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
1785-
count: 1
1786-
path: tests/Components/ArrayObjTest.php
1787-
1788-
-
1789-
message: "#^Parameter \\#1 \\$name of method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\TestCase\\:\\:runParserTest\\(\\) expects string, mixed given\\.$#"
1790-
count: 1
1791-
path: tests/Components/ArrayObjTest.php
1792-
17931778
-
17941779
message: "#^Cannot access offset 0 on array\\<PhpMyAdmin\\\\SqlParser\\\\Components\\\\CreateDefinition\\>\\|PhpMyAdmin\\\\SqlParser\\\\Components\\\\ArrayObj\\|null\\.$#"
17951780
count: 1
@@ -1870,21 +1855,6 @@ parameters:
18701855
count: 1
18711856
path: tests/Components/RenameOperationTest.php
18721857

1873-
-
1874-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Lexer\\\\ContextTest\\:\\:contextLoadingProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
1875-
count: 1
1876-
path: tests/Lexer/ContextTest.php
1877-
1878-
-
1879-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Lexer\\\\ContextTest\\:\\:contextNamesProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
1880-
count: 1
1881-
path: tests/Lexer/ContextTest.php
1882-
1883-
-
1884-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Lexer\\\\LexerTest\\:\\:lexProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
1885-
count: 1
1886-
path: tests/Lexer/LexerTest.php
1887-
18881858
-
18891859
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) with 2 and PhpMyAdmin\\\\SqlParser\\\\TokensList will always evaluate to false\\.$#"
18901860
count: 1
@@ -1895,16 +1865,6 @@ parameters:
18951865
count: 1
18961866
path: tests/Misc/UtfStringTest.php
18971867

1898-
-
1899-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Misc\\\\UtfStringTest\\:\\:utf8StringsProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
1900-
count: 1
1901-
path: tests/Misc/UtfStringTest.php
1902-
1903-
-
1904-
message: "#^Parameter \\#1 \\$str of class PhpMyAdmin\\\\SqlParser\\\\UtfString constructor expects string, mixed given\\.$#"
1905-
count: 1
1906-
path: tests/Misc/UtfStringTest.php
1907-
19081868
-
19091869
message: "#^Cannot call method has\\(\\) on PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
19101870
count: 1
@@ -1920,86 +1880,21 @@ parameters:
19201880
count: 1
19211881
path: tests/Parser/WithStatementTest.php
19221882

1923-
-
1924-
message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Exceptions\\\\LexerException\\|PhpMyAdmin\\\\SqlParser\\\\Exceptions\\\\ParserException\\:\\:\\$ch\\.$#"
1925-
count: 1
1926-
path: tests/TestCase.php
1927-
1928-
-
1929-
message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Exceptions\\\\LexerException\\|PhpMyAdmin\\\\SqlParser\\\\Exceptions\\\\ParserException\\:\\:\\$pos\\.$#"
1930-
count: 1
1931-
path: tests/TestCase.php
1932-
1933-
-
1934-
message: "#^Access to an undefined property PhpMyAdmin\\\\SqlParser\\\\Exceptions\\\\LexerException\\|PhpMyAdmin\\\\SqlParser\\\\Exceptions\\\\ParserException\\:\\:\\$token\\.$#"
1935-
count: 1
1936-
path: tests/TestCase.php
1937-
1938-
-
1939-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\TestCase\\:\\:getErrorsAsArray\\(\\) return type has no value type specified in iterable type array\\.$#"
1940-
count: 1
1941-
path: tests/TestCase.php
1942-
19431883
-
19441884
message: "#^Cannot access offset int on non\\-empty\\-array\\<int, string\\>\\|false\\.$#"
19451885
count: 1
19461886
path: tests/Utils/BufferedQueryTest.php
19471887

1948-
-
1949-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Utils\\\\BufferedQueryTest\\:\\:extractProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
1950-
count: 1
1951-
path: tests/Utils/BufferedQueryTest.php
1952-
1953-
-
1954-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Utils\\\\BufferedQueryTest\\:\\:testExtract\\(\\) has parameter \\$expected with no value type specified in iterable type array\\.$#"
1955-
count: 1
1956-
path: tests/Utils/BufferedQueryTest.php
1957-
1958-
-
1959-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Utils\\\\BufferedQueryTest\\:\\:testExtract\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
1960-
count: 1
1961-
path: tests/Utils/BufferedQueryTest.php
1962-
19631888
-
19641889
message: "#^PHPDoc tag @var has no value type specified in iterable type array\\.$#"
19651890
count: 1
19661891
path: tests/Utils/BufferedQueryTest.php
19671892

1968-
-
1969-
message: "#^Parameter \\#1 \\$str of function str_split expects string, mixed given\\.$#"
1970-
count: 1
1971-
path: tests/Utils/BufferedQueryTest.php
1972-
19731893
-
19741894
message: "#^Parameter \\#1 \\$var of function count expects array\\|Countable, array\\<int, string\\>\\|false given\\.$#"
19751895
count: 1
19761896
path: tests/Utils/BufferedQueryTest.php
19771897

1978-
-
1979-
message: "#^Parameter \\#2 \\$split_length of function str_split expects int\\<1, max\\>, mixed given\\.$#"
1980-
count: 1
1981-
path: tests/Utils/BufferedQueryTest.php
1982-
1983-
-
1984-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Utils\\\\FormatterTest\\:\\:formatQueriesProviders\\(\\) return type has no value type specified in iterable type array\\.$#"
1985-
count: 1
1986-
path: tests/Utils/FormatterTest.php
1987-
1988-
-
1989-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Utils\\\\FormatterTest\\:\\:mergeFormatsProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
1990-
count: 1
1991-
path: tests/Utils/FormatterTest.php
1992-
1993-
-
1994-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Utils\\\\FormatterTest\\:\\:testFormat\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
1995-
count: 1
1996-
path: tests/Utils/FormatterTest.php
1997-
1998-
-
1999-
message: "#^Parameter \\#1 \\$query of static method PhpMyAdmin\\\\SqlParser\\\\Utils\\\\Formatter\\:\\:format\\(\\) expects string, mixed given\\.$#"
2000-
count: 3
2001-
path: tests/Utils/FormatterTest.php
2002-
20031898
-
20041899
message: "#^Parameter \\#1 \\$statement of static method PhpMyAdmin\\\\SqlParser\\\\Utils\\\\Misc\\:\\:getAliases\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\Statements\\\\SelectStatement, PhpMyAdmin\\\\SqlParser\\\\Statement\\|null given\\.$#"
20051900
count: 1
@@ -2010,16 +1905,6 @@ parameters:
20101905
count: 1
20111906
path: tests/Utils/MiscTest.php
20121907

2013-
-
2014-
message: "#^Method PhpMyAdmin\\\\SqlParser\\\\Tests\\\\Utils\\\\QueryTest\\:\\:getTablesProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
2015-
count: 1
2016-
path: tests/Utils/QueryTest.php
2017-
2018-
-
2019-
message: "#^Parameter \\#1 \\$list of class PhpMyAdmin\\\\SqlParser\\\\Parser constructor expects PhpMyAdmin\\\\SqlParser\\\\TokensList\\|PhpMyAdmin\\\\SqlParser\\\\UtfString\\|string\\|null, mixed given\\.$#"
2020-
count: 1
2021-
path: tests/Utils/QueryTest.php
2022-
20231908
-
20241909
message: "#^Parameter \\#2 \\$list of static method PhpMyAdmin\\\\SqlParser\\\\Utils\\\\Query\\:\\:getClause\\(\\) expects PhpMyAdmin\\\\SqlParser\\\\TokensList, PhpMyAdmin\\\\SqlParser\\\\TokensList\\|null given\\.$#"
20251910
count: 9

psalm-baseline.xml

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,9 +1613,6 @@
16131613
</UndefinedPropertyFetch>
16141614
</file>
16151615
<file src="tests/Builder/CreateStatementTest.php">
1616-
<MixedInferredReturnType occurrences="1">
1617-
<code>array</code>
1618-
</MixedInferredReturnType>
16191616
<PossiblyInvalidArgument occurrences="2">
16201617
<code>$stmt-&gt;fields</code>
16211618
<code>$stmt-&gt;fields</code>
@@ -1634,12 +1631,6 @@
16341631
</PossiblyNullReference>
16351632
</file>
16361633
<file src="tests/Components/ArrayObjTest.php">
1637-
<MixedArgument occurrences="1">
1638-
<code>$test</code>
1639-
</MixedArgument>
1640-
<MixedInferredReturnType occurrences="1">
1641-
<code>array</code>
1642-
</MixedInferredReturnType>
16431634
<UndefinedMethod occurrences="2">
16441635
<code>$components</code>
16451636
<code>$components</code>
@@ -1694,9 +1685,6 @@
16941685
</UndefinedMethod>
16951686
</file>
16961687
<file src="tests/Components/ExpressionTest.php">
1697-
<MixedArrayAccess occurrences="1">
1698-
<code>$errors[0][0]</code>
1699-
</MixedArrayAccess>
17001688
<PossiblyNullPropertyFetch occurrences="2">
17011689
<code>$component-&gt;expr</code>
17021690
<code>$component-&gt;expr</code>
@@ -1716,9 +1704,6 @@
17161704
</DocblockTypeContradiction>
17171705
</file>
17181706
<file src="tests/Components/LockExpressionTest.php">
1719-
<MixedArrayAccess occurrences="1">
1720-
<code>$errors[0][0]</code>
1721-
</MixedArrayAccess>
17221707
<RedundantConditionGivenDocblockType occurrences="2">
17231708
<code>assertNotNull</code>
17241709
<code>assertNotNull</code>
@@ -1735,25 +1720,6 @@
17351720
<code>$component</code>
17361721
</InvalidArgument>
17371722
</file>
1738-
<file src="tests/Lexer/ContextTest.php">
1739-
<MixedInferredReturnType occurrences="2">
1740-
<code>array</code>
1741-
<code>array</code>
1742-
</MixedInferredReturnType>
1743-
</file>
1744-
<file src="tests/Lexer/LexerTest.php">
1745-
<MixedInferredReturnType occurrences="1">
1746-
<code>array</code>
1747-
</MixedInferredReturnType>
1748-
</file>
1749-
<file src="tests/Misc/UtfStringTest.php">
1750-
<MixedArgument occurrences="1">
1751-
<code>$text</code>
1752-
</MixedArgument>
1753-
<MixedInferredReturnType occurrences="1">
1754-
<code>array</code>
1755-
</MixedInferredReturnType>
1756-
</file>
17571723
<file src="tests/Parser/LoadStatementTest.php">
17581724
<PossiblyNullReference occurrences="1">
17591725
<code>has</code>
@@ -1768,46 +1734,12 @@
17681734
<InvalidArgument occurrences="1">
17691735
<code>new stdClass()</code>
17701736
</InvalidArgument>
1771-
<MixedArrayAccess occurrences="1">
1772-
<code>$parserErrors[0][0]</code>
1773-
</MixedArrayAccess>
17741737
</file>
17751738
<file src="tests/TestCase.php">
17761739
<LessSpecificReturnStatement occurrences="1">
17771740
<code>$data</code>
17781741
</LessSpecificReturnStatement>
17791742
<MoreSpecificReturnType occurrences="1"/>
1780-
<UndefinedPropertyFetch occurrences="3">
1781-
<code>$err-&gt;ch</code>
1782-
<code>$err-&gt;pos</code>
1783-
<code>$err-&gt;token</code>
1784-
</UndefinedPropertyFetch>
1785-
</file>
1786-
<file src="tests/Utils/BufferedQueryTest.php">
1787-
<MixedArgument occurrences="2">
1788-
<code>$chunkSize</code>
1789-
<code>$query</code>
1790-
</MixedArgument>
1791-
<MixedInferredReturnType occurrences="1">
1792-
<code>array</code>
1793-
</MixedInferredReturnType>
1794-
<PossiblyFalseArgument occurrences="1">
1795-
<code>$chunks</code>
1796-
</PossiblyFalseArgument>
1797-
<PossiblyInvalidArrayAccess occurrences="1">
1798-
<code>$chunks[$i++]</code>
1799-
</PossiblyInvalidArrayAccess>
1800-
</file>
1801-
<file src="tests/Utils/FormatterTest.php">
1802-
<MixedArgument occurrences="3">
1803-
<code>$query</code>
1804-
<code>$query</code>
1805-
<code>$query</code>
1806-
</MixedArgument>
1807-
<MixedInferredReturnType occurrences="2">
1808-
<code>array</code>
1809-
<code>array</code>
1810-
</MixedInferredReturnType>
18111743
</file>
18121744
<file src="tests/Utils/MiscTest.php">
18131745
<ArgumentTypeCoercion occurrences="1">
@@ -1819,7 +1751,7 @@
18191751
</PossiblyNullArgument>
18201752
</file>
18211753
<file src="tests/Utils/QueryTest.php">
1822-
<MixedArgument occurrences="9">
1754+
<MixedArgument occurrences="8">
18231755
<code>$delimiter</code>
18241756
<code>$delimiter</code>
18251757
<code>$delimiter</code>
@@ -1828,11 +1760,7 @@
18281760
<code>$query</code>
18291761
<code>$query</code>
18301762
<code>$query</code>
1831-
<code>$query</code>
18321763
</MixedArgument>
1833-
<MixedInferredReturnType occurrences="1">
1834-
<code>array</code>
1835-
</MixedInferredReturnType>
18361764
<PossiblyNullArgument occurrences="16">
18371765
<code>$parser-&gt;list</code>
18381766
<code>$parser-&gt;list</code>

tests/Builder/CreateStatementTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ public function testBuilderPartitions(): void
228228
$this->assertEquals($query, $parser->statements[0]->build());
229229
}
230230

231+
/**
232+
* @return string[][]
233+
*/
231234
public function partitionQueriesProvider(): array
232235
{
233236
return [

tests/Components/ArrayObjTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ public function testParseType(): void
4040
}
4141

4242
/**
43-
* @param mixed $test
44-
*
4543
* @dataProvider parseProvider
4644
*/
47-
public function testParse($test): void
45+
public function testParse(string $test): void
4846
{
4947
$this->runParserTest($test);
5048
}
5149

50+
/**
51+
* @return string[][]
52+
*/
5253
public function parseProvider(): array
5354
{
5455
return [

tests/Lexer/ContextTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function testLoadClosest(string $context, ?string $expected): void
4343
Context::load('');
4444
}
4545

46+
/**
47+
* @return array<string, array<int, string|null>>
48+
* @psalm-return array<string, array{string, (string|null)}>
49+
*/
4650
public function contextLoadingProvider(): array
4751
{
4852
return [
@@ -89,6 +93,9 @@ public function testLoadAll(string $context): void
8993
Context::load('');
9094
}
9195

96+
/**
97+
* @return string[][]
98+
*/
9299
public function contextNamesProvider(): array
93100
{
94101
return [

tests/Lexer/LexerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public function testLex(string $test): void
5656
$this->runParserTest($test);
5757
}
5858

59+
/**
60+
* @return string[][]
61+
*/
5962
public function lexProvider(): array
6063
{
6164
return [

tests/Misc/UtfStringTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,20 @@ public function testToString(): void
8484
/**
8585
* Test access to string.
8686
*
87-
* @param mixed $text
88-
* @param mixed $pos10
89-
* @param mixed $pos20
90-
*
9187
* @dataProvider utf8StringsProvider
9288
*/
93-
public function testAccess($text, $pos10, $pos20): void
89+
public function testAccess(string $text, ?string $pos10, ?string $pos20): void
9490
{
9591
$str = new UtfString($text);
9692
$this->assertEquals($pos10, $str->offsetGet(10));
9793
$this->assertEquals($pos20, $str->offsetGet(20));
9894
$this->assertEquals($pos10, $str->offsetGet(10));
9995
}
10096

97+
/**
98+
* @return array<string, array<int, string|null>>
99+
* @psalm-return array<string, array{string, (string|null), (string|null)}>
100+
*/
101101
public function utf8StringsProvider(): array
102102
{
103103
return [

0 commit comments

Comments
 (0)