|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Rebing\GraphQL\Tests\Unit\EngineErrorInResolverTests; |
| 6 | + |
| 7 | +use Mockery; |
| 8 | +use Rebing\GraphQL\Tests\TestCase; |
| 9 | +use Illuminate\Contracts\Debug\ExceptionHandler; |
| 10 | +use Symfony\Component\Debug\Exception\FatalThrowableError; |
| 11 | + |
| 12 | +class EngineErrorInResolverTest extends TestCase |
| 13 | +{ |
| 14 | + private const ERROR_REGEX = '/QueryWithEngineErrorInCodeQuery::getResult\(\) must be of the type int\w*, string given, called in/'; |
| 15 | + |
| 16 | + public function testForEngineError(): void |
| 17 | + { |
| 18 | + $result = $this->graphql('query { queryWithEngineErrorInCode }', [ |
| 19 | + 'expectErrors' => true, |
| 20 | + ]); |
| 21 | + |
| 22 | + $this->assertRegExp(static::ERROR_REGEX, $result['errors'][0]['debugMessage']); |
| 23 | + } |
| 24 | + |
| 25 | + protected function resolveApplicationExceptionHandler($app) |
| 26 | + { |
| 27 | + // We expect the error in QueryWithEngineErrorInCodeQuery to trigger |
| 28 | + // reporting to the handler (as opposed to swallowing it silently). |
| 29 | + $handlerMock = Mockery::mock(ExceptionHandler::class); |
| 30 | + $handlerMock |
| 31 | + ->shouldReceive('report') |
| 32 | + ->with(Mockery::on( |
| 33 | + function (FatalThrowableError $error) { |
| 34 | + $this->assertRegExp(static::ERROR_REGEX, $error->getMessage()); |
| 35 | + |
| 36 | + return true; |
| 37 | + } |
| 38 | + )) |
| 39 | + ->once(); |
| 40 | + |
| 41 | + $app->instance(ExceptionHandler::class, $handlerMock); |
| 42 | + } |
| 43 | + |
| 44 | + protected function getEnvironmentSetUp($app) |
| 45 | + { |
| 46 | + parent::getEnvironmentSetUp($app); |
| 47 | + |
| 48 | + $app['config']->set('graphql.schemas.default', [ |
| 49 | + 'query' => [ |
| 50 | + QueryWithEngineErrorInCodeQuery::class, |
| 51 | + ], |
| 52 | + ]); |
| 53 | + } |
| 54 | +} |
0 commit comments