Ejemplo n.º 1
0
 /**
  * @covers RecordsMan\RecordSet::add
  */
 public function testAdd()
 {
     /** @var Item $item */
     $item = Item::load(1);
     $subsCount = $item->subItems->count();
     $item->subItems->add(SubItem::create(['title' => 'New subitem']));
     $this->assertEquals($subsCount + 1, $item->subItems->count());
     /** @var SubItem $createdItem */
     $createdItem = SubItem::findFirst(null, ['id' => 'DESC']);
     $this->assertEquals($createdItem->item_id, $item->id);
     $this->assertEquals('New subitem', $createdItem->title);
     //TODO: Test counters updating, through relations, etc.
 }
Ejemplo n.º 2
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);
 }