Skip to content

Commit 9faacf7

Browse files
committed
Clean up more tests, add TODOs for fixes.
1 parent 80612b1 commit 9faacf7

File tree

4 files changed

+57
-70
lines changed

4 files changed

+57
-70
lines changed

tests/src/DrupalIntegrationTest.php

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
final class DrupalIntegrationTest extends AnalyzerTestBase {
88

9+
// @todo move to generic autoloading test.
910
public function testInstallPhp(): void
1011
{
1112
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/core/install.php');
1213
$this->assertCount(0, $errors->getErrors());
1314
$this->assertCount(0, $errors->getInternalErrors());
1415
}
1516

17+
// @todo move to generic autoloading test.
1618
public function testTestSuiteAutoloading() {
1719
$paths = [
1820
__DIR__ . '/../fixtures/drupal/core/tests/TestSuites/FunctionalJavascriptTestSuite.php',
@@ -34,12 +36,14 @@ public function testTestSuiteAutoloading() {
3436
self::assertCount(0, $errors->getInternalErrors(), print_r($errors->getInternalErrors(), true));
3537
}
3638

39+
// @todo move to generic autoloading test.
3740
public function testDrupalTestInChildSiteContant() {
3841
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/modules/phpstan_fixtures/src/DrupalTestInChildSiteContant.php');
3942
$this->assertCount(0, $errors->getErrors());
4043
$this->assertCount(0, $errors->getInternalErrors());
4144
}
4245

46+
// @todo move to generic autoloading test.
4347
public function testExtensionReportsError(): void
4448
{
4549
$is_d9 = version_compare('9.0.0', \Drupal::VERSION) !== 1;
@@ -62,6 +66,7 @@ public function testExtensionReportsError(): void
6266
self::assertNotFalse(strpos($error->getMessage(), 'phpstan_fixtures/phpstan_fixtures.fetch.inc could not be loaded from Drupal\\Core\\Extension\\ModuleHandlerInterface::loadInclude'));
6367
}
6468

69+
// @todo move to generic autoloading test.
6570
public function testExtensionTestSuiteAutoloading(): void
6671
{
6772
$paths = [
@@ -79,46 +84,7 @@ public function testExtensionTestSuiteAutoloading(): void
7984
}
8085
}
8186

82-
public function testServiceMapping8()
83-
{
84-
if (version_compare('9.0.0', \Drupal::VERSION) !== 1) {
85-
self::markTestSkipped('Only tested on Drupal 8.x.x');
86-
}
87-
$errorMessages = [
88-
'The "entity.manager" service is deprecated. You should use the \'entity_type.manager\' service instead.',
89-
'Call to an undefined method Drupal\Core\Entity\EntityManager::thisMethodDoesNotExist().',
90-
'Call to deprecated method getDefinitions() of class Drupal\\Core\\Entity\\EntityManager:
91-
in drupal:8.0.0 and is removed from drupal:9.0.0.
92-
Use \\Drupal\\Core\\Entity\\EntityTypeManagerInterface::getDefinitions()
93-
instead.',
94-
'The "path.alias_manager" service is deprecated. Use "path_alias.manager" instead. See https://drupal.org/node/3092086',
95-
];
96-
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/modules/phpstan_fixtures/src/TestServicesMappingExtension.php');
97-
self::assertCount(count($errorMessages), $errors->getErrors());
98-
self::assertCount(0, $errors->getInternalErrors());
99-
foreach ($errors->getErrors() as $key => $error) {
100-
self::assertEquals($errorMessages[$key], $error->getMessage());
101-
}
102-
}
103-
104-
public function testServiceMapping9()
105-
{
106-
if (version_compare('9.0.0', \Drupal::VERSION) === 1) {
107-
self::markTestSkipped('Only tested on Drupal 9.x.x');
108-
}
109-
// @todo: the actual error should be the fact `entity.manager` does not exist.
110-
$errorMessages = [
111-
'\Drupal calls should be avoided in classes, use dependency injection instead',
112-
'\Drupal calls should be avoided in classes, use dependency injection instead',
113-
];
114-
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/modules/phpstan_fixtures/src/TestServicesMappingExtension.php');
115-
self::assertCount(count($errorMessages), $errors->getErrors());
116-
self::assertCount(0, $errors->getInternalErrors());
117-
foreach ($errors->getErrors() as $key => $error) {
118-
self::assertEquals($errorMessages[$key], $error->getMessage());
119-
}
120-
}
121-
87+
// @todo move to ???
12288
public function testAppRootPseudoService() {
12389
$is_d9 = version_compare('9.0.0', \Drupal::VERSION) !== 1;
12490
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/modules/phpstan_fixtures/src/AppRootParameter.php');
@@ -136,12 +102,14 @@ public function testAppRootPseudoService() {
136102
}
137103
}
138104

105+
// @todo move to generic autoloading test.
139106
public function testThemeSettingsFile() {
140107
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/core/modules/system/tests/themes/test_theme_settings/theme-settings.php');
141108
$this->assertCount(0, $errors->getErrors(), var_export($errors, TRUE));
142109
$this->assertCount(0, $errors->getInternalErrors(), var_export($errors, TRUE));
143110
}
144111

112+
// @todo needs to be a test for ModuleLoadInclude
145113
public function testModuleLoadInclude() {
146114
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/modules/module_load_include_fixture/module_load_include_fixture.module');
147115
$this->assertCount(0, $errors->getErrors(), var_export($errors, TRUE));

tests/src/DrushIntegrationTest.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,25 @@
22

33
namespace mglaman\PHPStanDrupal\Tests;
44

5-
final class DrushIntegrationTest extends AnalyzerTestBase
5+
use PHPStan\Rules\Functions\CallToNonExistentFunctionRule;
6+
7+
final class DrushIntegrationTest extends DrupalRuleTestCase
68
{
7-
/**
8-
* @dataProvider dataPaths
9-
*/
10-
public function testPaths($path) {
11-
$errors = $this->runAnalyze($path);
12-
$errorMessages = [
13-
'Call to deprecated function drush_is_windows():
14-
. Use \\Consolidation\\SiteProcess\\Util\\Escape.',
15-
];
16-
$this->assertCount(1, $errors->getErrors(), var_export($errors, TRUE));
17-
$this->assertCount(0, $errors->getInternalErrors(), var_export($errors, TRUE));
18-
foreach ($errors->getErrors() as $key => $error) {
19-
$this->assertEquals($errorMessages[$key], $error->getMessage());
20-
}
21-
}
229

23-
public function dataPaths(): \Generator
10+
protected function getRule(): \PHPStan\Rules\Rule
11+
{
12+
// @phpstan-ignore-next-line
13+
return new CallToNonExistentFunctionRule(
14+
$this->createReflectionProvider(),
15+
true
16+
);
17+
}
18+
19+
public function testPaths(): void
2420
{
25-
yield [__DIR__ . '/../fixtures/drupal/modules/drush_command/src/Commands/TestDrushCommands.php'];
21+
$this->analyse([
22+
__DIR__ . '/../fixtures/drupal/modules/drush_command/src/Commands/TestDrushCommands.php'
23+
], []);
2624
}
2725

2826
}

tests/src/Rules/DummyRule.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace mglaman\PHPStanDrupal\Tests\Rules;
4+
5+
use PhpParser\Node;
6+
use PHPStan\Analyser\Scope;
7+
8+
final class DummyRule implements \PHPStan\Rules\Rule
9+
{
10+
public function getNodeType(): string
11+
{
12+
return 'PhpParser\Node\Expr\FuncCall';
13+
}
14+
15+
public function processNode(Node $node, Scope $scope): array
16+
{
17+
return [];
18+
}
19+
}

tests/src/ServiceProviderAutoloadingTest.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,29 @@
22

33
namespace mglaman\PHPStanDrupal\Tests;
44

5-
final class ServiceProviderAutoloadingTest extends AnalyzerTestBase
5+
use mglaman\PHPStanDrupal\Tests\Rules\DummyRule;
6+
7+
final class ServiceProviderAutoloadingTest extends DrupalRuleTestCase
68
{
9+
10+
protected function getRule(): \PHPStan\Rules\Rule
11+
{
12+
return new DummyRule();
13+
}
14+
715
/**
8-
* @dataProvider dataEntitySamples
16+
* @dataProvider dataFixtures
917
*/
10-
public function testLoadingServiceProvider(string $path, int $count, array $errorMessages) {
11-
$errors = $this->runAnalyze($path);
12-
$this->assertCount($count, $errors->getErrors(), print_r($errors, true));
13-
$this->assertCount(0, $errors->getInternalErrors(), print_r($errors, true));
14-
foreach ($errors->getErrors() as $key => $error) {
15-
$this->assertEquals($errorMessages[$key], $error->getMessage());
16-
}
18+
public function testLoadingServiceProvider(string $path, array $errorMessages) {
19+
$this->analyse([$path], $errorMessages);
1720
}
1821

1922

20-
public function dataEntitySamples(): \Generator
23+
public function dataFixtures(): \Generator
2124
{
2225
yield [
2326
__DIR__ . '/../fixtures/drupal/modules/service_provider_test/src/ServiceProviderTestServiceProvider.php',
24-
1,
25-
['If condition is always true.']
27+
[]
2628
];
2729
}
2830
}

0 commit comments

Comments
 (0)