Skip to content

Commit 8221c5f

Browse files
committed
Fix ServiceMapFactoryTest and error message in DrupalIntegrationTest
1 parent 9e108b2 commit 8221c5f

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

tests/src/DrupalIntegrationTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ public function testTestSuiteAutoloading() {
2121
__DIR__ . '/../fixtures/drupal/core/tests/TestSuites/UnitTestSuite.php',
2222
];
2323
foreach ($paths as $path) {
24+
$suiteName = basename($path, '.php');
2425
$errors = $this->runAnalyze($path);
25-
$this->assertCount(1, $errors->getErrors(), $path);
26-
$this->assertEquals('Unsafe usage of new static().', $errors->getErrors()[0]->getMessage());
27-
$this->assertCount(0, $errors->getInternalErrors(), print_r($errors->getInternalErrors(), true));
26+
self::assertCount(1, $errors->getErrors(), $path);
27+
self::assertEquals("Method Drupal\Tests\TestSuites\{$suiteName}::suite() should return static(Drupal\Tests\TestSuites\{$suiteName}) but return statement is missing.", $errors->getErrors()[0]->getMessage());
28+
self::assertCount(0, $errors->getInternalErrors(), print_r($errors->getInternalErrors(), true));
2829
}
2930

3031
// Abstract doesn't warn on static constructor.
3132
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/core/tests/TestSuites/TestSuiteBase.php');
32-
$this->assertCount(0, $errors->getErrors(), $path);
33-
$this->assertCount(0, $errors->getInternalErrors(), print_r($errors->getInternalErrors(), true));
33+
self::assertCount(0, $errors->getErrors());
34+
self::assertCount(0, $errors->getInternalErrors(), print_r($errors->getInternalErrors(), true));
3435
}
3536

3637
public function testDrupalTestInChildSiteContant() {

tests/src/ServiceMapFactoryTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace mglaman\PHPStanDrupal\Tests;
44

5+
use mglaman\PHPStanDrupal\Drupal\DrupalServiceDefinition;
6+
use mglaman\PHPStanDrupal\Drupal\ServiceMap;
57
use PHPUnit\Framework\TestCase;
68

79
final class ServiceMapFactoryTest extends TestCase
@@ -10,15 +12,15 @@ final class ServiceMapFactoryTest extends TestCase
1012
/**
1113
* @dataProvider getServiceProvider
1214
*
13-
* @covers \mglaman\PHPStanDrupal\DrupalServiceDefinition::__construct
14-
* @covers \mglaman\PHPStanDrupal\DrupalServiceDefinition::getClass
15-
* @covers \mglaman\PHPStanDrupal\DrupalServiceDefinition::isPublic
16-
* @covers \mglaman\PHPStanDrupal\DrupalServiceDefinition::getAlias
17-
* @covers \mglaman\PHPStanDrupal\DrupalServiceDefinition::getId
18-
* @covers \mglaman\PHPStanDrupal\ServiceMap::setDrupalServices
19-
* @covers \mglaman\PHPStanDrupal\ServiceMap::getService
15+
* @covers \mglaman\PHPStanDrupal\Drupal\DrupalServiceDefinition::__construct
16+
* @covers \mglaman\PHPStanDrupal\Drupal\DrupalServiceDefinition::getClass
17+
* @covers \mglaman\PHPStanDrupal\Drupal\DrupalServiceDefinition::isPublic
18+
* @covers \mglaman\PHPStanDrupal\Drupal\DrupalServiceDefinition::getAlias
19+
* @covers \mglaman\PHPStanDrupal\Drupal\DrupalServiceDefinition::getId
20+
* @covers \mglaman\PHPStanDrupal\Drupal\ServiceMap::setDrupalServices
21+
* @covers \mglaman\PHPStanDrupal\Drupal\ServiceMap::getService
2022
*/
21-
public function testFactory(string $id, callable $validator)
23+
public function testFactory(string $id, callable $validator): void
2224
{
2325
$service = new ServiceMap();
2426
$service->setDrupalServices([
@@ -49,8 +51,7 @@ function (?DrupalServiceDefinition $service): void {
4951
];
5052
yield [
5153
'entity_type.manager',
52-
function (?DrupalServiceDefinition $service): void {
53-
self::assertNotNull($service);
54+
function (DrupalServiceDefinition $service): void {
5455
self::assertEquals('entity_type.manager', $service->getId());
5556
self::assertEquals('Drupal\Core\Entity\EntityTypeManager', $service->getClass());
5657
self::assertTrue($service->isPublic());
@@ -66,8 +67,7 @@ function (?DrupalServiceDefinition $service): void {
6667
];
6768
yield [
6869
'config.storage.sync',
69-
function (?DrupalServiceDefinition $service): void {
70-
self::assertNotNull($service);
70+
function (DrupalServiceDefinition $service): void {
7171
self::assertEquals('config.storage.staging', $service->getAlias());
7272
}
7373
];

0 commit comments

Comments
 (0)