public function testUsage() { /* * Komponenty * SearchManager * SearchForm * SearchResult * SearchSettings */ //Defines props. Components has to decide, if it will use it (default) //or will use their oru value $dependency1 = new Dependency1(); $dependency2 = new Dependency2(); $propsSearchManager = new Props(['searchForm.PlaceHolder' => 'Default placeholder', 'searchResult.ActiveColor' => '#red', 'searchSettings.ShowGlobal' => false, 'dependency1' => $dependency1, 'dependency2' => $dependency2, 'renderMethod' => function () { echo "Hello world"; }]); //$control = new SearchManagerControl($propsSearchManager) //In search manager, who builds 3 components, search manager creates // // in SearchManager, creating SearchForm $searchFormProps = $propsSearchManager->create(['searchForm.PlaceHolder']); $searchFormProps->{"searchForm.ShowDescription"} = true; $searchControl = new SearchManagerControl($propsSearchManager); $searchControl['search']; $this->assertSame($dependency1, $searchControl->dep); }
public function testCreate() { $props = new Props(['a' => 5, 'b' => 1000, 'c' => 'c']); $props->computed('sum', function ($props) { return $props->a + $props->b; }); $this->assertEquals(['a', 'b', 'c', 'sum'], $props->keys()); $clone1 = $props->create(['a', 'sum'], ['extra' => 'extra_value']); $this->assertFalse($clone1->immutable()); $this->assertEquals(['extra', 'a', 'sum'], $clone1->keys()); $clone1->computed('b', function ($props) { return $props->a * 100; }); $this->assertEquals(['extra', 'a', 'sum', 'b'], $clone1->keys()); $this->assertEquals(500, $clone1->b); $this->assertEquals(505, $clone1->sum); $this->assertException(function () use($props) { $props->create(['a', 'b'], ['a' => 3]); }, 'Ra\\PropExistsException'); }