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()); }
/** * @param $key * @param bool $display * @return array|bool|int|string * @deprecated */ function _get($key, $display = false) { return $this->props->get($key, $display); }