title: unit testing and Static methods
body: <p>Reading up and picking up on unit testing, trying to make sense of <a href="http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/" rel="noreferrer">the following post</a> on that explains the hardships of static function calls. </p>
  
  <p>I don't clearly understand this issue.  I have always assumed static functions were a nice way of rounding up utility functions in a class. For example, I often  use static functions calls to initialise,  ie:</p>
  
  <pre><code>Init::loadConfig('settings.php');
  Init::setErrorHandler(APP_MODE); 
  Init::loggingMode(APP_MODE);
  
  // start loading app related objects ..
  $app = new App();
  </code></pre>
  
  <p>// After reading the post, I now aim for this instead ...</p>
  
  <pre><code>$init = new Init();
  $init-&gt;loadConfig('settings.php');
  $init-&gt;loggingMode(APP_MODE);
   // etc ...
  </code></pre>
  
  <p>But, the few dozen tests I had written for this class are the same. I changed nothing and they still all pass. Am I doing something wrong?</p>
  
  <p>The author of the post states the following:</p>
  
  <blockquote>
    <p><em>The basic issue with static methods is they are procedural code. I have no idea how to unit-test procedural code. Unit-testing assumes that I can instantiate a piece of my application in isolation. During the instantiation I wire the dependencies with mocks/friendlies which replace the real dependencies. With procedural programing there is nothing to “wire” since there are no objects, the code and data are separate.</em></p>
  </blockquote>
  
  <p>Now, I understand from the post that static methods create dependencies, but don't grasp intuitively why one cannot test the return value of a  static method just as easily as a regular method?</p>
  
  <p>I will be avoiding static methods, but I would of liked having an idea of WHEN static methods are useful, if at all. It seems from this post static methods are just about as evil as global variables and should be avoided as much as possible.</p>
  
  <p>Any additional information or links on the subject would be greatly appreciated.</p>