Skip to content

Commit 4be1232

Browse files
authored
test(github): Test on PHP 8.3 and Drupal 10.2.x (#1389)
1 parent eb467d6 commit 4be1232

5 files changed

Lines changed: 55 additions & 19 deletions

File tree

.github/workflows/testing.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,31 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
php-versions: ['7.3', '7.4', '8.0', '8.1']
17+
# Keep testing Drupal 9 untill 6 months after it got unsupported, so
18+
# untill May 1st 2024.
1719
drupal-core: ['9.5.x']
1820
phpstan: ['0']
1921
include:
2022
# Extra runs to also test on latest Drupal 10.
2123
- php-versions: '8.1'
22-
drupal-core: '10.1.x'
24+
drupal-core: '10.2.x'
2325
phpstan: '0'
24-
# We only need to run PHPStan once on the latest PHP version.
2526
- php-versions: '8.2'
26-
drupal-core: '10.1.x'
27+
drupal-core: '10.2.x'
28+
phpstan: '0'
29+
# We only need to run PHPStan once on the latest PHP version.
30+
- php-versions: '8.3'
31+
drupal-core: '10.2.x'
2732
phpstan: '1'
2833
steps:
2934
- name: Checkout Drupal core
30-
uses: actions/checkout@v3
35+
uses: actions/checkout@v4
3136
with:
3237
repository: drupal/drupal
3338
ref: ${{ matrix.drupal-core }}
3439

3540
- name: Checkout graphql module
36-
uses: actions/checkout@v3
41+
uses: actions/checkout@v4
3742
with:
3843
path: modules/graphql
3944

@@ -48,7 +53,7 @@ jobs:
4853
key: cache-v1
4954

5055
- name: Cache PHP extensions
51-
uses: actions/cache@v3
56+
uses: actions/cache@v4
5257
with:
5358
path: ${{ steps.extcache.outputs.dir }}
5459
key: ${{ steps.extcache.outputs.key }}
@@ -68,7 +73,7 @@ jobs:
6873
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
6974

7075
- name: Cache composer dependencies
71-
uses: actions/cache@v3
76+
uses: actions/cache@v4
7277
with:
7378
path: ${{ steps.composercache.outputs.dir }}
7479
# Use composer.json for key, if composer.lock is not committed.
@@ -107,7 +112,7 @@ jobs:
107112
jangregor/phpstan-prophecy:^1.0.0 \
108113
phpstan/phpstan-phpunit:^1.0.0 \
109114
phpstan/extension-installer:^1.0
110-
composer --no-interaction --no-progress --with-all-dependencies upgrade drupal/coder:8.3.21
115+
composer --no-interaction --no-progress --with-all-dependencies upgrade drupal/coder:8.3.22
111116
112117
- name: Run PHPStan
113118
if: ${{ matrix.phpstan == '1' }}

src/GraphQL/Utility/FileUpload.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
193193
switch ($uploaded_file->getError()) {
194194
case UPLOAD_ERR_INI_SIZE:
195195
case UPLOAD_ERR_FORM_SIZE:
196+
// @todo Drupal 9 compatibility, needs to be converted to ByteSizeMarkup
197+
// later.
198+
// @phpstan-ignore-next-line
196199
$maxUploadSize = format_size($this->getMaxUploadSize($settings));
197200
$response->addViolation($this->t('The file @file could not be saved because it exceeds @maxsize, the maximum allowed size for uploads.', [
198201
'@file' => $uploaded_file->getClientOriginalName(),
@@ -268,6 +271,9 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
268271
$file->setSize(@filesize($temp_file_path));
269272

270273
// Validate against file_validate() first with the temporary path.
274+
// @todo Drupal 9 compatibility, needs to be converted to file validate
275+
// service later.
276+
// @phpstan-ignore-next-line
271277
$errors = file_validate($file, $validators);
272278
$maxResolution = $settings['max_resolution'] ?? 0;
273279
$minResolution = $settings['min_resolution'] ?? 0;
@@ -499,6 +505,9 @@ protected function prepareFilename(string $filename, array &$validators): string
499505
/** @var \Drupal\file\FileInterface $file */
500506
$file = $this->fileStorage->create([]);
501507
$file->setFilename($filename);
508+
// @todo Drupal 9 compatibility, needs to be converted to file
509+
// validator service later.
510+
// @phpstan-ignore-next-line
502511
$passes_validation = empty(file_validate_extensions($file, $validators['file_validate_extensions'][0]));
503512
}
504513
if (empty($validators['file_validate_extensions'][0]) || $passes_validation) {

tests/src/Kernel/DataProducer/EntityDefinitionTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class EntityDefinitionTest extends GraphQLTestBase {
211211
[
212212
'id' => 'created',
213213
'label' => 'Authored on',
214-
'description' => 'The time that the node was created.',
214+
'description' => 'The date and time that the content was created.',
215215
'type' => 'created',
216216
'required' => FALSE,
217217
'multiple' => FALSE,
@@ -496,6 +496,11 @@ enum FieldTypes {
496496
'entity_form_display_context' => $builder->fromContext('entity_form_display'),
497497
])
498498
);
499+
500+
// @todo Different description between Drupal 9 and 10, can be removed when
501+
// Drupal 9 support is dropped.
502+
$this->fullDefinitionResult['entityDefinition']['fields'][11]['description'] =
503+
$this->container->get('entity_field.manager')->getBaseFieldDefinitions('node')['created']->getDescription();
499504
}
500505

501506
/**

tests/src/Kernel/DataProducer/EntityReferenceTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,40 @@
55
use Drupal\Core\Field\FieldStorageDefinitionInterface;
66
use Drupal\node\Entity\Node;
77
use Drupal\node\Entity\NodeType;
8-
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
98
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
109

10+
// @todo Drupal 9 compatibility: use the deprecated trait for Drupal 9.
11+
if (strpos(\Drupal::VERSION, '9') === 0) {
12+
13+
/**
14+
* Helper trait for compatibility with Drupal 9.
15+
*
16+
* @phpcs:disable Drupal.Classes.ClassFileName.NoMatch
17+
*/
18+
trait EntityReferenceFieldCreationTrait {
19+
// @phpstan-ignore-next-line
20+
use \Drupal\Tests\field\Traits\EntityReferenceTestTrait;
21+
22+
}
23+
}
24+
else {
25+
26+
/**
27+
* Helper trait for compatibility with Drupal 10.
28+
*/
29+
trait EntityReferenceFieldCreationTrait {
30+
use \Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait;
31+
32+
}
33+
}
34+
1135
/**
1236
* Tests the entity_reference data producers.
1337
*
1438
* @group graphql
1539
*/
1640
class EntityReferenceTest extends GraphQLTestBase {
17-
use EntityReferenceTestTrait;
41+
use EntityReferenceFieldCreationTrait;
1842

1943
/**
2044
* Test node that will be referenced.

tests/src/Kernel/DataProducer/EntityTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,7 @@ public function testResolveEntityRendered(): void {
469469

470470
// @todo Add metadata check.
471471
// $this->assertContains('node:1', $metadata->getCacheTags());
472-
// Rendered output is slightly different in Drupal 8 vs. 9.
473-
[$version] = explode('.', \Drupal::VERSION, 2);
474-
if ($version == 8) {
475-
$this->assertStringContainsString('<a href="/node/1" rel="bookmark"><span>' . $this->node->getTitle() . '</span>', $result);
476-
}
477-
else {
478-
$this->assertMatchesRegularExpression('#<a href="/node/1" rel="bookmark">\s*<span>' . $this->node->getTitle() . '</span>#', $result);
479-
}
472+
$this->assertMatchesRegularExpression('#<a href="/node/1" rel="bookmark">\s*<span>' . $this->node->getTitle() . '</span>#', $result);
480473
}
481474

482475
}

0 commit comments

Comments
 (0)