Skip to content

Commit 958911d

Browse files
authored
Merge pull request #237 from brambaud/test/entity-base
Test EntityInterface return type
2 parents a38735e + 04e7340 commit 958911d

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace mglaman\PHPStanDrupal\Tests\Type;
6+
7+
use mglaman\PHPStanDrupal\Tests\AdditionalConfigFilesTrait;
8+
use PHPStan\Testing\TypeInferenceTestCase;
9+
10+
final class EntityDynamicReturnTypeTest extends TypeInferenceTestCase
11+
{
12+
use AdditionalConfigFilesTrait;
13+
14+
public function dataFileAsserts(): iterable
15+
{
16+
yield from $this->gatherAssertTypes(__DIR__ . '/data/entity.php');
17+
}
18+
19+
/**
20+
* @dataProvider dataFileAsserts
21+
* @param string $assertType
22+
* @param string $file
23+
* @param mixed ...$args
24+
*/
25+
public function testFileAsserts(
26+
string $assertType,
27+
string $file,
28+
...$args
29+
): void
30+
{
31+
$this->assertFileAsserts($assertType, $file, ...$args);
32+
}
33+
}

tests/src/Type/data/entity.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace DrupalEntity;
4+
5+
use Drupal\node\Entity\Node;
6+
use function PHPStan\Testing\assertType;
7+
8+
assertType('Drupal\node\Entity\Node', $node = Node::create(['type' => 'page', 'title' => 'foo']));
9+
assertType('Drupal\node\Entity\Node', $node->createDuplicate());
10+
assertType('Drupal\node\Entity\Node', $node->enforceIsNew());
11+
assertType('Drupal\node\Entity\Node', $node->enforceIsNew(TRUE));
12+
assertType('Drupal\node\Entity\Node', $node->enforceIsNew(FALSE));
13+
assertType('Drupal\node\Entity\Node', $node->setOriginalId(42));
14+
assertType('Drupal\node\Entity\Node', $node->setOriginalId('42'));
15+
assertType('Drupal\node\Entity\Node', $node->setOriginalId(NULL));
16+
assertType('Drupal\node\Entity\Node|null', Node::load(42));
17+
assertType('Drupal\node\Entity\Node|null', Node::load('42'));
18+
assertType('array<Drupal\node\Entity\Node>', Node::loadMultiple([42, 29]));
19+
assertType('array<Drupal\node\Entity\Node>', Node::loadMultiple(['42', '29']));
20+
assertType('array<Drupal\node\Entity\Node>', Node::loadMultiple(NULL));

0 commit comments

Comments
 (0)