13
13
use PHPStan \Type \EntityTypeManagerGetStorageDynamicReturnTypeExtension ;
14
14
use PHPStan \Type \ObjectType ;
15
15
use PHPUnit \Framework \TestCase ;
16
+ use Prophecy \Prophet ;
16
17
17
18
final class EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest extends TestCase
18
19
{
20
+ /**
21
+ * @var Prophet
22
+ *
23
+ * @internal
24
+ */
25
+ private $ prophet ;
26
+
27
+ protected function setUp (): void
28
+ {
29
+ parent ::setUp ();
30
+ // @note we do not use phpspec/prophecy-phpunit due to conflicts with Drupal 8 PHPUnit.
31
+ $ this ->prophet = new Prophet ;
32
+ }
19
33
20
34
/**
21
35
* @covers \PHPStan\Type\EntityTypeManagerGetStorageDynamicReturnTypeExtension::__construct
@@ -35,35 +49,40 @@ public function testGetClass()
35
49
*/
36
50
public function testGetTypeFromMethodCall ($ entityType , $ storageClass )
37
51
{
52
+ // If we were passed a string, assume it is a class name to be mocked.
53
+ if (is_string ($ entityType )) {
54
+ $ entityType = $ this ->prophet ->prophesize ($ entityType )->reveal ();
55
+ }
56
+
38
57
$ x = new EntityTypeManagerGetStorageDynamicReturnTypeExtension ([
39
58
'node ' => 'Drupal\node\NodeStorage ' ,
40
59
'search_api_index ' => 'Drupal\search_api\Entity\SearchApiConfigEntityStorage ' ,
41
60
]);
42
61
43
- $ methodReflection = $ this ->prophesize (MethodReflection::class);
62
+ $ methodReflection = $ this ->prophet -> prophesize (MethodReflection::class);
44
63
$ methodReflection ->getName ()->willReturn ('getStorage ' );
45
64
46
- $ defaultObjectType = $ this ->prophesize (ObjectType::class);
65
+ $ defaultObjectType = $ this ->prophet -> prophesize (ObjectType::class);
47
66
$ defaultObjectType ->getClassName ()->willReturn ('Drupal\Core\Entity\EntityStorageInterface ' );
48
- $ variantsParametersAcceptor = $ this ->prophesize (ParametersAcceptor::class);
67
+ $ variantsParametersAcceptor = $ this ->prophet -> prophesize (ParametersAcceptor::class);
49
68
$ variantsParametersAcceptor ->getReturnType ()->willReturn ($ defaultObjectType ->reveal ());
50
69
$ methodReflection ->getVariants ()->willReturn ([$ variantsParametersAcceptor ->reveal ()]);
51
70
52
71
if ($ entityType === null ) {
53
72
$ this ->expectException (ShouldNotHappenException::class);
54
73
$ methodCall = new MethodCall (
55
- $ this ->prophesize (Expr::class)->reveal (),
74
+ $ this ->prophet -> prophesize (Expr::class)->reveal (),
56
75
'getStorage '
57
76
);
58
77
} else {
59
78
$ methodCall = new MethodCall (
60
- $ this ->prophesize (Expr::class)->reveal (),
79
+ $ this ->prophet -> prophesize (Expr::class)->reveal (),
61
80
'getStorage ' ,
62
81
[new Arg ($ entityType )]
63
82
);
64
83
}
65
84
66
- $ scope = $ this ->prophesize (Scope::class);
85
+ $ scope = $ this ->prophet -> prophesize (Scope::class);
67
86
68
87
$ type = $ x ->getTypeFromMethodCall (
69
88
$ methodReflection ->reveal (),
@@ -81,9 +100,9 @@ public function getEntityStorageProvider(): \Iterator
81
100
yield [new String_ ('user ' ), 'Drupal\Core\Entity\EntityStorageInterface ' ];
82
101
yield [new String_ ('search_api_index ' ), 'Drupal\search_api\Entity\SearchApiConfigEntityStorage ' ];
83
102
yield [null , null ];
84
- yield [$ this -> prophesize ( MethodCall::class)-> reveal () , 'Drupal\Core\Entity\EntityStorageInterface ' ];
85
- yield [$ this -> prophesize ( Expr \StaticCall::class)-> reveal () , 'Drupal\Core\Entity\EntityStorageInterface ' ];
86
- yield [$ this -> prophesize ( Expr \BinaryOp \Concat::class)-> reveal () , 'Drupal\Core\Entity\EntityStorageInterface ' ];
103
+ yield [MethodCall::class, 'Drupal\Core\Entity\EntityStorageInterface ' ];
104
+ yield [Expr \StaticCall::class, 'Drupal\Core\Entity\EntityStorageInterface ' ];
105
+ yield [Expr \BinaryOp \Concat::class, 'Drupal\Core\Entity\EntityStorageInterface ' ];
87
106
}
88
107
89
108
/**
@@ -94,11 +113,11 @@ public function testIsMethodSupported()
94
113
{
95
114
$ x = new EntityTypeManagerGetStorageDynamicReturnTypeExtension ([]);
96
115
97
- $ valid = $ this ->prophesize (MethodReflection::class);
116
+ $ valid = $ this ->prophet -> prophesize (MethodReflection::class);
98
117
$ valid ->getName ()->willReturn ('getStorage ' );
99
118
self ::assertTrue ($ x ->isMethodSupported ($ valid ->reveal ()));
100
119
101
- $ invalid = $ this ->prophesize (MethodReflection::class);
120
+ $ invalid = $ this ->prophet -> prophesize (MethodReflection::class);
102
121
$ invalid ->getName ()->willReturn ('getAccessControlHandler ' );
103
122
self ::assertFalse ($ x ->isMethodSupported ($ invalid ->reveal ()));
104
123
}
0 commit comments