Codeception / Specify

BDD style code blocks for PHPUnit / Codeception
MIT License
156 stars 22 forks source link

Output is not cleared after specify #10

Open ddziaduch opened 9 years ago

ddziaduch commented 9 years ago

Hi.

I've a test:

public function testSomething()
{
    $this->specify(
        'expect output',
        function () {
            $this->expectOutputString('lorem ipsum');
            (new TestedClass)->doSomething();
        }
    );
    $this->specify(
        'expect another output',
        function () {
            $this->expectOutputString('lorem ipsum');
            (new TestedClass)->doSomethingElse();
        }
    );
}

The first specification passes. Second specification is failing. It expect output to be "lorem ipsum 2", but gots "lorem ipsum 1lorem ipsum 2".

ghost commented 4 years ago

Calling the ob_clean() function immediately after performing tasks that involve the output buffer may be a solution.

Otherwise this may serve as a workaround: How to flush output after each echo call? .

I don't know if there is a way to fix this without refactoring the code, but I think it is due to the fact that Specify lives as a trait and that assertions are made within anonymous functions that this cannot be easily controlled without calling the Output Control Functions explicitly.

ddziaduch commented 4 years ago

@TavoNiievez wow, this is quiet old issue 😆