title: Unit testing report script
body: <p>I have a report that runs every week. The class basically looks like this (pseudo-code):</p>
  
  <pre><code>class mailreport {
    public function exec() {
       users = Users::getAll();
       for u in users {
          r = this.generateReportData(u);
          m = this.generateMail(r);
          sendMail(u, m);
       }
    } 
  
    protected generateReport(User u) {
       // do lots of calculation, return report
    }
  
    // ...
  }
  </code></pre>
  
  <p>Most of the bugs in this report are in the <code>generateReport</code>-method. It also does lots of pretty "pure" calculations, and would be easy to unit test if it weren't protected. The <code>exec</code>-method is hard to test because it has several dependencies and the output is a sent email with HTML.</p>
  
  <p>How should I break out the <code>generateReport</code>-method so I can unit-test it more easily? I could of course create some kind of <code>Report</code>-class with a public <code>generate</code>-method, but then why not just have a stand alone function?</p>