title: Unit testing functions with side effects?
body: <p>Let's say you're writing a function to check if a page was reached by the appropriate URL. The page has a "canonical" stub - for example, while a page could be reached at stackoverflow.com/questions/123, we would prefer (for SEO reasons) to redirect it to stackoverflow.com/questions/123/how-do-i-move-the-turtle-in-logo - and the actual redirect is safely contained in its own method (eg. redirectPage($url)), but how do you properly test the function which calls it?</p>
  
  <p>For example, take the following function:</p>
  
  <pre><code>function checkStub($questionId, $baseUrl, $stub) {
    canonicalStub = model-&gt;getStub($questionId);
    if ($stub != $canonicalStub) {
      redirectPage($baseUrl . $canonicalStub);
    }
  }
  </code></pre>
  
  <p>If you were to unit test the checkStub() function, wouldn't the redirect get in the way?</p>
  
  <p>This is part of a larger problem where certain functions seem to get too big and leave the realm of unit testing and into the world of integration testing. My mind immediately thinks of routers and controllers as having these sorts of problems, as testing them necessarily leads to the generation of pages rather than being confined to just their own function.</p>
  
  <p>Do I just fail at unit testing?</p>