Bartosz Rychlicki
Bartosz Rychlicki

Reputation: 1918

How can I test variables using PHPUnit in Zend Framework

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.

Upvotes: 2

Views: 247

Answers (1)

k.m
k.m

Reputation: 31474

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.

Upvotes: 2

Related Questions