Skip to content

Commit a79c97a

Browse files
committed
Use different approach to simulate a TypeError
Using a "real PHP error" would always trigger PHPStan to actually report it and this abort the travis testing pipeline.
1 parent 6c096f8 commit a79c97a

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

tests/Unit/EngineErrorInResolverTests/EngineErrorInResolverTest.php

+22-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,33 @@
1111

1212
class EngineErrorInResolverTest extends TestCase
1313
{
14-
private const ERROR_REGEX = '/QueryWithEngineErrorInCodeQuery::getResult\(\) must be of the type int\w*, string given, called in/';
15-
1614
public function testForEngineError(): void
1715
{
1816
$result = $this->graphql('query { queryWithEngineErrorInCode }', [
1917
'expectErrors' => true,
2018
]);
2119

22-
$this->assertRegExp(static::ERROR_REGEX, $result['errors'][0]['debugMessage']);
20+
$expectedResult = [
21+
'errors' => [
22+
[
23+
'debugMessage' => 'Simulating a TypeError',
24+
'message' => 'Internal server error',
25+
'extensions' => [
26+
'category' => 'internal',
27+
],
28+
'locations' => [
29+
[
30+
'line' => 1,
31+
'column' => 9,
32+
],
33+
],
34+
'path' => [
35+
'queryWithEngineErrorInCode',
36+
],
37+
],
38+
],
39+
];
40+
$this->assertSame($expectedResult, $result);;
2341
}
2442

2543
protected function resolveApplicationExceptionHandler($app)
@@ -31,7 +49,7 @@ protected function resolveApplicationExceptionHandler($app)
3149
->shouldReceive('report')
3250
->with(Mockery::on(
3351
function (FatalThrowableError $error) {
34-
$this->assertRegExp(static::ERROR_REGEX, $error->getMessage());
52+
$this->assertSame('Simulating a TypeError', $error->getMessage());
3553

3654
return true;
3755
}

tests/Unit/EngineErrorInResolverTests/QueryWithEngineErrorInCodeQuery.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rebing\GraphQL\Tests\Unit\EngineErrorInResolverTests;
66

7+
use TypeError;
78
use GraphQL\Type\Definition\Type;
89
use Rebing\GraphQL\Support\Mutation;
910

@@ -20,11 +21,6 @@ public function type(): Type
2021

2122
public function resolve($root, $args): string
2223
{
23-
// This code deliberately creates a PHP error!
24-
return $this->getResult('result');
25-
}
26-
27-
private function getResult(int $string): string
28-
{
24+
throw new TypeError('Simulating a TypeError');
2925
}
3026
}

0 commit comments

Comments
 (0)