Example #1
0
 /**
  * Tests the offsets.
  *
  * @test
  * @uses \Bairwell\Hydrator\CachedClass::__construct
  * @uses \Bairwell\Hydrator\CachedClass::getName
  * @uses \Bairwell\Hydrator\CachedClass::add
  * @covers \Bairwell\Hydrator\CachedClass::offsetSet
  * @uses \Bairwell\Hydrator\CachedClass::count
  * @covers \Bairwell\Hydrator\CachedClass::current
  * @covers \Bairwell\Hydrator\CachedClass::next
  * @covers \Bairwell\Hydrator\CachedClass::key
  * @covers \Bairwell\Hydrator\CachedClass::valid
  * @covers \Bairwell\Hydrator\CachedClass::rewind
  */
 public function testCachedClassIterator()
 {
     $sut = new CachedClass('test3');
     $this->assertEquals('test3', $sut->getName());
     $from = new From();
     $storedProperty = $first = new CachedProperty('test3', 'abc', $from);
     $second = new CachedProperty('test3', 'abc', $from);
     $third = new CachedProperty('test3', 'def', $from);
     $fourth = new CachedProperty('test3', 'def', $from);
     $sut->add($first);
     $sut->add($second);
     $sut->add($third);
     $sut->add($fourth);
     $this->assertCount(2, $sut);
     $iterations = 0;
     foreach ($sut as $k => $v) {
         if ('abc' === $k) {
             $this->assertEquals([$first, $second], $v);
             $iterations++;
         } elseif ('def' === $k) {
             $this->assertEquals([$third, $fourth], $v);
             $iterations++;
         } else {
             $this->fail('Unexpected key:' . $k);
         }
     }
     $this->assertEquals(2, $iterations);
 }