Loosing the test's "context" when defining it as a variable #40262
Unanswered
Drillan767
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Sorry if the title is confusing, I'm not really sure of how I should describe this.
I'm currently writing some tests for a command that is quite long and complex, and asks lots of questions and will ask several more based on previously answered ones. In the end, the command will create several database entries.
I'd like to test the command's behaviors, however there's quite a lot of lines duplications between tests, because some questions can't be avoided.
I had the idea to store the questions and given answers inside a config file then runs a
foreach()
command on it. The result would look like so:Everything works, I get the outputs I'm expecting and the exit status awaited.
However, if I try to run
$this->assertDatabaseHas()
, I will never find my created entries in my database, even though setting somedd()
here and there will tell me that the code's behavior hasn't changed.I recently realized that the simple act of defining
$this->artisan()
inside a variable that won't even be used is enough to "trigger" this behavior.I still can stick to the old fashioned way, but.. Is it normal?
Thank you in advance
Beta Was this translation helpful? Give feedback.
All reactions