title: How to test specific methods with PHPUnit
body: <p>I need help with PHPUnit and some methods. How should you guys write tests in PHPUnit to reach a high code coverage for the following properties and methods?</p>
  
  <p>I'm pretty new to PHPUnit and could need some help. I've just write some test cases for more basic code. This class generates flash messages for the end user, and store it in a session.</p>
  
  <p>Extremely grateful for some help. Any ideas?</p>
  
  <pre><code>private $sessionKey = 'statusMessage';
  private $messageTypes = ['info', 'error', 'success', 'warning']; // Message types.
  private $session = null;
  private $all = null;
  
  public function __construct() {
      if(isset($_SESSION[$this-&gt;sessionKey])) {
          $this-&gt;fetch();
      }
  }
  
  public function fetch() {
      $this-&gt;all = $_SESSION[$this-&gt;sessionKey];
  }
  
  public function add($type = 'debug', $message) {
      $statusMessage = ['type' =&gt; $type, 'message' =&gt; $message];
  
      if (is_null($this-&gt;all)) {
          $this-&gt;all = array();
      }
  
      array_push($this-&gt;all, $statusMessage);
  
      $_SESSION[$this-&gt;sessionKey] = $this-&gt;all;
  }
  
  public function clear() {
      $_SESSION[$this-&gt;sessionKey] = null;
      $this-&gt;all = null;
  }
  
  public function html() {
      $html = null;
  
      if(is_null($this-&gt;all))
          return $html;
  
      foreach ($this-&gt;all as $message) {
  
          $type = $message['type'];
          $message = $message['message'];
  
          $html .= "&lt;div class='message-" . $type . "'&gt;" . $message . "&lt;/div&gt;";
  
      }
  
      $this-&gt;clear();
  
      return $html;
  }
  </code></pre>
  
  <p>I have setup an setup-case, like this:</p>
  
  <pre><code>protected function setUp() {
      $this-&gt;flash = new ClassName();
  }
  </code></pre>
  
  <p>Also tried one test case:</p>
  
  <pre><code>public function testFetch() {
      $this-&gt;assertEquals($this-&gt;flash-&gt;fetch(), "statusMessage", "Wrong session key.");
  }
  </code></pre>
  
  <p>But gets an error message telling me: "Undefined variable: _SESSION"
  If I then try:</p>
  
  <pre><code>public function testFetch() {
      $_SESSION = array();
      $this-&gt;assertEquals($this-&gt;flash-&gt;fetch(), "statusMessage", "Wrong session key.");
  }
  </code></pre>
  
  <p>I get another error message telling: "Undefined index: statusMessage"</p>