16

I have some var_dumps in my php code (i understand what there must be none in the end, but still), and while tests are running they outputs non necessary information to console, is there a method to ignore some code execution?

I've tried

/**
 * @codeCoverageIgnore
 */

and

// @codeCoverageIgnoreStart
print '*';
// @codeCoverageIgnoreEnd

But this just ignores coverage, and still executes the code.

Itsmeromka
  • 3,621
  • 9
  • 46
  • 79
  • @codeCoverageIgnore is used for ignoring lines at the Code Coverage Report, but the lines will still be executed. – gontrollez Jul 30 '15 at 09:49

1 Answers1

32

You can set the setOutputCallback to a do nothing function. The effect is to suppress any output printed in the test or in the tested class.

As Example:

namespace Acme\DemoBundle\Tests;


class NoOutputTest extends \PHPUnit_Framework_TestCase {

    public function testSuppressedOutput()
    {
        // Suppress  output to console
        $this->setOutputCallback(function() {});
        print '*';
        $this->assertFalse(false, "Don't see the *");
    }

}

You can find some reference in the doc

Hope this help

Matteo
  • 37,680
  • 11
  • 100
  • 115