mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-29 00:25:17 +03:00
Fix CS in /tests/Error
This commit is contained in:
parent
8817e8e010
commit
3170951620
@ -1,4 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace GraphQL\Tests\Error;
|
namespace GraphQL\Tests\Error;
|
||||||
|
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
@ -10,27 +13,27 @@ use PHPUnit\Framework\TestCase;
|
|||||||
class ErrorTest extends TestCase
|
class ErrorTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @it uses the stack of an original error
|
* @see it('uses the stack of an original error')
|
||||||
*/
|
*/
|
||||||
public function testUsesTheStackOfAnOriginalError()
|
public function testUsesTheStackOfAnOriginalError() : void
|
||||||
{
|
{
|
||||||
$prev = new \Exception("Original");
|
$prev = new \Exception('Original');
|
||||||
$err = new Error('msg', null, null, null, null, $prev);
|
$err = new Error('msg', null, null, null, null, $prev);
|
||||||
|
|
||||||
$this->assertSame($err->getPrevious(), $prev);
|
$this->assertSame($err->getPrevious(), $prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it converts nodes to positions and locations
|
* @see it('converts nodes to positions and locations')
|
||||||
*/
|
*/
|
||||||
public function testConvertsNodesToPositionsAndLocations()
|
public function testConvertsNodesToPositionsAndLocations() : void
|
||||||
{
|
{
|
||||||
$source = new Source('{
|
$source = new Source('{
|
||||||
field
|
field
|
||||||
}');
|
}');
|
||||||
$ast = Parser::parse($source);
|
$ast = Parser::parse($source);
|
||||||
$fieldNode = $ast->definitions[0]->selectionSet->selections[0];
|
$fieldNode = $ast->definitions[0]->selectionSet->selections[0];
|
||||||
$e = new Error('msg', [ $fieldNode ]);
|
$e = new Error('msg', [$fieldNode]);
|
||||||
|
|
||||||
$this->assertEquals([$fieldNode], $e->nodes);
|
$this->assertEquals([$fieldNode], $e->nodes);
|
||||||
$this->assertEquals($source, $e->getSource());
|
$this->assertEquals($source, $e->getSource());
|
||||||
@ -39,16 +42,16 @@ class ErrorTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it converts single node to positions and locations
|
* @see it('converts single node to positions and locations')
|
||||||
*/
|
*/
|
||||||
public function testConvertSingleNodeToPositionsAndLocations()
|
public function testConvertSingleNodeToPositionsAndLocations() : void
|
||||||
{
|
{
|
||||||
$source = new Source('{
|
$source = new Source('{
|
||||||
field
|
field
|
||||||
}');
|
}');
|
||||||
$ast = Parser::parse($source);
|
$ast = Parser::parse($source);
|
||||||
$fieldNode = $ast->definitions[0]->selectionSet->selections[0];
|
$fieldNode = $ast->definitions[0]->selectionSet->selections[0];
|
||||||
$e = new Error('msg', $fieldNode); // Non-array value.
|
$e = new Error('msg', $fieldNode); // Non-array value.
|
||||||
|
|
||||||
$this->assertEquals([$fieldNode], $e->nodes);
|
$this->assertEquals([$fieldNode], $e->nodes);
|
||||||
$this->assertEquals($source, $e->getSource());
|
$this->assertEquals($source, $e->getSource());
|
||||||
@ -57,16 +60,16 @@ class ErrorTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it converts node with loc.start === 0 to positions and locations
|
* @see it('converts node with loc.start === 0 to positions and locations')
|
||||||
*/
|
*/
|
||||||
public function testConvertsNodeWithStart0ToPositionsAndLocations()
|
public function testConvertsNodeWithStart0ToPositionsAndLocations() : void
|
||||||
{
|
{
|
||||||
$source = new Source('{
|
$source = new Source('{
|
||||||
field
|
field
|
||||||
}');
|
}');
|
||||||
$ast = Parser::parse($source);
|
$ast = Parser::parse($source);
|
||||||
$operationNode = $ast->definitions[0];
|
$operationNode = $ast->definitions[0];
|
||||||
$e = new Error('msg', [ $operationNode ]);
|
$e = new Error('msg', [$operationNode]);
|
||||||
|
|
||||||
$this->assertEquals([$operationNode], $e->nodes);
|
$this->assertEquals([$operationNode], $e->nodes);
|
||||||
$this->assertEquals($source, $e->getSource());
|
$this->assertEquals($source, $e->getSource());
|
||||||
@ -75,14 +78,14 @@ class ErrorTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it converts source and positions to locations
|
* @see it('converts source and positions to locations')
|
||||||
*/
|
*/
|
||||||
public function testConvertsSourceAndPositionsToLocations()
|
public function testConvertsSourceAndPositionsToLocations() : void
|
||||||
{
|
{
|
||||||
$source = new Source('{
|
$source = new Source('{
|
||||||
field
|
field
|
||||||
}');
|
}');
|
||||||
$e = new Error('msg', null, $source, [ 10 ]);
|
$e = new Error('msg', null, $source, [10]);
|
||||||
|
|
||||||
$this->assertEquals(null, $e->nodes);
|
$this->assertEquals(null, $e->nodes);
|
||||||
$this->assertEquals($source, $e->getSource());
|
$this->assertEquals($source, $e->getSource());
|
||||||
@ -91,21 +94,21 @@ class ErrorTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it serializes to include message
|
* @see it('serializes to include message')
|
||||||
*/
|
*/
|
||||||
public function testSerializesToIncludeMessage()
|
public function testSerializesToIncludeMessage() : void
|
||||||
{
|
{
|
||||||
$e = new Error('msg');
|
$e = new Error('msg');
|
||||||
$this->assertEquals(['message' => 'msg'], $e->toSerializableArray());
|
$this->assertEquals(['message' => 'msg'], $e->toSerializableArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it serializes to include message and locations
|
* @see it('serializes to include message and locations')
|
||||||
*/
|
*/
|
||||||
public function testSerializesToIncludeMessageAndLocations()
|
public function testSerializesToIncludeMessageAndLocations() : void
|
||||||
{
|
{
|
||||||
$node = Parser::parse('{ field }')->definitions[0]->selectionSet->selections[0];
|
$node = Parser::parse('{ field }')->definitions[0]->selectionSet->selections[0];
|
||||||
$e = new Error('msg', [ $node ]);
|
$e = new Error('msg', [$node]);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
['message' => 'msg', 'locations' => [['line' => 1, 'column' => 3]]],
|
['message' => 'msg', 'locations' => [['line' => 1, 'column' => 3]]],
|
||||||
@ -114,26 +117,26 @@ class ErrorTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it serializes to include path
|
* @see it('serializes to include path')
|
||||||
*/
|
*/
|
||||||
public function testSerializesToIncludePath()
|
public function testSerializesToIncludePath() : void
|
||||||
{
|
{
|
||||||
$e = new Error(
|
$e = new Error(
|
||||||
'msg',
|
'msg',
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
[ 'path', 3, 'to', 'field' ]
|
['path', 3, 'to', 'field']
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals([ 'path', 3, 'to', 'field' ], $e->path);
|
$this->assertEquals(['path', 3, 'to', 'field'], $e->path);
|
||||||
$this->assertEquals(['message' => 'msg', 'path' => [ 'path', 3, 'to', 'field' ]], $e->toSerializableArray());
|
$this->assertEquals(['message' => 'msg', 'path' => ['path', 3, 'to', 'field']], $e->toSerializableArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it default error formatter includes extension fields
|
* @see it('default error formatter includes extension fields')
|
||||||
*/
|
*/
|
||||||
public function testDefaultErrorFormatterIncludesExtensionFields()
|
public function testDefaultErrorFormatterIncludesExtensionFields() : void
|
||||||
{
|
{
|
||||||
$e = new Error(
|
$e = new Error(
|
||||||
'msg',
|
'msg',
|
||||||
@ -146,9 +149,12 @@ class ErrorTest extends TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(['foo' => 'bar'], $e->getExtensions());
|
$this->assertEquals(['foo' => 'bar'], $e->getExtensions());
|
||||||
$this->assertEquals([
|
$this->assertEquals(
|
||||||
'message' => 'msg',
|
[
|
||||||
'extensions' => ['foo' => 'bar'],
|
'message' => 'msg',
|
||||||
], $e->toSerializableArray());
|
'extensions' => ['foo' => 'bar'],
|
||||||
|
],
|
||||||
|
$e->toSerializableArray()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace GraphQL\Tests\Error;
|
namespace GraphQL\Tests\Error;
|
||||||
|
|
||||||
use GraphQL\Error\Error;
|
use GraphQL\Error\Error;
|
||||||
@ -10,12 +13,10 @@ use PHPUnit\Framework\TestCase;
|
|||||||
|
|
||||||
class PrintErrorTest extends TestCase
|
class PrintErrorTest extends TestCase
|
||||||
{
|
{
|
||||||
// Describe printError
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it prints an line numbers with correct padding
|
* @see it('prints an line numbers with correct padding')
|
||||||
*/
|
*/
|
||||||
public function testPrintsAnLineNumbersWithCorrectPadding()
|
public function testPrintsAnLineNumbersWithCorrectPadding() : void
|
||||||
{
|
{
|
||||||
$singleDigit = new Error(
|
$singleDigit = new Error(
|
||||||
'Single digit line number with no padding',
|
'Single digit line number with no padding',
|
||||||
@ -24,7 +25,7 @@ class PrintErrorTest extends TestCase
|
|||||||
[0]
|
[0]
|
||||||
);
|
);
|
||||||
|
|
||||||
$actual = FormattedError::printError($singleDigit);
|
$actual = FormattedError::printError($singleDigit);
|
||||||
$expected = 'Single digit line number with no padding
|
$expected = 'Single digit line number with no padding
|
||||||
|
|
||||||
Test (9:1)
|
Test (9:1)
|
||||||
@ -39,8 +40,8 @@ Test (9:1)
|
|||||||
new Source("*\n", 'Test', new SourceLocation(9, 1)),
|
new Source("*\n", 'Test', new SourceLocation(9, 1)),
|
||||||
[0]
|
[0]
|
||||||
);
|
);
|
||||||
$actual = FormattedError::printError($doubleDigit);
|
$actual = FormattedError::printError($doubleDigit);
|
||||||
$expected = 'Left padded first line number
|
$expected = 'Left padded first line number
|
||||||
|
|
||||||
Test (9:1)
|
Test (9:1)
|
||||||
9: *
|
9: *
|
||||||
@ -51,19 +52,21 @@ Test (9:1)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @it prints an error with nodes from different sources
|
* @see it('prints an error with nodes from different sources')
|
||||||
*/
|
*/
|
||||||
public function testPrintsAnErrorWithNodesFromDifferentSources()
|
public function testPrintsAnErrorWithNodesFromDifferentSources() : void
|
||||||
{
|
{
|
||||||
$sourceA = Parser::parse(new Source('type Foo {
|
$sourceA = Parser::parse(new Source(
|
||||||
|
'type Foo {
|
||||||
field: String
|
field: String
|
||||||
}',
|
}',
|
||||||
'SourceA'
|
'SourceA'
|
||||||
));
|
));
|
||||||
|
|
||||||
$fieldTypeA = $sourceA->definitions[0]->fields[0]->type;
|
$fieldTypeA = $sourceA->definitions[0]->fields[0]->type;
|
||||||
|
|
||||||
$sourceB = Parser::parse(new Source('type Foo {
|
$sourceB = Parser::parse(new Source(
|
||||||
|
'type Foo {
|
||||||
field: Int
|
field: Int
|
||||||
}',
|
}',
|
||||||
'SourceB'
|
'SourceB'
|
||||||
@ -71,7 +74,6 @@ Test (9:1)
|
|||||||
|
|
||||||
$fieldTypeB = $sourceB->definitions[0]->fields[0]->type;
|
$fieldTypeB = $sourceB->definitions[0]->fields[0]->type;
|
||||||
|
|
||||||
|
|
||||||
$error = new Error(
|
$error = new Error(
|
||||||
'Example error with two nodes',
|
'Example error with two nodes',
|
||||||
[
|
[
|
||||||
|
Loading…
Reference in New Issue
Block a user