Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your minimal test case illustrates some aspects quite nicely:</p> <ol> <li>You are using <code>$this-&gt;assertTrue(true)</code> just for the sake of asserting something.</li> <li>Your tested function does some logging, which is not tested.</li> <li>Your test run is cluttered with log output.</li> </ol> <p>Let's address the third point first: Whatever logger you use, it should be able to get configured to put the log messages somewhere. As it currently seems, the logger just echos the messages. You probably also have the ability to log into a file, or send a mail. Or do nothing at all. So in theory you should be able to silence the log output by applying a configuration just for the tests.</p> <p>The second point: Whenever you silence the logger output, you cannot verify that the logging actually works correctly.</p> <p>Logging actually comes it multiple flavours, one of them is helping the developer debugging the application in case of errors, and another one is leaving an audit trail for very important application transactions. That audit trail logging is a vital part of the behavior of the class, and it must be tested, while the debugging aid is simply an addon to the class that won't hurt the application if it does not happen.</p> <p>So the question is: What is this logging doing in YOUR application? Is it simply a debugging aid, or is it a vital part of application behavior?</p> <p>If it is vital, then it must be tested. And that testing is best accomplished by injecting a mock object of the logger, and assert a call to the <code>log()</code> function, probably with the correct parameters.</p> <p>And if you actually inject that logger mock during your test, the configured assertions for that mock act as the test, and my first point is actually void, because now you HAVE test assertions, but they do not assert the return value (there is none in this example), but the correct calling of an inner object.</p> <p>If, on the other hand, you are not using the logger for something vital, then there is no need to mock and test it. And in this case, the code example is bad, because you really have nothing you could test for. Which should make you wonder whether that function <code>testing()</code> is really worth being there. :)</p> <p>Assuming that a real function would do some other things beyond logging, there should be something that you can test, though. Together with silencing the logger by configuration you should end up having a very clean test output.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload