Skip to content

Commit 9e8f44f

Browse files
authored
test(github): Test in PHP development mode and fix deprecation warnings (#1362)
1 parent fa8b191 commit 9e8f44f

11 files changed

Lines changed: 289 additions & 118 deletions

File tree

.github/workflows/testing.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
php-version: ${{ matrix.php-versions }}
6161
# Disable Xdebug for better performance.
6262
coverage: none
63+
ini-file: development
6364
extensions: ${{ env.extensions }}
6465

6566
- name: Get composer cache directory

tests/src/Kernel/DataProducer/Entity/Fields/Image/ImageDerivativeTest.php

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,50 @@ class ImageDerivativeTest extends GraphQLTestBase {
2020
*/
2121
protected static $modules = ['image', 'file'];
2222

23+
/**
24+
* The file system URI under test.
25+
*
26+
* @var string
27+
*/
28+
protected $fileUri;
29+
30+
/**
31+
* The file entity mock.
32+
*
33+
* @var \Drupal\file\FileInterface
34+
*/
35+
protected $file;
36+
37+
/**
38+
* The image style for testing.
39+
*
40+
* @var \Drupal\image\Entity\ImageStyle
41+
*/
42+
protected $style;
43+
44+
/**
45+
* A file entity mock that returns FALSE on access checking.
46+
*
47+
* @var \Drupal\file\FileInterface
48+
*/
49+
protected $fileNotAccessible;
50+
2351
/**
2452
* {@inheritdoc}
2553
*/
2654
public function setUp(): void {
2755
parent::setUp();
2856

29-
$this->file_uri = 'public://test.jpg';
57+
$this->fileUri = 'public://test.jpg';
3058

3159
$this->file = $this->getMockBuilder(FileInterface::class)
3260
->disableOriginalConstructor()
3361
->getMock();
3462

35-
$this->file->method('getFileUri')->willReturn($this->file_uri);
63+
$this->file->method('getFileUri')->willReturn($this->fileUri);
3664
$this->file->method('access')->willReturn((new AccessResultAllowed())->addCacheTags(['test_tag']));
37-
$this->file->width = 600;
38-
$this->file->height = 400;
65+
@$this->file->width = 600;
66+
@$this->file->height = 400;
3967

4068
$this->style = ImageStyle::create(['name' => 'test_style']);
4169
$effect = [
@@ -49,11 +77,11 @@ public function setUp(): void {
4977
$this->style->addImageEffect($effect);
5078
$this->style->save();
5179

52-
$this->file_not_accessible = $this->getMockBuilder(FileInterface::class)
80+
$this->fileNotAccessible = $this->getMockBuilder(FileInterface::class)
5381
->disableOriginalConstructor()
5482
->getMock();
5583

56-
$this->file_not_accessible->method('access')->willReturn((new AccessResultForbidden())->addCacheTags(['test_tag_forbidden']));
84+
$this->fileNotAccessible->method('access')->willReturn((new AccessResultForbidden())->addCacheTags(['test_tag_forbidden']));
5785
}
5886

5987
/**
@@ -69,7 +97,7 @@ public function testImageDerivative(): void {
6997

7098
$this->assertEquals(
7199
[
72-
'url' => $this->style->buildUrl($this->file_uri),
100+
'url' => $this->style->buildUrl($this->fileUri),
73101
'width' => 300,
74102
'height' => 200,
75103
],
@@ -83,7 +111,7 @@ public function testImageDerivative(): void {
83111
// Test that we don't get the derivative if we don't have access to the
84112
// original file, but we still get the access result cache tags.
85113
$result = $this->executeDataProducer('image_derivative', [
86-
'entity' => $this->file_not_accessible,
114+
'entity' => $this->fileNotAccessible,
87115
'style' => 'test_style',
88116
]);
89117

tests/src/Kernel/DataProducer/Entity/Fields/Image/ImageUrlTest.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,32 @@
1414
*/
1515
class ImageUrlTest extends GraphQLTestBase {
1616

17+
/**
18+
* The file entity mock.
19+
*
20+
* @var \Drupal\file\FileInterface
21+
*/
22+
protected $file;
23+
24+
/**
25+
* A file entity mock that returns FALSE on access checking.
26+
*
27+
* @var \Drupal\file\FileInterface
28+
*/
29+
protected $fileNotAccessible;
30+
31+
/**
32+
* The generated file URI.
33+
*
34+
* @var string
35+
*/
36+
protected $fileUri;
37+
1738
/**
1839
* {@inheritdoc}
1940
*/
2041
public function setUp(): void {
2142
parent::setUp();
22-
$this->dataProducerManager = $this->container->get('plugin.manager.graphql.data_producer');
2343

2444
$this->fileUri = \Drupal::service('file_url_generator')->generateAbsoluteString('public://test.jpg');
2545

@@ -30,11 +50,11 @@ public function setUp(): void {
3050
$this->file->method('getFileUri')->willReturn($this->fileUri);
3151
$this->file->method('access')->willReturn((new AccessResultAllowed())->addCacheTags(['test_tag']));
3252

33-
$this->file_not_accessible = $this->getMockBuilder(FileInterface::class)
53+
$this->fileNotAccessible = $this->getMockBuilder(FileInterface::class)
3454
->disableOriginalConstructor()
3555
->getMock();
3656

37-
$this->file_not_accessible->method('access')->willReturn((new AccessResultForbidden())->addCacheTags(['test_tag_forbidden']));
57+
$this->fileNotAccessible->method('access')->willReturn((new AccessResultForbidden())->addCacheTags(['test_tag_forbidden']));
3858
}
3959

4060
/**
@@ -53,7 +73,7 @@ public function testImageUrl(): void {
5373
// Test that we do not get a file we don't have access to, but the cache
5474
// tags are still added.
5575
$result = $this->executeDataProducer('image_url', [
56-
'entity' => $this->file_not_accessible,
76+
'entity' => $this->fileNotAccessible,
5777
]);
5878

5979
$this->assertNull($result);

tests/src/Kernel/DataProducer/EntityMultipleTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
66
use Drupal\node\NodeInterface;
7-
use Drupal\Core\Entity\EntityInterface;
8-
use Drupal\user\UserInterface;
97
use Drupal\node\Entity\NodeType;
108
use Drupal\node\Entity\Node;
119

@@ -42,18 +40,6 @@ class EntityMultipleTest extends GraphQLTestBase {
4240
public function setUp(): void {
4341
parent::setUp();
4442

45-
$this->entity = $this->getMockBuilder(NodeInterface::class)
46-
->disableOriginalConstructor()
47-
->getMock();
48-
49-
$this->entity_interface = $this->getMockBuilder(EntityInterface::class)
50-
->disableOriginalConstructor()
51-
->getMock();
52-
53-
$this->user = $this->getMockBuilder(UserInterface::class)
54-
->disableOriginalConstructor()
55-
->getMock();
56-
5743
$content_type = NodeType::create([
5844
'type' => 'lorem',
5945
'name' => 'ipsum',

tests/src/Kernel/DataProducer/EntityReferenceTest.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
66
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
77
use Drupal\Core\Field\FieldStorageDefinitionInterface;
8-
use Drupal\node\NodeInterface;
9-
use Drupal\Core\Entity\EntityInterface;
108
use Drupal\node\Entity\NodeType;
119
use Drupal\node\Entity\Node;
12-
use Drupal\user\UserInterface;
1310

1411
/**
1512
* Tests the entity_reference data producers.
@@ -19,24 +16,26 @@
1916
class EntityReferenceTest extends GraphQLTestBase {
2017
use EntityReferenceTestTrait;
2118

19+
/**
20+
* Test node that will be referenced.
21+
*
22+
* @var \Drupal\node\Entity\Node
23+
*/
24+
protected $referencedNode;
25+
26+
/**
27+
* Test node.
28+
*
29+
* @var \Drupal\node\Entity\Node
30+
*/
31+
protected $node;
32+
2233
/**
2334
* {@inheritdoc}
2435
*/
2536
public function setUp(): void {
2637
parent::setUp();
2738

28-
$this->entity = $this->getMockBuilder(NodeInterface::class)
29-
->disableOriginalConstructor()
30-
->getMock();
31-
32-
$this->entity_interface = $this->getMockBuilder(EntityInterface::class)
33-
->disableOriginalConstructor()
34-
->getMock();
35-
36-
$this->user = $this->getMockBuilder(UserInterface::class)
37-
->disableOriginalConstructor()
38-
->getMock();
39-
4039
$content_type1 = NodeType::create([
4140
'type' => 'test1',
4241
'name' => 'ipsum1',
@@ -51,19 +50,19 @@ public function setUp(): void {
5150

5251
$this->createEntityReferenceField('node', 'test1', 'field_test1_to_test2', 'test1 lable', 'node', 'default', [], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
5352

54-
$this->referenced_node = Node::create([
53+
$this->referencedNode = Node::create([
5554
'title' => 'Dolor2',
5655
'type' => 'test2',
5756
]);
58-
$this->referenced_node->save();
59-
$this->referenced_node
57+
$this->referencedNode->save();
58+
$this->referencedNode
6059
->addTranslation('fr', ['title' => 'Dolor2 French'])
6160
->save();
6261

6362
$this->node = Node::create([
6463
'title' => 'Dolor',
6564
'type' => 'test1',
66-
'field_test1_to_test2' => $this->referenced_node->id(),
65+
'field_test1_to_test2' => $this->referencedNode->id(),
6766
]);
6867
$this->node->save();
6968
}
@@ -78,7 +77,7 @@ public function testResolveEntityReference(): void {
7877
'access' => TRUE,
7978
'access_operation' => 'view',
8079
]);
81-
$this->assertEquals($this->referenced_node->id(), reset($result)->id());
80+
$this->assertEquals($this->referencedNode->id(), reset($result)->id());
8281
$this->assertEquals('Dolor2', reset($result)->label());
8382

8483
$result = $this->executeDataProducer('entity_reference', [
@@ -88,7 +87,7 @@ public function testResolveEntityReference(): void {
8887
'access_operation' => 'view',
8988
'language' => 'fr',
9089
]);
91-
$this->assertEquals($this->referenced_node->id(), reset($result)->id());
90+
$this->assertEquals($this->referencedNode->id(), reset($result)->id());
9291
$this->assertEquals('Dolor2 French', reset($result)->label());
9392
}
9493

tests/src/Kernel/DataProducer/EntityTest.php

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,41 @@ class EntityTest extends GraphQLTestBase {
2424
*/
2525
protected $node;
2626

27+
/**
28+
* Mocked test entity.
29+
*
30+
* @var \Drupal\node\NodeInterface|\PHPUnit\Framework\MockObject\MockObject
31+
*/
32+
protected $entity;
33+
34+
/**
35+
* Mocked test entity interface.
36+
*
37+
* @var \Drupal\Core\Entity\EntityInterface
38+
*/
39+
protected $entityInterface;
40+
41+
/**
42+
* Mocked test user.
43+
*
44+
* @var \Drupal\user\UserInterface
45+
*/
46+
protected $user;
47+
48+
/**
49+
* Translated test entity.
50+
*
51+
* @var \Drupal\node\NodeInterface
52+
*/
53+
protected $translationFr;
54+
55+
/**
56+
* Translated test entity.
57+
*
58+
* @var \Drupal\node\NodeInterface
59+
*/
60+
protected $translationDe;
61+
2762
/**
2863
* {@inheritdoc}
2964
*/
@@ -34,7 +69,7 @@ public function setUp(): void {
3469
->disableOriginalConstructor()
3570
->getMock();
3671

37-
$this->entity_interface = $this->getMockBuilder(EntityInterface::class)
72+
$this->entityInterface = $this->getMockBuilder(EntityInterface::class)
3873
->disableOriginalConstructor()
3974
->getMock();
4075

@@ -64,11 +99,11 @@ public function setUp(): void {
6499
]);
65100
$this->node->save();
66101

67-
$this->translation_fr = $this->node->addTranslation('fr', ['title' => 'sit amet fr']);
68-
$this->translation_fr->save();
102+
$this->translationFr = $this->node->addTranslation('fr', ['title' => 'sit amet fr']);
103+
$this->translationFr->save();
69104

70-
$this->translation_de = $this->node->addTranslation('de', ['title' => 'sit amet de']);
71-
$this->translation_de->save();
105+
$this->translationDe = $this->node->addTranslation('de', ['title' => 'sit amet de']);
106+
$this->translationDe->save();
72107

73108
\Drupal::service('content_translation.manager')->setEnabled('node', 'lorem', TRUE);
74109
}
@@ -103,7 +138,7 @@ public function testResolveChanged(): void {
103138

104139
$this->assertNull($this->executeDataProducer('entity_changed', [
105140
'format' => 'Y-m-d',
106-
'entity' => $this->entity_interface,
141+
'entity' => $this->entityInterface,
107142
]));
108143
}
109144

@@ -122,7 +157,7 @@ public function testResolveCreated(): void {
122157

123158
$this->assertNull($this->executeDataProducer('entity_created', [
124159
'format' => 'Y-m-d',
125-
'entity' => $this->entity_interface,
160+
'entity' => $this->entityInterface,
126161
]));
127162
}
128163

@@ -199,7 +234,7 @@ public function testResolveOwner(): void {
199234
]));
200235

201236
$this->assertNull($this->executeDataProducer('entity_owner', [
202-
'entity' => $this->entity_interface,
237+
'entity' => $this->entityInterface,
203238
]));
204239
}
205240

@@ -229,7 +264,7 @@ public function testResolvePublished(): void {
229264
]));
230265

231266
$this->assertNull($this->executeDataProducer('entity_published', [
232-
'entity' => $this->entity_interface,
267+
'entity' => $this->entityInterface,
233268
]));
234269
}
235270

0 commit comments

Comments
 (0)