AttributeBagReferenceTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. use Fhaculty\Graph\Attribute\AttributeBagReference;
  3. class AttributeBagReferenceTest extends TestCase
  4. {
  5. public function testEmpty()
  6. {
  7. $attributes = array();
  8. $bag = new AttributeBagReference($attributes);
  9. $this->assertNull($bag->getAttribute('unknown'));
  10. $this->assertEquals('default', $bag->getAttribute('unknown', 'default'));
  11. $this->assertEquals(array(), $bag->getAttributes());
  12. $this->assertSame($bag, $bag->getAttributeBag());
  13. }
  14. public function testSome()
  15. {
  16. $attributes = array(
  17. 'true' => true,
  18. 'two' => 2,
  19. );
  20. $bag = new AttributeBagReference($attributes);
  21. $this->assertSame(true, $bag->getAttribute('true'));
  22. $this->assertSame(2, $bag->getAttribute('two'));
  23. $this->assertEquals(array('true' => true, 'two' => 2), $bag->getAttributes());
  24. $bag->setAttribute('float', '1.2');
  25. $bag->setAttributes(array('two' => 'two', 'three' => 3));
  26. $expected = array('true' => true, 'two' => 'two', 'float' => 1.2, 'three' => 3);
  27. $this->assertEquals($expected, $bag->getAttributes());
  28. $this->assertEquals($expected, $attributes);
  29. }
  30. }