setData($data) ->setDataLength($dataLength); } /* getters and setters */ public function __toString() { // e.g. echo new DataSetValue(DataSetValue::ALPHA_LOWER, 2) would output "ab" return substr($this->getData(), 0, $this->getDataLength()); } } class AssertionTuple { protected $assertionMethod = ''; protected $data; public function __construct($assertionMethod, DataSetValue $data) { $this->setAssertionMethod($assertionMethod) ->setData($data); } } class AssertionStack implements Iterator { private $position = 0; protected $stack = array(); public function push(AssertionTuple $tuple) { $this->stack[] = $tuple; } public function rewind() { $this->position = 0; } public function current() { return $this->stack[$this->position]->getData(); } public function key() { return $this->stack[$this->position]->getAssertionMethod(); } public function next() { ++$this->position; } public function valid() { return isset($this->stack[$this->position]); } } class UnitTest extends PHPUnit_Framework_TestCase { public function testAddress1() { $stack = new AssertionStack; $stack->push(new AssertionTuple('equals', new DataSetValue(DataSetValue::ALPHA_NUMERIC))) ->push(new AssertionTuple('notEquals', new DataSetValue(DataSetValue::SYMBOLS))); foreach ($stack as $assertionMethod => $data) { $this->instance->setAddress2($data); $assertionMethod = 'assert' . ucfirst($assertionMethod); $this->$assertionMethod($data, $this->instance->getAddress2()); } }