Skip to content

Commit

Permalink
test(github): Test on PHP 8.3 and Drupal 10.2.x (#1389)
Browse files Browse the repository at this point in the history
  • Loading branch information
klausi authored Jan 28, 2024
1 parent eb467d6 commit 4be1232
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,31 @@ jobs:
fail-fast: false
matrix:
php-versions: ['7.3', '7.4', '8.0', '8.1']
# Keep testing Drupal 9 untill 6 months after it got unsupported, so
# untill May 1st 2024.
drupal-core: ['9.5.x']
phpstan: ['0']
include:
# Extra runs to also test on latest Drupal 10.
- php-versions: '8.1'
drupal-core: '10.1.x'
drupal-core: '10.2.x'
phpstan: '0'
# We only need to run PHPStan once on the latest PHP version.
- php-versions: '8.2'
drupal-core: '10.1.x'
drupal-core: '10.2.x'
phpstan: '0'
# We only need to run PHPStan once on the latest PHP version.
- php-versions: '8.3'
drupal-core: '10.2.x'
phpstan: '1'
steps:
- name: Checkout Drupal core
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: drupal/drupal
ref: ${{ matrix.drupal-core }}

- name: Checkout graphql module
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: modules/graphql

Expand All @@ -48,7 +53,7 @@ jobs:
key: cache-v1

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

- name: Cache composer dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composercache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
Expand Down Expand Up @@ -107,7 +112,7 @@ jobs:
jangregor/phpstan-prophecy:^1.0.0 \
phpstan/phpstan-phpunit:^1.0.0 \
phpstan/extension-installer:^1.0
composer --no-interaction --no-progress --with-all-dependencies upgrade drupal/coder:8.3.21
composer --no-interaction --no-progress --with-all-dependencies upgrade drupal/coder:8.3.22
- name: Run PHPStan
if: ${{ matrix.phpstan == '1' }}
Expand Down
9 changes: 9 additions & 0 deletions src/GraphQL/Utility/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
switch ($uploaded_file->getError()) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
// @todo Drupal 9 compatibility, needs to be converted to ByteSizeMarkup
// later.
// @phpstan-ignore-next-line
$maxUploadSize = format_size($this->getMaxUploadSize($settings));
$response->addViolation($this->t('The file @file could not be saved because it exceeds @maxsize, the maximum allowed size for uploads.', [
'@file' => $uploaded_file->getClientOriginalName(),
Expand Down Expand Up @@ -268,6 +271,9 @@ public function saveFileUpload(UploadedFile $uploaded_file, array $settings): Fi
$file->setSize(@filesize($temp_file_path));

// Validate against file_validate() first with the temporary path.
// @todo Drupal 9 compatibility, needs to be converted to file validate
// service later.
// @phpstan-ignore-next-line
$errors = file_validate($file, $validators);
$maxResolution = $settings['max_resolution'] ?? 0;
$minResolution = $settings['min_resolution'] ?? 0;
Expand Down Expand Up @@ -499,6 +505,9 @@ protected function prepareFilename(string $filename, array &$validators): string
/** @var \Drupal\file\FileInterface $file */
$file = $this->fileStorage->create([]);
$file->setFilename($filename);
// @todo Drupal 9 compatibility, needs to be converted to file
// validator service later.
// @phpstan-ignore-next-line
$passes_validation = empty(file_validate_extensions($file, $validators['file_validate_extensions'][0]));
}
if (empty($validators['file_validate_extensions'][0]) || $passes_validation) {
Expand Down
7 changes: 6 additions & 1 deletion tests/src/Kernel/DataProducer/EntityDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class EntityDefinitionTest extends GraphQLTestBase {
[
'id' => 'created',
'label' => 'Authored on',
'description' => 'The time that the node was created.',
'description' => 'The date and time that the content was created.',
'type' => 'created',
'required' => FALSE,
'multiple' => FALSE,
Expand Down Expand Up @@ -496,6 +496,11 @@ enum FieldTypes {
'entity_form_display_context' => $builder->fromContext('entity_form_display'),
])
);

// @todo Different description between Drupal 9 and 10, can be removed when
// Drupal 9 support is dropped.
$this->fullDefinitionResult['entityDefinition']['fields'][11]['description'] =
$this->container->get('entity_field.manager')->getBaseFieldDefinitions('node')['created']->getDescription();
}

/**
Expand Down
28 changes: 26 additions & 2 deletions tests/src/Kernel/DataProducer/EntityReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,40 @@
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;

// @todo Drupal 9 compatibility: use the deprecated trait for Drupal 9.
if (strpos(\Drupal::VERSION, '9') === 0) {

/**
* Helper trait for compatibility with Drupal 9.
*
* @phpcs:disable Drupal.Classes.ClassFileName.NoMatch
*/
trait EntityReferenceFieldCreationTrait {
// @phpstan-ignore-next-line
use \Drupal\Tests\field\Traits\EntityReferenceTestTrait;

}
}
else {

/**
* Helper trait for compatibility with Drupal 10.
*/
trait EntityReferenceFieldCreationTrait {
use \Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait;

}
}

/**
* Tests the entity_reference data producers.
*
* @group graphql
*/
class EntityReferenceTest extends GraphQLTestBase {
use EntityReferenceTestTrait;
use EntityReferenceFieldCreationTrait;

/**
* Test node that will be referenced.
Expand Down
9 changes: 1 addition & 8 deletions tests/src/Kernel/DataProducer/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,7 @@ public function testResolveEntityRendered(): void {

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

}

0 comments on commit 4be1232

Please sign in to comment.