Example #1
0
 public function testGetProperty()
 {
     /** @var Item $item */
     $item = Item::load(1);
     Item::addProperty('id_info', function () {
         return 'Id of';
     });
     Item::addProperty('id_info', function ($fieldValue) {
         return "{$fieldValue} " . get_class($this);
     });
     Item::addProperty('id_info', function ($fieldValue) {
         /** @var \Test\Item $this */
         return "{$fieldValue} is {$this->id}";
     });
     $this->assertEquals('Id of Test\\Item is 1', $item->id_info);
     /** @var SubItem $subItem */
     $subItem = SubItem::load(2);
     SubItem::addProperty('id_info', function () {
         return '2x id of';
     });
     SubItem::addProperty('id_info', function ($fieldValue) {
         return "{$fieldValue} " . get_class($this);
     });
     SubItem::addProperty('id_info', function ($fieldValue) {
         /** @var \Test\Item $this */
         return "{$fieldValue} is " . $this->id * 2;
     });
     $this->assertEquals('2x id of Test\\SubItem is 4', $subItem->id_info);
 }