Example #1
0
 /**
  * Tests the offsets.
  *
  * @test
  * @uses \Bairwell\Hydrator\CachedClass::__construct
  * @uses \Bairwell\Hydrator\CachedClass::getName
  * @covers \Bairwell\Hydrator\CachedClass::offsetGet
  * @covers \Bairwell\Hydrator\CachedClass::offsetSet
  * @covers \Bairwell\Hydrator\CachedClass::count
  * @covers \Bairwell\Hydrator\CachedClass::offsetUnset
  * @covers \Bairwell\Hydrator\CachedClass::offsetExists
  * @covers \Bairwell\Hydrator\CachedClass::add
  */
 public function testCachedClassOffset()
 {
     $sut = new CachedClass('test2');
     $from = new From();
     $storedProperty = new CachedProperty('test2', 'abc', $from);
     $sut->add($storedProperty);
     $this->assertEquals(1, $sut->count());
     $this->assertTrue($sut->offsetExists('abc'));
     $this->assertInternalType('array', $sut->offsetGet('abc'));
     $this->assertCount(1, $sut->offsetGet('abc'));
     $this->assertSame($storedProperty, $sut->offsetGet('abc')[0]);
     // add a second
     $second = new CachedProperty('test2', 'abc', $from);
     $sut->add($second);
     $this->assertEquals(1, $sut->count());
     $this->assertInternalType('array', $sut->offsetGet('abc'));
     $this->assertCount(2, $sut->offsetGet('abc'));
     $this->assertSame($storedProperty, $sut->offsetGet('abc')[0]);
     $this->assertSame($second, $sut->offsetGet('abc')[1]);
     // add a third with a different name
     $third = new CachedProperty('test2', 'test', $from);
     $sut->offsetSet('test', $third);
     $this->assertEquals(2, $sut->count());
     $this->assertInternalType('array', $sut->offsetGet('test'));
     $this->assertCount(1, $sut->offsetGet('test'));
     $this->assertSame($third, $sut->offsetGet('test')[0]);
     // unset test
     $sut->offsetUnset('abc');
     $this->assertEquals(1, $sut->count());
     $this->assertInternalType('array', $sut->offsetGet('test'));
     $this->assertCount(1, $sut->offsetGet('test'));
     $this->assertSame($third, $sut->offsetGet('test')[0]);
     $this->assertNull($sut->offsetGet('abc'));
 }