assert() public method

Runs an expectation directly, for extending the tests with new expectation classes.
public assert ( SimpleExpectation $expectation, mixed $compare, string $message = '%s' ) : boolean
$expectation SimpleExpectation Expectation subclass.
$compare mixed Value to compare.
$message string Message to display.
return boolean True on pass
Example #1
0
 /**
  *    Tests the type of a value.
  *    @param $value          Value to take type of.
  *    @param $type           Hoped for type.
  *    @param $message        Message to display.
  *    @public
  */
 function assertType($value, $type, $message = "%s")
 {
     parent::assert(new TrueExpectation(), gettype($value) == strtolower($type), $message);
 }
Example #2
0
 /**
  *    Receives event from unit test that the current
  *    test method has finished. Totals up the call
  *    counts and triggers a test assertion if a test
  *    is present for expected call counts.
  *    @param string $test_method      Current method name.
  *    @param SimpleTestCase $test     Test to send message to.
  *    @access public
  */
 function atTestEnd($test_method, &$test)
 {
     foreach ($this->_expected_counts as $method => $expectation) {
         $test->assert($expectation, $this->getCallCount($method));
     }
     foreach ($this->_max_counts as $method => $expectation) {
         if ($expectation->test($this->getCallCount($method))) {
             $test->assert($expectation, $this->getCallCount($method));
         }
     }
 }
 /**
  *    Compares the expected exception with any
  *    in the queue. Issues a pass or fail and
  *    returns the state of the test.
  *    @param SimpleTestCase $test    Test case to send messages to.
  *    @param Exception $exception    Exception to compare.
  *    @return boolean                False on no match.
  */
 function isExpected($test, $exception)
 {
     if ($this->expected) {
         return $test->assert($this->expected, $exception, $this->message);
     }
     foreach ($this->ignored as $ignored) {
         if ($ignored->test($exception)) {
             return true;
         }
     }
     return false;
 }
 /**
  *    Compares the expected exception with any
  *    in the queue. Issues a pass or fail and
  *    returns the state of the test.
  *    @param SimpleTestCase $test    Test case to send messages to.
  *    @param Exception $exception    Exception to compare.
  *    @return boolean                False on no match.
  */
 function isExpected($test, $exception)
 {
     if ($this->expected) {
         return $test->assert($this->expected, $exception, $this->message);
     }
     return false;
 }
 /**
  *    Tests a regex match.
  *    @param $pattern        Regex to match.
  *    @param $subject        String to search in.
  *    @param $message        Message to display.
  *    @public
  */
 function assertRegexp($pattern, $subject, $message = false)
 {
     parent::assert(new PatternExpectation($pattern), $subject, $message);
 }