Skip to content

Commit

Permalink
fixed codestyle checks
Browse files Browse the repository at this point in the history
  • Loading branch information
peldax committed Jul 28, 2020
1 parent 64085ab commit 21f7255
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 117 deletions.
7 changes: 5 additions & 2 deletions src/Graphpinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public function runQuery(\Infinityloop\Utils\Json $request) : \Graphpinator\Reso
$this->validateRequest($request);

$query = $request[self::QUERY];
$variables = $request[self::VARIABLES] ?? [];
$operationName = $request[self::OPERATION_NAME] ?? null;
$variables = $request[self::VARIABLES]
?? [];
//phpcs:ignore SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable
$operationName = $request[self::OPERATION_NAME]
?? null;

try {
return \Graphpinator\Parser\Parser::parseString($query)
Expand Down
3 changes: 2 additions & 1 deletion src/Resolver/VariableValueSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ final class VariableValueSet extends \Infinityloop\Utils\ObjectSet
public function __construct(
\Graphpinator\Normalizer\Variable\VariableSet $definedVariables,
array $providedValues
) {
)
{
foreach ($definedVariables as $variable) {
$this->array[$variable->getName()] = $variable->createValue($providedValues);
}
Expand Down
8 changes: 6 additions & 2 deletions tests/Spec/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ public function simpleDataProvider() : array
],
[
\Infinityloop\Utils\Json::fromArray([
'query' => 'query queryName { field0 { ... namedFragment @include(if: true) } } fragment namedFragment on Abc { field1 { name } }',
'query' => 'query queryName {
field0 { ... namedFragment @include(if: true) } } fragment namedFragment on Abc { field1 { name }
}',
]),
\Infinityloop\Utils\Json::fromArray(['data' => ['field0' => ['field1' => ['name' => 'Test 123']]]]),
],
[
\Infinityloop\Utils\Json::fromArray([
'query' => 'query queryName { field0 { ... namedFragment @include(if: false) } } fragment namedFragment on Abc { field1 { name } }',
'query' => 'query queryName {
field0 { ... namedFragment @include(if: false) } } fragment namedFragment on Abc { field1 { name }
}',
]),
\Infinityloop\Utils\Json::fromArray(['data' => ['field0' => []]]),
],
Expand Down
5 changes: 4 additions & 1 deletion tests/Spec/ErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public function testSimple(\Infinityloop\Utils\Json $request, \Infinityloop\Util
$result = $graphpinator->runQuery($request);

self::assertSame($expected->toString(), \json_encode($result, \JSON_THROW_ON_ERROR, 512));
self::assertSame($expected['errors'], \json_decode(\json_encode($result->getErrors(), \JSON_THROW_ON_ERROR, 512), true, 512, \JSON_THROW_ON_ERROR));
self::assertSame(
$expected['errors'],
\json_decode(\json_encode($result->getErrors(), \JSON_THROW_ON_ERROR, 512), true, 512, \JSON_THROW_ON_ERROR),
);
self::assertNull($result->getData());
}

Expand Down
6 changes: 4 additions & 2 deletions tests/Spec/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public function simpleDataProvider() : array
],
[
\Infinityloop\Utils\Json::fromArray([
'query' => 'query queryName { field0 { field1(arg2: {name: "foo", innerList: [], innerNotNull: {name: "bar", number: []} }) { name } } }',
'query' => 'query queryName {
field0 { field1(arg2: {name: "foo", innerList: [], innerNotNull: {name: "bar", number: []} }) { name } }
}',
]),
\Infinityloop\Utils\Json::fromArray([
'data' => [
Expand Down Expand Up @@ -206,7 +208,7 @@ public function simpleDataProvider() : array
}
}
}',
'variables' => ['var1' => ['name' => 'bar', 'number' => []]]
'variables' => ['var1' => ['name' => 'bar', 'number' => []]],
]),
\Infinityloop\Utils\Json::fromArray([
'data' => [
Expand Down
155 changes: 53 additions & 102 deletions tests/Spec/IntrospectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public function testSimple(\Infinityloop\Utils\Json $request, \Infinityloop\Util
$result = $graphpinator->runQuery($request);

self::assertSame($expected->toString(), \json_encode($result, \JSON_THROW_ON_ERROR, 512));
self::assertSame($expected['data'], \json_decode(\json_encode($result->getData(), \JSON_THROW_ON_ERROR, 512), true, 512, \JSON_THROW_ON_ERROR));
self::assertSame(
$expected['data'],
\json_decode(\json_encode($result->getData(), \JSON_THROW_ON_ERROR, 512), true, 512, \JSON_THROW_ON_ERROR),
);
self::assertNull($result->getErrors());
}

Expand Down Expand Up @@ -266,24 +269,13 @@ enumValues {
\Infinityloop\Utils\Json::fromArray([
'query' => '{
__type(name: "TestUnion") {
kind name description fields {
name
}
interfaces {
name
}
possibleTypes {
name
}
inputFields {
name
}
enumValues {
name
}
ofType {
name
}
kind name description
fields { name }
interfaces { name }
possibleTypes { name }
inputFields { name }
enumValues { name }
ofType { name }
}
}',
]),
Expand All @@ -307,24 +299,13 @@ enumValues {
\Infinityloop\Utils\Json::fromArray([
'query' => '{
__type(name: "TestInnerInput") {
kind name description fields {
name
}
interfaces {
name
}
possibleTypes {
name
}
inputFields {
name
}
enumValues {
name
}
ofType {
name
}
kind name description
fields { name }
interfaces { name }
possibleTypes { name }
inputFields { name }
enumValues { name }
ofType { name }
}
}',
]),
Expand All @@ -348,24 +329,13 @@ enumValues {
\Infinityloop\Utils\Json::fromArray([
'query' => '{
__type(name: "TestEnum") {
kind name description fields {
name
}
interfaces {
name
}
possibleTypes {
name
}
inputFields {
name
}
enumValues {
name description isDeprecated deprecationReason
}
ofType {
name
}
kind name description
fields { name }
interfaces { name }
possibleTypes { name }
inputFields { name }
enumValues { name description isDeprecated deprecationReason }
ofType { name }
}
}',
]),
Expand All @@ -392,7 +362,9 @@ enumValues {
],
[
\Infinityloop\Utils\Json::fromArray([
'query' => '{ __type(name: "TestExplicitEnum") { enumValues(includeDeprecated: true){name description isDeprecated deprecationReason} } }',
'query' => '{ __type(name: "TestExplicitEnum") {
enumValues(includeDeprecated: true){name description isDeprecated deprecationReason} }
}',
]),
\Infinityloop\Utils\Json::fromArray([
'data' => [
Expand All @@ -409,7 +381,9 @@ enumValues {
],
[
\Infinityloop\Utils\Json::fromArray([
'query' => '{ __type(name: "TestExplicitEnum") { enumValues(includeDeprecated: false){name description isDeprecated deprecationReason} } }',
'query' => '{ __type(name: "TestExplicitEnum") {
enumValues(includeDeprecated: false){name description isDeprecated deprecationReason} }
}',
]),
\Infinityloop\Utils\Json::fromArray([
'data' => [
Expand All @@ -429,13 +403,9 @@ enumValues {
'query' => '{
__type(name: "TestInterface") {
fields {
name description args {
name
}
name description args { name }
isDeprecated deprecationReason type {
kind name ofType {
name
}
kind name ofType { name }
}
}
}
Expand Down Expand Up @@ -463,13 +433,9 @@ enumValues {
'query' => '{
__type(name: "Abc") {
fields(includeDeprecated: false) {
name description isDeprecated deprecationReason type{
name
}
name description isDeprecated deprecationReason type { name }
args {
name description type {
name
}
name description type { name }
defaultValue
}
}
Expand Down Expand Up @@ -511,13 +477,9 @@ enumValues {
'query' => '{
__type(name: "Abc") {
fields(includeDeprecated: true) {
name description isDeprecated deprecationReason type {
name
}
name description isDeprecated deprecationReason type { name }
args {
name description type {
name
}
name description type { name }
defaultValue
}
}
Expand Down Expand Up @@ -604,7 +566,7 @@ public function testType(\Infinityloop\Utils\Json $request, \Infinityloop\Utils\

self::assertSame(
$result->toString(),
\json_encode($graphpinator->runQuery($request), JSON_THROW_ON_ERROR, 512),
\json_encode($graphpinator->runQuery($request), \JSON_THROW_ON_ERROR, 512),
);
}

Expand All @@ -613,24 +575,12 @@ public function testDescription() : void
$request = \Infinityloop\Utils\Json::fromArray([
'query' => '{
__type(name: "Abc") {
kind name description fields {
name
}
interfaces {
name
}
possibleTypes {
name
}
inputFields {
name
}
enumValues {
name
}
ofType {
name
}
kind name description fields { name }
interfaces { name }
possibleTypes { name }
inputFields { name }
enumValues { name }
ofType { name }
}
}',
]);
Expand Down Expand Up @@ -663,13 +613,10 @@ public function testDeprecatedFields() : void
'query' => '{
__type(name: "Abc") {
fields(includeDeprecated: false) {
name description isDeprecated deprecationReason type {
name
}
name description isDeprecated deprecationReason type { name }
args {
name description type {
name
}
name description
type { name }
defaultValue
}
}
Expand All @@ -694,7 +641,9 @@ public function testDeprecatedFields() : void
public function testDeprecatedFalseEnum() : void
{
$request = \Infinityloop\Utils\Json::fromArray([
'query' => '{ __type(name: "TestExplicitEnum") { enumValues(includeDeprecated: false){name description isDeprecated deprecationReason} } }',
'query' => '{ __type(name: "TestExplicitEnum") {
enumValues(includeDeprecated: false){ name description isDeprecated deprecationReason } }
}',
]);
$graphpinator = new \Graphpinator\Graphpinator(PrintSchema::getSchema());
$result = \Infinityloop\Utils\Json::fromArray([
Expand Down Expand Up @@ -727,7 +676,9 @@ public function testDeprecatedFalseEnum() : void
public function testDeprecatedTrueEnum() : void
{
$request = \Infinityloop\Utils\Json::fromArray([
'query' => '{ __type(name: "TestExplicitEnum") { enumValues(includeDeprecated: true){name description isDeprecated deprecationReason} } }',
'query' => '{ __type(name: "TestExplicitEnum") {
enumValues(includeDeprecated: true){name description isDeprecated deprecationReason} }
}',
]);
$graphpinator = new \Graphpinator\Graphpinator(PrintSchema::getSchema());
$result = \Infinityloop\Utils\Json::fromArray([
Expand Down
13 changes: 6 additions & 7 deletions tests/Spec/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public function testComponents(\Infinityloop\Utils\Json $request, \Infinityloop\
$normalizer = new \Graphpinator\Normalizer\Normalizer(TestSchema::getSchema());
$resolver = new \Graphpinator\Resolver\Resolver();

$result = $resolver->resolve($normalizer->normalize($parser->parse()), $request['variables'] ?? []);
$result = $resolver->resolve($normalizer->normalize($parser->parse()), $request['variables']
?? []);

self::assertSame($expected->toString(), \json_encode($result, \JSON_THROW_ON_ERROR, 512));
self::assertSame($expected['data'], \json_decode(\json_encode($result->getData()), true));
Expand Down Expand Up @@ -94,8 +95,7 @@ public function invalidDataProvider() : array
\Graphpinator\Exception\Resolver\FieldResultAbstract::class,
],
[
\Infinityloop\Utils\Json::fromArray([
]),
\Infinityloop\Utils\Json::fromArray([]),
\Graphpinator\Exception\RequestWithoutQuery::class,
],
[
Expand All @@ -107,14 +107,14 @@ public function invalidDataProvider() : array
[
\Infinityloop\Utils\Json::fromArray([
'query' => '',
'variables' => 'abc'
'variables' => 'abc',
]),
\Graphpinator\Exception\RequestVariablesNotArray::class,
],
[
\Infinityloop\Utils\Json::fromArray([
'query' => '',
'operationName' => 123
'operationName' => 123,
]),
\Graphpinator\Exception\RequestOperationNameNotString::class,
],
Expand All @@ -131,8 +131,7 @@ public function invalidDataProvider() : array

/**
* @dataProvider invalidDataProvider
* @param string $request
* @param \Infinityloop\Utils\Json $variables
* @param \Infinityloop\Utils\Json $request
* @param string $exception
*/
public function testInvalid(\Infinityloop\Utils\Json $request, string $exception) : void
Expand Down

0 comments on commit 21f7255

Please sign in to comment.