Skip to content

Commit 62abd97

Browse files
committed
Add tests
1 parent 369e16c commit 62abd97

12 files changed

+279
-382
lines changed

.phpstan-dba-mysqli.cache

Lines changed: 3 additions & 247 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Rules/QueryPlanAnalyzerRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class QueryPlanAnalyzerRule implements Rule
3333
/**
3434
* @var list<string>
3535
*/
36-
private array $classMethods;
36+
public array $classMethods;
3737

3838
private ReflectionProvider $reflectionProvider;
3939

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace staabm\PHPStanDba\Tests\Fixture;
6+
7+
class StaticDatabase
8+
{
9+
public static function query(string $sql, int $fetchMode = null): mixed
10+
{
11+
return null;
12+
}
13+
14+
public static function prepare(string $sql): mixed
15+
{
16+
return null;
17+
}
18+
19+
public static function preparedQuery(string $sql, array $params = []): mixed
20+
{
21+
return null;
22+
}
23+
24+
public static function executeQuery(string $sql, array $params = []): mixed
25+
{
26+
return null;
27+
}
28+
}

tests/default/config/.phpunit-phpstan-dba-mysqli.cache

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/rules/QueryPlanAnalyzerRuleTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ protected function getRule(): Rule
4242
QueryReflection::getRuntimeConfiguration()->debugMode($this->debugMode);
4343
QueryReflection::getRuntimeConfiguration()->analyzeQueryPlans($this->numberOfAllowedUnindexedReads, $this->numberOfRowsNotRequiringIndex);
4444

45-
return self::getContainer()->getByType(QueryPlanAnalyzerRule::class);
45+
$rule = self::getContainer()->getByType(QueryPlanAnalyzerRule::class);
46+
$rule->classMethods[] = 'staabm\PHPStanDba\Tests\Fixture\StaticDatabase::query#0';
47+
$rule->classMethods[] = 'staabm\PHPStanDba\Tests\Fixture\StaticDatabase::executeQuery#0';
48+
return $rule;
4649
}
4750

4851
public static function getAdditionalConfigFiles(): array
@@ -94,6 +97,16 @@ public function testNotUsingIndex(): void
9497
28,
9598
$tip,
9699
],
100+
[
101+
"Query is not using an index on table 'ada'." . $proposal,
102+
79,
103+
$tip,
104+
],
105+
[
106+
"Query is not using an index on table 'ada'." . $proposal,
107+
80,
108+
$tip,
109+
],
97110
]);
98111
}
99112

@@ -140,6 +153,16 @@ public function testNotUsingIndexInDebugMode(): void
140153
28,
141154
$tip,
142155
],
156+
[
157+
"Query is not using an index on table 'ada'." . $proposal . "\n\nSimulated query: EXPLAIN SELECT * FROM `ada` WHERE email = 'test@example.com'",
158+
79,
159+
$tip,
160+
],
161+
[
162+
"Query is not using an index on table 'ada'." . $proposal . "\n\nSimulated query: EXPLAIN SELECT *,adaid FROM `ada` WHERE email = 'test@example.com'",
163+
80,
164+
$tip,
165+
],
143166
[
144167
'Unresolvable Query: Cannot simulate parameter value for type: mixed.',
145168
61,

0 commit comments

Comments
 (0)