-
-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathServiceIdTypeTest.php
More file actions
64 lines (57 loc) · 2.13 KB
/
ServiceIdTypeTest.php
File metadata and controls
64 lines (57 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php declare(strict_types=1);
namespace mglaman\PHPStanDrupal\Tests\Type;
use Drupal\Core\Entity\EntityTypeManager;
use mglaman\PHPStanDrupal\Drupal\ServiceMap;
use mglaman\PHPStanDrupal\Drupal\ServiceMapStaticAccessor;
use mglaman\PHPStanDrupal\Tests\AdditionalConfigFilesTrait;
use PHPStan\Testing\PHPStanTestCase;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\VerbosityLevel;
final class ServiceIdTypeTest extends PHPStanTestCase {
use AdditionalConfigFilesTrait;
public function dataAccepts(): iterable
{
yield 'self' => [
new \mglaman\PHPStanDrupal\Type\ServiceIdType(),
new \mglaman\PHPStanDrupal\Type\ServiceIdType(),
TrinaryLogic::createYes(),
];
yield 'valid service' => [
new \mglaman\PHPStanDrupal\Type\ServiceIdType(),
new ConstantStringType('entity_type.manager'),
TrinaryLogic::createYes(),
];
yield 'invalid service' => [
new \mglaman\PHPStanDrupal\Type\ServiceIdType(),
new ConstantStringType('foo.manager'),
TrinaryLogic::createMaybe(),
];
yield 'generic string' => [
new \mglaman\PHPStanDrupal\Type\ServiceIdType(),
new StringType(),
TrinaryLogic::createMaybe(),
];
}
/**
* @dataProvider dataAccepts
*/
public function testAccepts(\mglaman\PHPStanDrupal\Type\ServiceIdType $type, Type $otherType, TrinaryLogic $expectedResult): void
{
$serviceMap = new ServiceMap();
$serviceMap->setDrupalServices([
'entity_type.manager' => [
'class' => EntityTypeManager::class
],
]);
ServiceMapStaticAccessor::registerInstance($serviceMap);
$actualResult = $type->accepts($otherType, true);
self::assertSame(
$expectedResult->describe(),
$actualResult->describe(),
sprintf('%s -> accepts(%s)', $type->describe(VerbosityLevel::precise()), $otherType->describe(VerbosityLevel::precise())),
);
}
}