Skip to content

Commit 44a98e4

Browse files
authored
Merge pull request #42 from thecodingmachine/laravel-9-and-10
Adding compatibility with Laravel 9 and 10
2 parents 5ade008 + 00e9865 commit 44a98e4

File tree

8 files changed

+57
-83
lines changed

8 files changed

+57
-83
lines changed

.github/workflows/continuous_integration.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ jobs:
1515

1616
strategy:
1717
matrix:
18-
install-args: ['', '--prefer-lowest']
19-
php-version: ['7.4', '8.0']
18+
include:
19+
- install-args: "--prefer-lowest"
20+
php-version: "8.1"
21+
- install-args: ""
22+
php-version: "8.1"
23+
- install-args: ""
24+
php-version: "8.2"
2025
fail-fast: false
2126

2227
steps:

composer.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,27 @@
1313
{
1414
"name": "David N\u00e9grier",
1515
"email": "[email protected]",
16-
"homepage": "http://mouf-php.com"
16+
"homepage": "https://workadventu.re"
1717
}
1818
],
1919
"scripts": {
2020
"test": "phpunit"
2121
},
2222
"require": {
23-
"php": ">=7.2|^8",
24-
"thecodingmachine/graphqlite": "^6.0",
25-
"illuminate/console": "^5.7|^6.0|^7|^8|^9",
26-
"illuminate/container": "^5.7|^6.0|^7|^8|^9",
27-
"illuminate/support": "^5.7|^6.0|^7|^8|^9",
28-
"illuminate/cache": "^5.7|^6.0|^7|^8|^9",
23+
"php": "^8.1",
24+
"thecodingmachine/graphqlite": "^v6.2.1",
25+
"illuminate/console": "^9 || ^10",
26+
"illuminate/container": "^9 || ^10",
27+
"illuminate/support": "^9 || ^10",
28+
"illuminate/cache": "^9 || ^10",
2929
"symfony/psr-http-message-bridge": "^1.3.0 || ^2",
3030
"laminas/laminas-diactoros": "^2.2.2",
31-
"symfony/cache": "^4.3 || ^5 || ^6"
31+
"symfony/cache": "^4.3 || ^5 || ^6",
32+
"psr/container": "^2.0.2"
3233
},
3334
"require-dev": {
34-
"orchestra/testbench": "^3.7.7 || ^4 || ^5",
35-
"phpunit/phpunit": "^7.5.4 || ^8.3",
35+
"orchestra/testbench": "^7 || ^8",
36+
"phpunit/phpunit": "^9.6.6 || ^10.0.19",
3637
"ext-sqlite3": "*"
3738
},
3839
"autoload": {
@@ -47,7 +48,7 @@
4748
},
4849
"extra": {
4950
"branch-alias": {
50-
"dev-master": "6.0.x-dev"
51+
"dev-master": "6.1.x-dev"
5152
},
5253
"laravel": {
5354
"providers": [

phpunit.xml.dist

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
bootstrap="vendor/autoload.php"
12-
>
13-
<testsuites>
14-
<testsuite name="Test Suite">
15-
<directory>./tests/</directory>
16-
</testsuite>
17-
</testsuites>
18-
19-
<php>
20-
<env name="APP_KEY" value="9E6B382F19C53C5327840752500B0260"/>
21-
<env name="APP_DEBUG" value="true"/>
22-
</php>
23-
24-
<filter>
25-
<whitelist processUncoveredFilesFromWhitelist="true">
26-
<directory suffix=".php">src/</directory>
27-
<exclude>
28-
<directory suffix=".php">src/routes</directory>
29-
</exclude>
30-
</whitelist>
31-
</filter>
32-
<logging>
33-
<log type="coverage-html" target="build/coverage" />
34-
<log type="coverage-clover" target="build/logs/clover.xml"/>
35-
</logging>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
<exclude>
8+
<directory suffix=".php">src/routes</directory>
9+
</exclude>
10+
<report>
11+
<clover outputFile="build/logs/clover.xml"/>
12+
<html outputDirectory="build/coverage"/>
13+
</report>
14+
</coverage>
15+
<testsuites>
16+
<testsuite name="Test Suite">
17+
<directory>./tests/</directory>
18+
</testsuite>
19+
</testsuites>
20+
<php>
21+
<env name="APP_KEY" value="9E6B382F19C53C5327840752500B0260"/>
22+
<env name="APP_DEBUG" value="true"/>
23+
</php>
24+
<logging/>
3625
</phpunit>

src/Exceptions/ValidateException.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,11 @@ public static function create(string $message, string $argumentName)
1919
return $exception;
2020
}
2121

22-
/**
23-
* @return bool
24-
*/
25-
public function isClientSafe()
22+
public function isClientSafe(): bool
2623
{
2724
return true;
2825
}
2926

30-
/**
31-
* @return string
32-
*/
33-
public function getCategory()
34-
{
35-
return 'Validate';
36-
}
37-
3827

3928
/**
4029
* Returns the "extensions" object attached to the GraphQL error.

src/Mappers/PaginatorTypeMapper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace TheCodingMachine\GraphQLite\Laravel\Mappers;
66

77
use GraphQL\Type\Definition\InputObjectType;
8+
use GraphQL\Type\Definition\NamedType;
89
use GraphQL\Type\Definition\NullableType;
910
use GraphQL\Type\Definition\OutputType;
1011
use GraphQL\Type\Definition\Type;
@@ -196,11 +197,11 @@ public function canMapNameToType(string $typeName): bool
196197
*
197198
* @param string $typeName The name of the GraphQL type
198199
*
199-
* @return Type&((ResolvableMutableInputInterface&InputObjectType)|MutableObjectType|MutableInterfaceType)
200+
* @return Type&NamedType&((ResolvableMutableInputInterface&InputObjectType)|MutableObjectType|MutableInterfaceType)
200201
*
201202
* @throws CannotMapTypeExceptionInterface
202203
*/
203-
public function mapNameToType(string $typeName): Type
204+
public function mapNameToType(string $typeName): Type&NamedType
204205
{
205206
if (strpos($typeName, 'LengthAwarePaginatorResult_') === 0) {
206207
$subTypeName = substr($typeName, 27);

src/Mappers/Parameters/ParameterValidator.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use GraphQL\Type\Definition\InputType;
88
use GraphQL\Type\Definition\ResolveInfo;
9+
use GraphQL\Type\Definition\Type;
910
use Illuminate\Validation\Factory as ValidationFactory;
1011
use TheCodingMachine\GraphQLite\Exceptions\GraphQLAggregateException;
1112
use TheCodingMachine\GraphQLite\Laravel\Exceptions\ValidateException;
@@ -45,11 +46,8 @@ public function __construct(InputTypeParameterInterface $parameter, string $para
4546

4647
/**
4748
* @param array<string, mixed> $args
48-
* @param mixed $context
49-
*
50-
* @return mixed
5149
*/
52-
public function resolve(?object $source, array $args, $context, ResolveInfo $info)
50+
public function resolve(?object $source, array $args, mixed $context, ResolveInfo $info): mixed
5351
{
5452
$value = $this->parameter->resolve($source, $args, $context, $info);
5553

@@ -68,7 +66,7 @@ public function resolve(?object $source, array $args, $context, ResolveInfo $inf
6866
return $value;
6967
}
7068

71-
public function getType(): InputType
69+
public function getType(): InputType&Type
7270
{
7371
return $this->parameter->getType();
7472
}
@@ -78,10 +76,7 @@ public function hasDefaultValue(): bool
7876
return $this->parameter->hasDefaultValue();
7977
}
8078

81-
/**
82-
* @return mixed
83-
*/
84-
public function getDefaultValue()
79+
public function getDefaultValue(): mixed
8580
{
8681
return $this->parameter->getDefaultValue();
8782
}

src/SanePsr11ContainerAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function get($id)
5353
*
5454
* @return bool
5555
*/
56-
public function has($id)
56+
public function has($id): bool
5757
{
5858
if (class_exists($id) && !$this->container->has($id)) {
5959
try {

tests/Providers/GraphQLiteServiceProviderTest.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,19 @@ public function testValidator()
8787
$response->assertJson([
8888
'errors' => [
8989
[
90-
'message' => 'The foo must be a valid email address.',
9190
'extensions' => [
9291
'argument' => 'foo',
93-
'category' => 'Validate'
9492
],
9593
],
9694
[
97-
'message' => 'The bar must be greater than 42.',
9895
'extensions' => [
9996
'argument' => 'bar',
100-
'category' => 'Validate'
10197
],
10298
]
10399
]
104100
]);
101+
$this->assertStringContainsString('must be a valid email address.', $response->json('errors')[0]['message']);
102+
$this->assertStringContainsString('must be greater than 42.', $response->json('errors')[1]['message']);
105103

106104
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
107105
}
@@ -114,34 +112,31 @@ public function testValidatorMultiple()
114112
[
115113
'extensions' => [
116114
'argument' => 'foo',
117-
'category' => 'Validate'
118115
],
119116
],
120117
[
121-
'message' => 'The foo must be a valid IPv4 address.',
122118
'extensions' => [
123119
'argument' => 'foo',
124-
'category' => 'Validate'
125120
],
126121
]
127122
]
128123
]);
129124

130-
$this->assertStringContainsString('The foo must start with one of the following: 192', $response->json('errors')[0]['message']);
125+
$this->assertStringContainsString('must start with one of the following: 192', $response->json('errors')[0]['message']);
126+
$this->assertStringContainsString('must be a valid IPv4 address.', $response->json('errors')[1]['message']);
131127

132128
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
133129
$response = $this->json('POST', '/graphql', ['query' => '{ testValidatorMultiple(foo:"192.168.1") }']);
134130
$response->assertJson([
135131
'errors' => [
136132
[
137-
'message' => 'The foo must be a valid IPv4 address.',
138133
'extensions' => [
139134
'argument' => 'foo',
140-
'category' => 'Validate'
141135
],
142136
]
143137
]
144138
]);
139+
$this->assertStringContainsString('must be a valid IPv4 address.', $response->json('errors')[0]['message']);
145140

146141
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
147142

@@ -152,12 +147,11 @@ public function testValidatorMultiple()
152147
[
153148
'extensions' => [
154149
'argument' => 'foo',
155-
'category' => 'Validate'
156150
],
157151
]
158152
]
159153
]);
160-
$this->assertStringContainsString('The foo must start with one of the following: 192', $response->json('errors')[0]['message']);
154+
$this->assertStringContainsString('must start with one of the following: 192', $response->json('errors')[0]['message']);
161155

162156
$this->assertSame(400, $response->getStatusCode(), $response->getContent());
163157

0 commit comments

Comments
 (0)