setMaxAllowedHeight('string'); $this->fail('Exception was expected:' . $expectedExceptionMssg); } catch (Exception $e) { $this->pass('Exception was thrown: ' . $expectedExceptionMssg); } $expectedExceptionMssg = 'should be thrown when not PositiveIntOrNull - empty string'; try { $obj = new Models_AdSlotExtent($width=468, $height=60); $obj->setMaxAllowedHeight(''); $this->fail('Exception was expected:' . $expectedExceptionMssg); } catch (Exception $e) { $this->pass('Exception was thrown: ' . $expectedExceptionMssg); } $expectedExceptionMssg = 'should be thrown when not PositiveIntOrNull - zero'; try { $obj = new Models_AdSlotExtent($width=468, $height=60); $obj->setMaxAllowedHeight(0); $this->fail('Exception was expected:' . $expectedExceptionMssg); } catch (Exception $e) { $this->pass('Exception was thrown: ' . $expectedExceptionMssg); } $expectedExceptionMssg = 'should be thrown when not EqualOrGreaterThanDefaultHeight - 59 < 60'; try { $obj = new Models_AdSlotExtent($width=468, $height=60); $obj->setMaxAllowedHeight(59); $this->fail('Exception was expected:' . $expectedExceptionMssg); } catch (Exception $e) { $this->pass('Exception was thrown: ' . $expectedExceptionMssg); } }//end of single test method } /** And here is the test subject: Fail: example_mulitple_simpletest_expectations_adslotextent.php -> TestOf_Models_AdSlotExtent -> test_setMaxAllowedHeightThrowsErrorWhenNotValid -> Exception was expected:should be thrown when not EqualOrGreaterThanDefaultHeight - 59 < 60 at [example_mulitple_simpletest_expectations_adslotextent.php line 53] **/ /** *@desc to represent an extent of an an adslot * it is not as simple as a 'width and height' - because we also need to define how elastic the extent is. * i.e. how much we can veer from those dimensions and what should happen if if we do. */ class Models_AdSlotExtent { /** *@desc declares whether or not the extent allows content that is greater than this width */ protected $_widthOverflowPermittedFlag = FALSE; /** *@desc declares whether or not the extent allows content that is greater than this height */ protected $_heightOverflowPermittedFlag = TRUE; /** *@desc declares the max total height (maybe different to default height if it overflows) * Null means there is no max height * if value is an int its in pixels * initialized value is NULL - 'no max' (because web pages tend to expand vertically ) */ protected $_maxAllowedHeight = NULL; /** *@desc declares the max total width (maybe different to default height if it overflows) * Null means there is no max height * if value is an int its in pixels * no value initialized value - (because web pages tend not to expand horizontally very well - so this should be set to default width of extent upon construction ) */ protected $_maxAllowedWidth; /** *@desc defines the natural 'resting' width of the extent */ protected $_defaultWidth; /** *@desc defines the natural 'resting' height of the extent */ protected $_defaultHeight; /** *@param $defaultWidth null|int pixels - if null it means unknown *@param $defaultHeight null|int pixels - if null it means unknown */ public function __construct($defaultWidth=NULL,$defaultHeight=NULL) { $this->_defaultWidth = $defaultWidth; $this->_defaultHeight = $defaultHeight; if (!(is_null($defaultWidth))) { //its not null //initialize default properties //by default the max allowed width should be same as default width cos tend to like widths to keep thier values $this->setMaxAllowedWidth($this->_defaultWidth); } } protected function isEitherPositiveIntOrNull($intpixels) { //i know return (((is_numeric($intpixels) && ($intpixels > 0))) || is_null($intpixels) ) ? TRUE : FALSE; } public function setMaxAllowedHeight($intpixels=NULL) { if (!($this->isEitherPositiveIntOrNull($intpixels))) { throw new Exception('intpixels should either be a positive integer or null'); } /* BUT HEY - where is that check on the should be thrown when not EqualOrGreaterThanDefaultHeight Thats why a test should fail if (!($intpixels >= $this->_defaultHeight)) { throw new Exception('intpixels should be EqualOrGreaterThanDefaultHeight'); } */ $this->_maxAllowedHeight=$intpixels; } public function setHeightOverflowPermittedFlag($bool) { $this->_heightOverflowPermittedFlag=$bool; } protected function setMaxAllowedWidth($intpixels=NULL) { if (!($this->isEitherPositiveIntOrNull($intpixels))) { throw new Exception('intpixels should either be a positive integer or null'); } $this->_maxAllowedWidth=$intpixels; } public function getDefaultWidth() { return $this->_defaultWidth; } public function getDefaultHeight() { return $this->_defaultHeight; } }//end of class /** Code Snippet Related to: How to Test for Expected Exception Thrown in Simpletest - *The* Answer See: http://www.eatmybusiness.com/food/2010/01/16/how-to-test-for-expected-exception-thrown-in-simpletest-the-answer/139/ **/