2

OK, maybe im not getting this right. Im new to Unit testing. But I want to test something like this:

I have an action that display tickets for user to do on current day. I want to make assertion that will check if: if there is 0 tickets then the messages says "no tickets for today", if there are > 0 tickets than system displays table. I know how to check if view renders a message or renders a table, but how to make an "if" in the test? Something like:

<code>
if(count($tickets > 0) {
 $this->assertQuery('table');
} else {
 $this->assertQueryContentContains('#message', 'No tickets for today');
}
</code>

I dont get how to make a stubb data or get value of a certain variable from action.

1
  • 2
    Normally you would want two separate tests: one that finds no tickets and other that finds some. Set up fake data or mock objects so you can do both. Commented Feb 12, 2012 at 23:02

1 Answer 1

2

You shouldn't have any logic in unit test. Problem with logic in unit test is that it usually mirrors logic from tested piece of code, which pretty much kills the purpose of unit testing.

Instead, you want to simulate conditions for each test (and in your case you need at least two) and verify whether tested expectations were met. Unless $tickets retrieval is complex process (it then should be mocked), simulating conditions in your case would be simply setting $tickets to appropriate value.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.