Skip to content

Commit e0dacc2

Browse files
authored
test(phpunit): Replace deprecated getMockForAbstractClass() and getName() calls (#1415)
1 parent 75dd0a4 commit e0dacc2

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

.github/workflows/testing.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
# Pin the exact Coder version to upgrade manually when we want to.
106106
run: |
107107
composer --no-interaction --no-progress require \
108-
phpstan/phpstan:^1.11.2 \
108+
phpstan/phpstan:^1.11.9 \
109109
mglaman/phpstan-drupal:^1.1.2 \
110110
phpstan/phpstan-deprecation-rules:^1.0.0 \
111111
jangregor/phpstan-prophecy:^1.0.0 \

src/Plugin/GraphQL/DataProducer/Entity/Fields/Image/ImageDerivative.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ public function resolve(FileInterface $entity = NULL, $style, RefinableCacheable
9898
$metadata->addCacheableDependency($access);
9999
if ($access->isAllowed() && $image_style = ImageStyle::load($style)) {
100100

101-
// @phpstan-ignore-next-line
102101
$width = $entity->width;
103-
// @phpstan-ignore-next-line
104102
$height = $entity->height;
105103

104+
// @phpstan-ignore-next-line
106105
if (empty($width) || empty($height)) {
107106
/** @var \Drupal\Core\Image\ImageInterface $image */
108107
$image = \Drupal::service('image.factory')->get($entity->getFileUri());

tests/src/Kernel/AlterableSchemaTest.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Drupal\Tests\graphql\Kernel;
44

55
use Drupal\graphql\GraphQL\ResolverRegistry;
6-
use Drupal\graphql\Plugin\GraphQL\SchemaExtension\SdlSchemaExtensionPluginBase;
6+
use Drupal\graphql\Plugin\SchemaExtensionPluginInterface;
77
use Drupal\graphql\Plugin\SchemaExtensionPluginManager;
88
use Drupal\Tests\graphql\Kernel\Schema\AlterableComposableTestSchema;
99

@@ -148,17 +148,17 @@ protected function mockSchema($id, $schema, array $extensions = []): void {
148148
->getMock();
149149

150150
// Adds extra extension in order to test alter extension data event.
151-
$extensions['graphql_alterable_schema_test'] = $this->getMockBuilder(SdlSchemaExtensionPluginBase::class)
152-
->disableOriginalConstructor()
153-
->onlyMethods(['getBaseDefinition', 'getExtensionDefinition'])
154-
->getMockForAbstractClass();
151+
$extensions['graphql_alterable_schema_test'] = $this->getMockBuilder(SchemaExtensionPluginInterface::class)
152+
->getMock();
155153

156154
$extensions['graphql_alterable_schema_test']->expects(static::any())
157155
->method('getBaseDefinition')
158156
->willReturn('');
159157

160158
// Different extension definition for different tests.
161-
switch ($this->getName()) {
159+
// PHPUnit compatibility: remove once support for Drupal 10.2 is dropped.
160+
$methodName = method_exists($this, 'name') ? 'name' : 'getName';
161+
switch ($this->$methodName()) {
162162
case 'testEmptySchemaExtensionAlteredQueryResultPropertyAdded':
163163
$extensionDefinition = '';
164164
break;
@@ -193,7 +193,7 @@ protected function mockSchema($id, $schema, array $extensions = []): void {
193193
$this->container->get('event_dispatcher'),
194194
])
195195
->onlyMethods(['getSchemaDefinition', 'getResolverRegistry'])
196-
->getMockForAbstractClass();
196+
->getMock();
197197

198198
$this->schema->expects(static::any())
199199
->method('getSchemaDefinition')

tests/src/Traits/MockingTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protected function mockSchema($id, $schema, array $extensions = []): void {
145145
['development' => FALSE],
146146
])
147147
->onlyMethods(['getSchemaDefinition', 'getResolverRegistry'])
148-
->getMockForAbstractClass();
148+
->getMock();
149149

150150
$this->schema->expects(static::any())
151151
->method('getSchemaDefinition')

0 commit comments

Comments
 (0)