From 9b2228b17efde826f741372d3950bf326f641da3 Mon Sep 17 00:00:00 2001 From: Jacob Thomason Date: Wed, 13 Sep 2023 04:07:41 -0400 Subject: [PATCH 1/3] Add new line for better description formatting --- src/Middlewares/CostFieldMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Middlewares/CostFieldMiddleware.php b/src/Middlewares/CostFieldMiddleware.php index 56daa62328..3e4865ca49 100644 --- a/src/Middlewares/CostFieldMiddleware.php +++ b/src/Middlewares/CostFieldMiddleware.php @@ -63,7 +63,7 @@ public function process(QueryFieldDescriptor $queryFieldDescriptor, FieldHandler private function buildQueryComment(Cost $costAttribute): string { - return 'Cost: ' . + return "\nCost: " . implode(', ', [ 'complexity = ' . $costAttribute->complexity, 'multipliers = [' . implode(', ', $costAttribute->multipliers) . ']', From 2e5cf182c70d83bfd7f873986cf09f597a857dc8 Mon Sep 17 00:00:00 2001 From: Jacob Thomason Date: Wed, 13 Sep 2023 04:13:23 -0400 Subject: [PATCH 2/3] Updated tests --- tests/Integration/QueryComplexityTest.php | 8 ++++---- tests/Middlewares/CostFieldMiddlewareTest.php | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/Integration/QueryComplexityTest.php b/tests/Integration/QueryComplexityTest.php index c3af9d04f8..8268b57acd 100644 --- a/tests/Integration/QueryComplexityTest.php +++ b/tests/Integration/QueryComplexityTest.php @@ -175,7 +175,7 @@ public function testReportsQueryCostInIntrospection(string|null $expectedDescrip public static function reportsQueryCostInIntrospectionProvider(): iterable { yield [ - 'Cost: complexity = 5, multipliers = [take], defaultMultiplier = 500', + '\nCost: complexity = 5, multipliers = [take], defaultMultiplier = 500', 'Query', 'articles', ]; @@ -187,15 +187,15 @@ public static function reportsQueryCostInIntrospectionProvider(): iterable ]; yield [ - 'Cost: complexity = 5, multipliers = [], defaultMultiplier = null', + '\nCost: complexity = 5, multipliers = [], defaultMultiplier = null', 'Post', 'comment', ]; yield [ - 'Cost: complexity = 3, multipliers = [], defaultMultiplier = null', + '\nCost: complexity = 3, multipliers = [], defaultMultiplier = null', 'Post', 'author', ]; } -} \ No newline at end of file +} diff --git a/tests/Middlewares/CostFieldMiddlewareTest.php b/tests/Middlewares/CostFieldMiddlewareTest.php index 863fbdb89e..10b4af7ff4 100644 --- a/tests/Middlewares/CostFieldMiddlewareTest.php +++ b/tests/Middlewares/CostFieldMiddlewareTest.php @@ -109,17 +109,17 @@ public function testAddsCostInDescription(string $expectedDescription, Cost $cos public static function addsCostInDescriptionProvider(): iterable { yield [ - 'Cost: complexity = 1, multipliers = [], defaultMultiplier = null', + '\nCost: complexity = 1, multipliers = [], defaultMultiplier = null', new Cost(), ]; yield [ - 'Cost: complexity = 5, multipliers = [take], defaultMultiplier = 500', + '\nCost: complexity = 5, multipliers = [take], defaultMultiplier = 500', new Cost(complexity: 5, multipliers: ['take'], defaultMultiplier: 500) ]; yield [ - 'Cost: complexity = 5, multipliers = [take, null], defaultMultiplier = null', + '\nCost: complexity = 5, multipliers = [take, null], defaultMultiplier = null', new Cost(complexity: 5, multipliers: ['take', 'null'], defaultMultiplier: null) ]; } From 951d1195e7c364671961d40f2d9313d3b76dfa9e Mon Sep 17 00:00:00 2001 From: Jacob Thomason Date: Wed, 13 Sep 2023 04:15:13 -0400 Subject: [PATCH 3/3] Use double quotes for proper \n parsing --- tests/Integration/QueryComplexityTest.php | 6 +++--- tests/Middlewares/CostFieldMiddlewareTest.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Integration/QueryComplexityTest.php b/tests/Integration/QueryComplexityTest.php index 8268b57acd..fd2fbe95f6 100644 --- a/tests/Integration/QueryComplexityTest.php +++ b/tests/Integration/QueryComplexityTest.php @@ -175,7 +175,7 @@ public function testReportsQueryCostInIntrospection(string|null $expectedDescrip public static function reportsQueryCostInIntrospectionProvider(): iterable { yield [ - '\nCost: complexity = 5, multipliers = [take], defaultMultiplier = 500', + "\nCost: complexity = 5, multipliers = [take], defaultMultiplier = 500", 'Query', 'articles', ]; @@ -187,13 +187,13 @@ public static function reportsQueryCostInIntrospectionProvider(): iterable ]; yield [ - '\nCost: complexity = 5, multipliers = [], defaultMultiplier = null', + "\nCost: complexity = 5, multipliers = [], defaultMultiplier = null", 'Post', 'comment', ]; yield [ - '\nCost: complexity = 3, multipliers = [], defaultMultiplier = null', + "\nCost: complexity = 3, multipliers = [], defaultMultiplier = null", 'Post', 'author', ]; diff --git a/tests/Middlewares/CostFieldMiddlewareTest.php b/tests/Middlewares/CostFieldMiddlewareTest.php index 10b4af7ff4..c5ddccabc6 100644 --- a/tests/Middlewares/CostFieldMiddlewareTest.php +++ b/tests/Middlewares/CostFieldMiddlewareTest.php @@ -109,17 +109,17 @@ public function testAddsCostInDescription(string $expectedDescription, Cost $cos public static function addsCostInDescriptionProvider(): iterable { yield [ - '\nCost: complexity = 1, multipliers = [], defaultMultiplier = null', + "\nCost: complexity = 1, multipliers = [], defaultMultiplier = null", new Cost(), ]; yield [ - '\nCost: complexity = 5, multipliers = [take], defaultMultiplier = 500', + "\nCost: complexity = 5, multipliers = [take], defaultMultiplier = 500", new Cost(complexity: 5, multipliers: ['take'], defaultMultiplier: 500) ]; yield [ - '\nCost: complexity = 5, multipliers = [take, null], defaultMultiplier = null', + "\nCost: complexity = 5, multipliers = [take, null], defaultMultiplier = null", new Cost(complexity: 5, multipliers: ['take', 'null'], defaultMultiplier: null) ]; }