Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide output during PHPUnit test execution

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.

like image 326
MyMomSaysIamSpecial Avatar asked Jul 30 '15 07:07

MyMomSaysIamSpecial


People also ask

What is assertion in PHPUnit?

The assertEquals() function is a builtin function in PHPUnit and is used to assert whether the actual obtained value is equals to expected value or not. This assertion will return true in the case if the expected value is the same as the actual value else returns false.

Which method is used to create a mock with PHPUnit?

PHPUnit provides methods that are used to automatically create objects that will replace the original object in our test. createMock($type) and getMockBuilder($type) methods are used to create mock object. The createMock method immediately returns a mock object of the specified type.

What is the use of PHPUnit?

PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit architecture for unit testing frameworks that originated with SUnit and became popular with JUnit.


1 Answers

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

like image 80
Matteo Avatar answered Sep 22 '22 08:09

Matteo