Skip to content

Commit 74e75c4

Browse files
authored
Merge pull request #173 from mglaman/phpspec-prophecy-trait
Fix HEAD due to upstream fix and deprecations on prophesize
2 parents 5c32c12 + c738d0b commit 74e75c4

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

tests/src/DrupalIntegrationTest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,15 @@ public function testDrupalTestInChildSiteContant() {
4242
public function testExtensionReportsError() {
4343
$is_d9 = version_compare('9.0.0', \Drupal::VERSION) !== 1;
4444
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/modules/phpstan_fixtures/phpstan_fixtures.module');
45-
// @todo this only broke on D9.
46-
self::assertCount($is_d9 ? 4 : 3, $errors->getErrors(), var_export($errors, true));
45+
self::assertCount(3, $errors->getErrors(), var_export($errors, true));
4746
self::assertCount(0, $errors->getInternalErrors(), var_export($errors, true));
4847

4948
$errors = $errors->getErrors();
5049
$error = array_shift($errors);
5150
self::assertEquals('If condition is always false.', $error->getMessage());
5251
$error = array_shift($errors);
5352
self::assertEquals('Function phpstan_fixtures_MissingReturnRule() should return string but return statement is missing.', $error->getMessage());
54-
if ($is_d9) {
55-
$error = array_shift($errors);
56-
self::assertEquals('Binary operation "." between SplString and \'/core/includes…\' results in an error.', $error->getMessage());
57-
}
5853
$error = array_shift($errors);
59-
6054
self::assertNotFalse(strpos($error->getMessage(), 'phpstan_fixtures/phpstan_fixtures.fetch.inc could not be loaded from Drupal\\Core\\Extension\\ModuleHandlerInterface::loadInclude'));
6155
}
6256

tests/src/EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,23 @@
1313
use PHPStan\Type\EntityTypeManagerGetStorageDynamicReturnTypeExtension;
1414
use PHPStan\Type\ObjectType;
1515
use PHPUnit\Framework\TestCase;
16+
use Prophecy\Prophet;
1617

1718
final 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

Comments
 (0)