Skip to content

Commit 2c4fa37

Browse files
committed
Add test data for #377
1 parent 479217b commit 2c4fa37

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
"autoload-dev": {
4747
"psr-4": {
4848
"mglaman\\PHPStanDrupal\\Tests\\": "tests/src/"
49-
}
49+
},
50+
"classmap": [
51+
"tests/src/Type/data"
52+
]
5053
},
5154
"extra": {
5255
"branch-alias": {

tests/src/Type/EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ final class EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest extends Ty
2121
public function dataFileAsserts(): iterable
2222
{
2323
yield from $this->gatherAssertTypes(__DIR__ . '/data/entity-type-manager.php');
24+
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-377.php');
2425
}
2526

2627
/**

tests/src/Type/data/bug-377.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace bug377;
4+
5+
use Drupal\Core\Entity\EntityStorageInterface;
6+
use Drupal\Core\Entity\EntityTypeManagerInterface;
7+
use function PHPStan\Testing\assertType;
8+
9+
class Foo {
10+
private EntityTypeManagerInterface $entityTypeManager;
11+
private EntityStorageInterface $myEntityStorage;
12+
13+
public function __construct(EntityTypeManagerInterface $entityTypeManager)
14+
{
15+
$this->entityTypeManager = $entityTypeManager;
16+
$this->myEntityStorage = $entityTypeManager->getStorage('node');
17+
}
18+
19+
public function storageType() {
20+
// @todo property typing overrides our internal typing to determine entity storage type.
21+
assertType('Drupal\Core\Entity\EntityStorageInterface', $this->myEntityStorage);
22+
assertType('Drupal\node\NodeStorage', $this->entityTypeManager->getStorage('node'));
23+
}
24+
25+
public function entityType() {
26+
$entity = $this->myEntityStorage->load('123');
27+
assertType('Drupal\Core\Entity\EntityInterface|null', $entity);
28+
}
29+
30+
}

tests/src/Type/data/entity-type-manager.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace EntityTypeManagerGetStorage;
44

55
use function PHPStan\Testing\assertType;
6-
use function PHPUnit\Framework\assertInstanceOf;
76

87
$etm = \Drupal::entityTypeManager();
98

0 commit comments

Comments
 (0)