jeudi 9 juin 2016

Testing output twice

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

<?php
public function testAutoTriggerOff()
{
    $user = array(
        'id'=>1,
        'name'=>'Andy',
        'logTime'=> time()
        );
    $this->elevent->turnOffAutoTrigger();
    $this->elevent->attach('Elevent\Test\Event\UserHasLoggedIn', new WelcomeUser);
    $event = $this->elevent->setEvent('Elevent\Test\Event\UserHasLoggedIn', $user);
    $this->expectOutputString('');
    $this->elevent->trigger($event);
    $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->elevent->trigger($event);
    $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?

Aucun commentaire:

Enregistrer un commentaire