Testing output twice [PHPUNIT]

Is it able to test output twice?
This is the code

public function testAutoTriggerOff()
    $user = array(
        'logTime'=> time()
    $this->elevent->attach('Elevent\Test\Event\UserHasLoggedIn', new WelcomeUser);
    $event = $this->elevent->setEvent('Elevent\Test\Event\UserHasLoggedIn', $user);
    $this->expectOutputString('Welcome, Andy');

So, after the setEvent is called, I want to test that there is no output…
And, after the trigger is called, I want to test that the output is ‘Welcome, Andy’
This test passed.
However, if I changed the first test output into something that should be false, such as

$this->expectOutputString('this one should be false');
$this->expectOutputString('Welcome, Andy');

But, the test also passed. I expected it to fail, since I want to test the output twice.
Before the trigger, it should give no output.
After the trigger, the output should be ‘Welcome, Andy’
How to test that way?

In this case, I test if auto-trigger is really off… If the auto-trigger is off, I need to call the trigger method to fire the listener… If it’s on, I don’t need to call the trigger, it’s auto-triggered since the event is set…

There might be a way. But it doesn’t seem right. At least to me “unit” signifies “one” - “single”, not “two”.

Can you split it into separate tests? eg.
shouldNotBeOutputString and shouldBeOutputString

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.