title: PHPUnit - Testing Switch/Default cases
body: <p>I have a question about PHPUnit. I want to write a test case for the following <em><code>Message</code></em> class and want to cover the <em><code>default: case</code></em> in my test cases by passing an invalid <em><code>$type</code></em> in the <code>isValidMessageType()</code> method. Just to give you a proper scenario of when this will be useful, suppose the developer adds another type i.e. 3 in the <code>isValidMessageType()</code> method but forgets to add a switch case in the <code>SendMessage()</code> method, in that scenario the default case will throw an exception.</p>
  
  <pre><code>class Message
  {
  
      public function isValidMessageType($type)
      {
          return ($type == 1 || $type == 2)
      }
  
      public function SendMessage($type)
      {
  
          if(!$this-&gt;isValidMessageType($type)){
              throw new Exception('Invalid Message type');
          }
  
          switch ($type) {
              case 1:
                  // do something
                  break;
              case 2:
                  // do something
                  break;
              default:
                  throw new Exception('Invalid Message type');
          }
  
      }
  
  }
  </code></pre>
  
  <p>Can someone please help me how to achieve this?</p>
  
  <p>Thanks in advance</p>