mercoledì 21 settembre 2011

Extremely Simple PHP Unit Test Framework/3 [ENG]

Part I

Part II

We've seen the test suite, the test, the test runner (the contraption required to get the test to run). The last thing is the test base class which implements the assertions.

class Test
{

 function assertEquals($expected, $got)
 {
  if ($expected!=$got)
  {
   trigger_error("Expected '" .$expected. "' but got '" .$got. "'", E_USER_ERROR);
  }
 }

 function assertContains($haystack, $needle)
 {
  if (strpos($haystack, $needle)<0)
  {
   trigger_error("String '" .$needle. "' is not contained in '" .$haystack. "'", E_USER_ERROR);
  }
 }
 
 function assertNotNull($object)
 {
  if ($object==NULL)
  {
   trigger_error("assertNotNull failure", E_USER_ERROR);
  }
 }
 
 function assertTrue($condition)
 {
  if (!$condition)
  {
   trigger_error("assertTrue failed", E_USER_ERROR);
  }
 } 
 
}

As you can see I kept that really really simple.

Nessun commento: