<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;h1&gt;Introduction&lt;/h1&gt;
&lt;p&gt;There are times where you will want behavior beyond a basic assertion, or you expect an error to occur because of bad data passed in. SnapTest can account for these things using special test conditions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; These are the only three &amp;#8220;Assertions&amp;#8221; that are not required to have a return statement. This is because their occurrence will naturally interrupt the running test and therefore won&amp;#8217;t have time to reach a return statement.&lt;/p&gt;
&lt;h1&gt;Using $this&amp;#8594;willThrow($class_name)&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;$this-&amp;gt;willThrow($class_name)&lt;/code&gt; specifically can handle the unhandled exception that may be encountered. This is simply a shorthand way of writing the following test:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
// willThrow method
public function testMethod() {
    $this-&amp;gt;willThrow('Foo_Exception');
    $test_obj-&amp;gt;brokenMethod(); // throws a foo
}

// traditional method
public function testMethod() {
    try {
        $test_obj-&amp;gt;brokenMethod(); // throws a foo
    }
    catch (Foo_Exception $e) {
        return $this-&amp;gt;assertIsA($e, 'Foo_Exception');
    }
    catch (Exception $e) {
        return $this-&amp;gt;assertIsA($e, 'Foo_Exception');
    }
    return $this-&amp;gt;assertIsA(false, 'Foo_Exception'); // no good descriptor for this part
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h1&gt;Using $this&amp;#8594;willError()&lt;/h1&gt;
&lt;p&gt;Similar to the willThrow call, using &lt;code&gt;$this-&amp;gt;willError()&lt;/code&gt; indicates to the test class that the currently running test will cause a &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; error. Any errors encountered during the running of the test are swallowed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; Errors are not always failures. However, in the default report format (text), you will be notified if any warnings or errors were encountered in your script.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
public function testMethod() {
    $this-&amp;gt;willError();
    $this-&amp;gt;methodDoesArrayOpsWithoutChecking(null);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h1&gt;Using $this&amp;#8594;todo()&lt;/h1&gt;
&lt;p&gt;The last of the special assertions indicates a test that is not complete. This will end the running testMethod and throw a failure. This is very useful for marking untested functionality that is needed, or flagging a method that does not have all its tests written.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
public function testMethod() {
    $this-&amp;gt;todo();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An optional message can be passed into todo() which will be displayed in the output.&lt;/p&gt;
&lt;h1&gt;Using $this&amp;#8594;skip()&lt;/h1&gt;
&lt;p&gt;If the criteria aren&amp;#8217;t met, then it&amp;#8217;s possible to skip over a test that cannot be run, as opposed to throwing an error. For example, a MySQL test on an Oracle system would probably fail, so it&amp;#8217;s safe to skip that test as opposed to failing it. Skipped tests are counted as neither passes nor fails.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
public function testMethod() {
    $this-&amp;gt;skip();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An optional message can be passed into skip() which will be displayed in the output. Additionally, putting &lt;code&gt;$this-&amp;gt;skip()&lt;/code&gt; in your setup() method makes it possible to skip all tests in a given class.&lt;/p&gt;</body>
  <created-at type="datetime">2009-11-26T18:51:00-08:00</created-at>
  <id type="integer">266967</id>
  <permalink>special-assertions</permalink>
  <repository-id type="integer">1880</repository-id>
  <title>Special Assertions</title>
  <updated-at type="datetime">2009-07-15T09:51:25-07:00</updated-at>
  <user-id type="integer">1795</user-id>
</wiki>
