Skip to content

Commit 07147f6

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 577e858 commit 07147f6

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

tests/Unit/EngineErrorInResolverTests/EngineErrorInResolverTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
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+
// Using a regex here because in some cases the message gets prefixed with "Type error:"
21+
$this->assertRegExp('/Simulating a TypeError/', $result['errors'][0]['debugMessage']);
2322
}
2423

2524
protected function resolveApplicationExceptionHandler($app)
@@ -31,7 +30,8 @@ protected function resolveApplicationExceptionHandler($app)
3130
->shouldReceive('report')
3231
->with(Mockery::on(
3332
function (FatalThrowableError $error) {
34-
$this->assertRegExp(static::ERROR_REGEX, $error->getMessage());
33+
// Using a regex here because in some cases the message gets prefixed with "Type error:"
34+
$this->assertRegExp('/Simulating a TypeError/', $error->getMessage());
3535

3636
return true;
3737
}

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)