Example #1
0
 /**
  * Set a target used category item
  *
  * @param string             $targetId target id
  * @param CategoryItemEntity $item     item object
  * @return void
  */
 public function used($targetId, CategoryItemEntity $item)
 {
     if (!$this->itemRepo->existsUsed($targetId, $item)) {
         $this->itemRepo->insertUsed($targetId, $item);
         $item->count++;
         $this->itemRepo->update($item);
     }
 }
 public function testInsertUsed()
 {
     list($conn, $query) = $this->getMocks();
     $instance = new CategoryItemRepository($conn);
     $targetId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
     $mockItemEntity = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockItemEntity->id = 2;
     $conn->shouldReceive('table')->andReturn($query);
     $query->shouldReceive('insert')->once()->with(m::on(function ($array) use($targetId) {
         return $array['targetId'] === $targetId && $array['itemId'] === 2;
     }));
     $instance->insertUsed($targetId, $mockItemEntity);
 }