Skip to content

Commit 1ea8292

Browse files
authored
test(drupal): Switch to Drupal core 9.4 testing (#1287)
1 parent d1fc8d7 commit 1ea8292

File tree

5 files changed

+88
-61
lines changed

5 files changed

+88
-61
lines changed

.github/workflows/testing.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
php-versions: ['7.3', '7.4', '8.0', '8.1']
17-
drupal-core: ['9.3.x']
16+
php-versions: ['7.3', '7.4', '8.0']
17+
drupal-core: ['9.4.x']
18+
phpstan: ['0']
1819
include:
20+
# We only need to run PHPStan once on the latest PHP version.
21+
- php-versions: '8.1'
22+
drupal-core: '9.4.x'
23+
phpstan: '1'
1924
# Extra run to also test on latest Drupal 10 and PHP 8.1.
2025
- php-versions: '8.1'
2126
drupal-core: '10.0.x'
27+
phpstan: '0'
2228
steps:
2329
- name: Checkout Drupal core
2430
uses: actions/checkout@v2
@@ -79,7 +85,7 @@ jobs:
7985
run: composer --no-interaction --no-progress require \
8086
webonyx/graphql-php:^14.8 \
8187
drupal/typed_data:^1.0 \
82-
phpstan/phpstan:^1.4.6 \
88+
phpstan/phpstan:^1.7.14 \
8389
mglaman/phpstan-drupal:^1.1.2 \
8490
phpstan/phpstan-deprecation-rules:^1.0.0 \
8591
jangregor/phpstan-prophecy:^1.0.0 \
@@ -103,8 +109,7 @@ jobs:
103109
SIMPLETEST_DB: "sqlite://localhost/:memory:"
104110

105111
- name: Run PHPStan
106-
run: |
107-
cd modules/graphql && ../../vendor/bin/phpstan analyse
112+
run: if [[ ${{ matrix.phpstan }} == "1" ]]; then cd modules/graphql && ../../vendor/bin/phpstan analyse; fi
108113

109114
- name: Run PHPCS
110115
run: |

phpstan.neon

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ parameters:
66
customRulesetUsed: true
77
paths:
88
- .
9-
# We test with PHPStan on Drupal 8 and 9 and might have different ignored
10-
# errors on both.
11-
reportUnmatchedIgnoredErrors: false
129
# We inherit a lot of Drupal core docs that don't specify iterable types on
1310
# arrays, not sure we can fix this in a good way.
1411
checkMissingIterableValueType: false
1512
# Not sure we can specify generic types properly with Drupal coding standards
1613
# yet, disable for now.
1714
checkGenericClassInNonGenericObjectType: false
18-
# Exclude the RouteLoad producer because the redirect module is not D10
19-
# compatible so we are not downloading it.
2015
excludePaths:
16+
# Exclude the RouteLoad producer because the redirect module is not D10
17+
# compatible so we are not downloading it.
2118
- src/Plugin/GraphQL/DataProducer/Routing/RouteLoad.php
19+
# This file only exists for Drupal 10 compatibility, ignore it for now.
20+
- tests/src/Traits/CompatibleLoggerTrait10.php
2221
ignoreErrors:
2322
# @todo Ignore phpstan-drupal extension's rules for now, activate later.
2423
- '#\Drupal calls should be avoided in classes, use dependency injection instead#'
@@ -38,35 +37,9 @@ parameters:
3837
message: "#^Method Drupal\\\\graphql\\\\Plugin\\\\LanguageNegotiation\\\\OperationLanguageNegotiation\\:\\:getLangcode\\(\\) should return string but returns false\\.$#"
3938
count: 1
4039
path: src/Plugin/LanguageNegotiation/OperationLanguageNegotiation.php
41-
- "#^Parameter .+ of method Drupal\\\\Core\\\\Entity\\\\Query\\\\QueryInterface\\:\\:range\\(\\) expects null, int given\\.$#"
4240
# We forgot to use return type hints on some interfaces, cannot be changed
4341
# in stable 4.0.
4442
# @todo use return type hints everywhere for 5.0.
45-
-
46-
message: "#^Method Drupal\\\\graphql\\\\Entity\\\\ServerInterface\\:\\:addPersistedQueryInstance\\(\\) has no return typehint specified\\.$#"
47-
count: 1
48-
path: src/Entity/ServerInterface.php
49-
50-
-
51-
message: "#^Method Drupal\\\\graphql\\\\Entity\\\\ServerInterface\\:\\:removePersistedQueryInstance\\(\\) has no return typehint specified\\.$#"
52-
count: 1
53-
path: src/Entity/ServerInterface.php
54-
55-
-
56-
message: "#^Method Drupal\\\\graphql\\\\Entity\\\\ServerInterface\\:\\:removeAllPersistedQueryInstances\\(\\) has no return typehint specified\\.$#"
57-
count: 1
58-
path: src/Entity/ServerInterface.php
59-
60-
-
61-
message: "#^Method Drupal\\\\graphql\\\\Plugin\\\\PersistedQueryPluginInterface\\:\\:setWeight\\(\\) has no return typehint specified\\.$#"
62-
count: 1
63-
path: src/Plugin/PersistedQueryPluginInterface.php
64-
65-
-
66-
message: "#^Method Drupal\\\\graphql\\\\Plugin\\\\SchemaExtensionPluginInterface\\:\\:registerResolvers\\(\\) has no return typehint specified\\.$#"
67-
count: 1
68-
path: src/Plugin/SchemaExtensionPluginInterface.php
69-
7043
-
7144
message: "#^Method Drupal\\\\graphql\\\\Plugin\\\\PersistedQueryPluginInterface\\:\\:setWeight\\(\\) has no return type specified\\.$#"
7245
count: 1
@@ -91,8 +64,3 @@ parameters:
9164
message: "#^Method Drupal\\\\graphql\\\\Entity\\\\ServerInterface\\:\\:removePersistedQueryInstance\\(\\) has no return type specified\\.$#"
9265
count: 1
9366
path: src/Entity/ServerInterface.php
94-
95-
-
96-
message: "#^Unable to resolve the template type ExpectedType in call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\)$#"
97-
count: 1
98-
path: tests/src/Kernel/ResolverBuilderTest.php

tests/src/Kernel/Framework/LoggerTest.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Drupal\Tests\graphql\Kernel\Framework;
44

5-
use Drupal\Core\Logger\RfcLoggerTrait;
65
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
6+
use Drupal\Tests\graphql\Traits\CompatibleLoggerTrait;
77
use Psr\Log\LoggerInterface;
88

99
/**
@@ -13,14 +13,7 @@
1313
*/
1414
class LoggerTest extends GraphQLTestBase implements LoggerInterface {
1515

16-
use RfcLoggerTrait;
17-
18-
/**
19-
* Loggers calls.
20-
*
21-
* @var array
22-
*/
23-
protected $loggerCalls = [];
16+
use CompatibleLoggerTrait;
2417

2518
/**
2619
* {@inheritdoc}
@@ -50,17 +43,6 @@ protected function setUp(): void {
5043
$this->container->get('logger.factory')->addLogger($this);
5144
}
5245

53-
/**
54-
* {@inheritdoc}
55-
*/
56-
public function log($level, $message, array $context = []) {
57-
$this->loggerCalls[] = [
58-
'level' => $level,
59-
'message' => $message,
60-
'context' => $context,
61-
];
62-
}
63-
6446
/**
6547
* Test if invariant violation errors are logged.
6648
*/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Drupal\Tests\graphql\Traits;
4+
5+
use Drupal\Core\Logger\RfcLoggerTrait;
6+
7+
// The logger trait has a different function signature in Drupal 10, so we need
8+
// this hack to register a compatible trait for both Drupal 9 and 10.
9+
[$version] = explode('.', \Drupal::VERSION, 2);
10+
if ($version >= 10) {
11+
require_once __DIR__ . '/CompatibleLoggerTrait10.php';
12+
}
13+
else {
14+
/**
15+
* Drupal 9 compatible.
16+
*/
17+
trait CompatibleLoggerTrait {
18+
use RfcLoggerTrait;
19+
20+
/**
21+
* Collected loggers calls.
22+
*
23+
* @var array
24+
*/
25+
protected $loggerCalls = [];
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function log($level, $message, array $context = []) {
31+
$this->loggerCalls[] = [
32+
'level' => $level,
33+
'message' => $message,
34+
'context' => $context,
35+
];
36+
}
37+
38+
}
39+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Drupal\Tests\graphql\Traits;
4+
5+
use Drupal\Core\Logger\RfcLoggerTrait;
6+
7+
/**
8+
* Drupal 10 compatible.
9+
*/
10+
// phpcs:ignore
11+
trait CompatibleLoggerTrait {
12+
use RfcLoggerTrait;
13+
14+
/**
15+
* Collected loggers calls.
16+
*
17+
* @var array
18+
*/
19+
protected $loggerCalls = [];
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
// phpcs:ignore
25+
public function log($level, string|\Stringable $message, array $context = []): void {
26+
$this->loggerCalls[] = [
27+
'level' => $level,
28+
'message' => $message,
29+
'context' => $context,
30+
];
31+
}
32+
33+
}

0 commit comments

Comments
 (0)