Пример #1
0
 /**
  * The first message is always added when the object is created, all other
  * message are added via add interface. This error implements both
  * Coutable and Iterator interfaces meaning the following methods are
  * available: count, key, current, next, rewind, valid.
  *
  * @return null
  */
 public function testMessages()
 {
     $this->assertEquals(1, $this->error->count());
     $msg2 = 'second error message';
     $msg3 = 'third error message';
     $msg4 = 'fourth error message';
     $this->assertSame($this->error, $this->error->add($msg2));
     $this->assertEquals(2, $this->error->count());
     $this->assertSame($this->error, $this->error->add($msg3));
     $this->assertEquals(3, $this->error->count());
     $this->assertSame($this->error, $this->error->add($msg4));
     $this->assertEquals(4, $this->error->count());
     $this->assertTrue($this->error->valid());
     $this->assertEquals(0, $this->error->key());
     $this->assertEquals($this->firstMsg, $this->error->current());
     /* go to next message */
     $this->assertNull($this->error->next());
     $this->assertTrue($this->error->valid());
     $this->assertEquals(1, $this->error->key());
     $this->assertEquals($msg2, $this->error->current());
     /* go to next message */
     $this->assertNull($this->error->next());
     $this->assertTrue($this->error->valid());
     $this->assertEquals(2, $this->error->key());
     $this->assertEquals($msg3, $this->error->current());
     /* go to next message */
     $this->assertNull($this->error->next());
     $this->assertTrue($this->error->valid());
     $this->assertEquals(3, $this->error->key());
     $this->assertEquals($msg4, $this->error->current());
     /* try to go past the end */
     $this->assertNull($this->error->next());
     $this->assertFalse($this->error->valid());
     $this->assertNull($this->error->key());
     $this->assertFalse($this->error->current());
     /* go back to the first element */
     $this->assertNull($this->error->rewind());
     $this->assertTrue($this->error->valid());
     $this->assertEquals(0, $this->error->key());
     $this->assertEquals($this->firstMsg, $this->error->current());
 }