-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
[TESTS] Refactor to support database tests via sqlite #289
Conversation
Eventually we need integration tests right? |
Ack, see the TODO ;-) |
]); | ||
|
||
$this->assertSqlQueries(<<<'SQL' | ||
select "posts"."id", "posts"."title" from "posts" where "posts"."id" = ? limit 1; |
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.
This test shows the functionality with SelectFields
\o/
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.
Nice
4c5d25a
to
0940aad
Compare
|
||
public function type() | ||
{ | ||
return GraphQL::type('Post'); |
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.
Shouldn't this (and the other Queries as well) return Type::nonNull(GraphQL::type('Post'))
instead?
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.
Ok nvm, I just saw the issue you posted. It's strange though, because I thought I've used nonNull with custom types
description | ||
} | ||
} | ||
GRAQPHQL; |
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.
Whats the issue with indenting this?
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.
What do you mean specifically?
]); | ||
|
||
$this->assertSqlQueries(<<<'SQL' | ||
select "posts"."id", "posts"."title" from "posts" where "posts"."id" = ? limit 1; |
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.
Whats the issue with indenting this?
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.
Can you elaborate?
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.
its kinda painful to work this way! My editor went mad!
Image
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.
Hmm, works correctly for me => using PhpStorm 2019 here; what IDE are you using?
The issue I'm seeing:
- it doesn't matter for the GraphQL queries (whitespace is insignificant)
- but for the SQL assertion/comparison, they are significant
Another reason I like to keep it this way is, especially for the SQL assertions, they can get very long. Inevitably horizontal scrolling for them will be necessary often, but the less that is required, the better.
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.
Nice work! The assertSqlQueries
solution is cool.
…o the other tests
Future fix prepared in #283
Thanks! I don't see this approach used very often. I've been working on commercial projects where, under complex circumstances, it's necessary to understand the SQL code being executed (selected columns, n+1 problems, redundant queries, …). Especially in this case where the entire goal of |
Summary
Only "tests" related code has been touched in this PR!
I've already started moving tests into a dedicated namespace
TestCaseDatabase
class which will setup an in-memory SQLITE database and see it with migrations/factories fromtests/Support/database
mainly, we will split tests between pure unit tests (no database required) and ones with
TODO
When endpoint test fails under certain error conditions, they return a regular 404 error page with the exception included in the HTML => this makes debugging harder than it should beWill tackle later.
This should pave the way for #277 and #283 so we we'll have proper tests for them.