-
-
Notifications
You must be signed in to change notification settings - Fork 560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce reusable test utility dedent()
#936
Conversation
Codecov Report
@@ Coverage Diff @@
## master #936 +/- ##
============================================
+ Coverage 94.18% 94.23% +0.05%
Complexity 50 50
============================================
Files 117 117
Lines 9659 9679 +20
============================================
+ Hits 9097 9121 +24
+ Misses 562 558 -4
Continue to review full report at Codecov.
|
We can have a discussion about using functions over static methods in an issue, separate from this pull request. Last time I checked, they were suboptimal for performance when compared with autoloading. |
} | ||
'); | ||
self::assertEquals( | ||
implode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be easier to use a NOWDOC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about it for a short moment myself, but I dismissed the idea. I'm trying to keep the code generally and tests particularly as much close to the reference implementation as possible to make it easy to reflect future changes.
dedent()
deals with whitespaces and empty lines, so it's important to be clear about what the testing string is. I believe using implode()
is more explicit than NOWDOC where is easier to get lost in the indentation etc. It also makes changes like this one super obvious: graphql/graphql-js@1e46389#diff-6738ab51d9c26ea2d4b271f22bb521b267a1e290755dc4cf5da78fcf86facb6c
Co-authored-by: Benedikt Franke <[email protected]>
@spawnia, your comment (#936 (comment)) made me think if we actually need One disadvantage I can see is that nowdoc ignores the last newline, so it needs an extra one to get the same behaviour: $sdl = <<<'GQL'
type Query {
field(in: Input): String
}
GQL; Another disadvantage is that nowdoc is a language construct and we can't control its behaviour as we could with |
Equivalent of
dedent()
test utility function fromgraphql-js
.Its behaviour matches
graphql-js
v15 (v16 version trims trailing newlines).Introduced in reaction to #930 (review)
It lives in
tests/TestUtils
directory, where I later intend to move other testing utilities and fixtures (similarly tographql-js
's__testUtils__
).Personally, I would prefer to have the utility as a function, rather than a static method. But that wouldn't quite fit into the current codebase.
Compare these two snippets:
TestUtils::
is completely unnecessary noise that doesn't add any additional information aboutdedent()
. And it also further complicates already difficult diffing withgraphql-js
.To keep the code consistent with the current "static methods for everything" approach, I went with
Str::dedent()
. It's at least short and has the meaning of "dedent is a function operating on a string".However, if you would like to give it a go, I'm happy to refactor the method to a function. There are more static methods that could be changed to functions and I believe the codebase could benefit from it.