From c738d0bab18c0c85048d129013919dccafb8fe8d Mon Sep 17 00:00:00 2001 From: Matt Glaman Date: Wed, 12 May 2021 14:23:29 -0500 Subject: [PATCH] Fix HEAD due SplString fix and deprecations --- tests/src/DrupalIntegrationTest.php | 8 +--- ...tStorageDynamicReturnTypeExtensionTest.php | 41 ++++++++++++++----- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/tests/src/DrupalIntegrationTest.php b/tests/src/DrupalIntegrationTest.php index a983e8a8..369646c5 100644 --- a/tests/src/DrupalIntegrationTest.php +++ b/tests/src/DrupalIntegrationTest.php @@ -42,8 +42,7 @@ public function testDrupalTestInChildSiteContant() { public function testExtensionReportsError() { $is_d9 = version_compare('9.0.0', \Drupal::VERSION) !== 1; $errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/modules/phpstan_fixtures/phpstan_fixtures.module'); - // @todo this only broke on D9. - self::assertCount($is_d9 ? 4 : 3, $errors->getErrors(), var_export($errors, true)); + self::assertCount(3, $errors->getErrors(), var_export($errors, true)); self::assertCount(0, $errors->getInternalErrors(), var_export($errors, true)); $errors = $errors->getErrors(); @@ -51,12 +50,7 @@ public function testExtensionReportsError() { self::assertEquals('If condition is always false.', $error->getMessage()); $error = array_shift($errors); self::assertEquals('Function phpstan_fixtures_MissingReturnRule() should return string but return statement is missing.', $error->getMessage()); - if ($is_d9) { - $error = array_shift($errors); - self::assertEquals('Binary operation "." between SplString and \'/core/includes…\' results in an error.', $error->getMessage()); - } $error = array_shift($errors); - self::assertNotFalse(strpos($error->getMessage(), 'phpstan_fixtures/phpstan_fixtures.fetch.inc could not be loaded from Drupal\\Core\\Extension\\ModuleHandlerInterface::loadInclude')); } diff --git a/tests/src/EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest.php b/tests/src/EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest.php index 2f007c32..34d7e7e7 100644 --- a/tests/src/EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest.php +++ b/tests/src/EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest.php @@ -13,9 +13,23 @@ use PHPStan\Type\EntityTypeManagerGetStorageDynamicReturnTypeExtension; use PHPStan\Type\ObjectType; use PHPUnit\Framework\TestCase; +use Prophecy\Prophet; final class EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest extends TestCase { + /** + * @var Prophet + * + * @internal + */ + private $prophet; + + protected function setUp(): void + { + parent::setUp(); + // @note we do not use phpspec/prophecy-phpunit due to conflicts with Drupal 8 PHPUnit. + $this->prophet = new Prophet; + } /** * @covers \PHPStan\Type\EntityTypeManagerGetStorageDynamicReturnTypeExtension::__construct @@ -35,35 +49,40 @@ public function testGetClass() */ public function testGetTypeFromMethodCall($entityType, $storageClass) { + // If we were passed a string, assume it is a class name to be mocked. + if (is_string($entityType)) { + $entityType = $this->prophet->prophesize($entityType)->reveal(); + } + $x = new EntityTypeManagerGetStorageDynamicReturnTypeExtension([ 'node' => 'Drupal\node\NodeStorage', 'search_api_index' => 'Drupal\search_api\Entity\SearchApiConfigEntityStorage', ]); - $methodReflection = $this->prophesize(MethodReflection::class); + $methodReflection = $this->prophet->prophesize(MethodReflection::class); $methodReflection->getName()->willReturn('getStorage'); - $defaultObjectType = $this->prophesize(ObjectType::class); + $defaultObjectType = $this->prophet->prophesize(ObjectType::class); $defaultObjectType->getClassName()->willReturn('Drupal\Core\Entity\EntityStorageInterface'); - $variantsParametersAcceptor = $this->prophesize(ParametersAcceptor::class); + $variantsParametersAcceptor = $this->prophet->prophesize(ParametersAcceptor::class); $variantsParametersAcceptor->getReturnType()->willReturn($defaultObjectType->reveal()); $methodReflection->getVariants()->willReturn([$variantsParametersAcceptor->reveal()]); if ($entityType === null) { $this->expectException(ShouldNotHappenException::class); $methodCall = new MethodCall( - $this->prophesize(Expr::class)->reveal(), + $this->prophet->prophesize(Expr::class)->reveal(), 'getStorage' ); } else { $methodCall = new MethodCall( - $this->prophesize(Expr::class)->reveal(), + $this->prophet->prophesize(Expr::class)->reveal(), 'getStorage', [new Arg($entityType)] ); } - $scope = $this->prophesize(Scope::class); + $scope = $this->prophet->prophesize(Scope::class); $type = $x->getTypeFromMethodCall( $methodReflection->reveal(), @@ -81,9 +100,9 @@ public function getEntityStorageProvider(): \Iterator yield [new String_('user'), 'Drupal\Core\Entity\EntityStorageInterface']; yield [new String_('search_api_index'), 'Drupal\search_api\Entity\SearchApiConfigEntityStorage']; yield [null, null]; - yield [$this->prophesize(MethodCall::class)->reveal(), 'Drupal\Core\Entity\EntityStorageInterface']; - yield [$this->prophesize(Expr\StaticCall::class)->reveal(), 'Drupal\Core\Entity\EntityStorageInterface']; - yield [$this->prophesize(Expr\BinaryOp\Concat::class)->reveal(), 'Drupal\Core\Entity\EntityStorageInterface']; + yield [MethodCall::class, 'Drupal\Core\Entity\EntityStorageInterface']; + yield [Expr\StaticCall::class, 'Drupal\Core\Entity\EntityStorageInterface']; + yield [Expr\BinaryOp\Concat::class, 'Drupal\Core\Entity\EntityStorageInterface']; } /** @@ -94,11 +113,11 @@ public function testIsMethodSupported() { $x = new EntityTypeManagerGetStorageDynamicReturnTypeExtension([]); - $valid = $this->prophesize(MethodReflection::class); + $valid = $this->prophet->prophesize(MethodReflection::class); $valid->getName()->willReturn('getStorage'); self::assertTrue($x->isMethodSupported($valid->reveal())); - $invalid = $this->prophesize(MethodReflection::class); + $invalid = $this->prophet->prophesize(MethodReflection::class); $invalid->getName()->willReturn('getAccessControlHandler'); self::assertFalse($x->isMethodSupported($invalid->reveal())); }