Example #1
0
 /**
  * Tests the add.
  *
  * @test
  * @uses \Bairwell\Hydrator\CachedClass::__construct
  * @uses \Bairwell\Hydrator\CachedClass::getName
  * @covers \Bairwell\Hydrator\CachedClass::count
  * @covers \Bairwell\Hydrator\CachedClass::add
  * @covers \Bairwell\Hydrator\CachedClass::get
  * @covers \Bairwell\Hydrator\CachedClass::offsetGet
  * @covers \Bairwell\Hydrator\CachedClass::offsetExists
  **/
 public function testAdd()
 {
     $sut = new CachedClass('test2');
     $this->assertEquals('test2', $sut->getName());
     $this->assertEquals(0, $sut->count());
     $this->assertFalse($sut->offsetExists('abc'));
     $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->assertEquals([$storedProperty], $sut->offsetGet('abc'));
     $storedProperty2 = new CachedProperty('test2', 'abc', $from);
     $sut->add($storedProperty2);
     $this->assertEquals(1, $sut->count());
     $this->assertTrue($sut->offsetExists('abc'));
     $this->assertInternalType('array', $sut->offsetGet('abc'));
     $this->assertCount(2, $sut->offsetGet('abc'));
     $this->assertEquals([$storedProperty, $storedProperty2], $sut->offsetGet('abc'));
     $this->assertEquals([$storedProperty, $storedProperty2], $sut['abc']);
     $this->assertEquals([$storedProperty, $storedProperty2], $sut->get('abc'));
     $this->assertEquals([], $sut->get('stuff'));
     // error
     $storedProperty3 = new CachedProperty('tedsdsdsst2', 'abc', $from);
     try {
         $sut->add($storedProperty3);
         $this->fail('Expected exception');
     } catch (\TypeError $e) {
         $this->assertEquals('Cannot add property "abc" for class tedsdsdsst2 to class test2', $e->getMessage());
     }
 }