1313use PHPStan \Type \EntityTypeManagerGetStorageDynamicReturnTypeExtension ;
1414use PHPStan \Type \ObjectType ;
1515use PHPUnit \Framework \TestCase ;
16+ use Prophecy \Prophet ;
1617
1718final class EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest extends TestCase
1819{
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+ }
1933
2034 /**
2135 * @covers \PHPStan\Type\EntityTypeManagerGetStorageDynamicReturnTypeExtension::__construct
@@ -35,35 +49,40 @@ public function testGetClass()
3549 */
3650 public function testGetTypeFromMethodCall ($ entityType , $ storageClass )
3751 {
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+
3857 $ x = new EntityTypeManagerGetStorageDynamicReturnTypeExtension ([
3958 'node ' => 'Drupal\node\NodeStorage ' ,
4059 'search_api_index ' => 'Drupal\search_api\Entity\SearchApiConfigEntityStorage ' ,
4160 ]);
4261
43- $ methodReflection = $ this ->prophesize (MethodReflection::class);
62+ $ methodReflection = $ this ->prophet -> prophesize (MethodReflection::class);
4463 $ methodReflection ->getName ()->willReturn ('getStorage ' );
4564
46- $ defaultObjectType = $ this ->prophesize (ObjectType::class);
65+ $ defaultObjectType = $ this ->prophet -> prophesize (ObjectType::class);
4766 $ defaultObjectType ->getClassName ()->willReturn ('Drupal\Core\Entity\EntityStorageInterface ' );
48- $ variantsParametersAcceptor = $ this ->prophesize (ParametersAcceptor::class);
67+ $ variantsParametersAcceptor = $ this ->prophet -> prophesize (ParametersAcceptor::class);
4968 $ variantsParametersAcceptor ->getReturnType ()->willReturn ($ defaultObjectType ->reveal ());
5069 $ methodReflection ->getVariants ()->willReturn ([$ variantsParametersAcceptor ->reveal ()]);
5170
5271 if ($ entityType === null ) {
5372 $ this ->expectException (ShouldNotHappenException::class);
5473 $ methodCall = new MethodCall (
55- $ this ->prophesize (Expr::class)->reveal (),
74+ $ this ->prophet -> prophesize (Expr::class)->reveal (),
5675 'getStorage '
5776 );
5877 } else {
5978 $ methodCall = new MethodCall (
60- $ this ->prophesize (Expr::class)->reveal (),
79+ $ this ->prophet -> prophesize (Expr::class)->reveal (),
6180 'getStorage ' ,
6281 [new Arg ($ entityType )]
6382 );
6483 }
6584
66- $ scope = $ this ->prophesize (Scope::class);
85+ $ scope = $ this ->prophet -> prophesize (Scope::class);
6786
6887 $ type = $ x ->getTypeFromMethodCall (
6988 $ methodReflection ->reveal (),
@@ -81,9 +100,9 @@ public function getEntityStorageProvider(): \Iterator
81100 yield [new String_ ('user ' ), 'Drupal\Core\Entity\EntityStorageInterface ' ];
82101 yield [new String_ ('search_api_index ' ), 'Drupal\search_api\Entity\SearchApiConfigEntityStorage ' ];
83102 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 ' ];
87106 }
88107
89108 /**
@@ -94,11 +113,11 @@ public function testIsMethodSupported()
94113 {
95114 $ x = new EntityTypeManagerGetStorageDynamicReturnTypeExtension ([]);
96115
97- $ valid = $ this ->prophesize (MethodReflection::class);
116+ $ valid = $ this ->prophet -> prophesize (MethodReflection::class);
98117 $ valid ->getName ()->willReturn ('getStorage ' );
99118 self ::assertTrue ($ x ->isMethodSupported ($ valid ->reveal ()));
100119
101- $ invalid = $ this ->prophesize (MethodReflection::class);
120+ $ invalid = $ this ->prophet -> prophesize (MethodReflection::class);
102121 $ invalid ->getName ()->willReturn ('getAccessControlHandler ' );
103122 self ::assertFalse ($ x ->isMethodSupported ($ invalid ->reveal ()));
104123 }
0 commit comments