예제 #1
0
파일: PropsTest.php 프로젝트: jasir/Ra
 public function testPropsCreation()
 {
     $props = new Props(['prop1' => 1, 'prop2' => 2]);
     $this->assertEquals(['prop1', 'prop2'], $props->keys());
     //default state is immutable
     $this->assertFalse($props->immutable());
     //accessing properties
     $this->assertEquals(1, $props->prop1);
     $this->assertEquals(1, $props->get('prop1'));
     $this->assertException(function () use($props) {
         $props->nogood;
     }, 'Ra\\PropNotFoundException');
     $props->computed('sum', function ($props) {
         return $props->prop1 + $props->prop2;
     });
     $this->assertEquals(3, $props->sum);
     $this->assertEquals(3, $props->get('sum'));
     // setting props
     $props->newProp = 4;
     $this->assertEquals(4, $props->newProp);
     $this->assertException(function () use($props) {
         $props->newProp = 5;
     }, 'Ra\\PropExistsException');
     $this->assertTrue($props->immutable(true));
     // when in immutable, throws
     $this->assertException(function () use($props) {
         $props->moreProperty = 5;
     }, 'Ra\\PropsImmutableException');
     $this->assertFalse($props->immutable(false));
     $this->assertFalse($props->immutable());
     //$prop->keys - keys are sorted
     $this->assertEquals(['prop1', 'prop2', 'newProp', 'sum'], $props->keys());
 }