public function testFetchProgenitor()
 {
     list($conn, $query) = $this->getMocks();
     $instance = new CategoryItemRepository($conn);
     $mockItemEntity1 = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockItemEntity2 = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $conn->shouldReceive('table')->andReturn($query);
     $query->shouldReceive('whereIn')->once()->with('id', m::on(function ($closure) use($query) {
         $query->shouldReceive('select')->once()->with('descendant')->andReturnSelf();
         $query->shouldReceive('from')->andReturnSelf();
         $query->shouldReceive('whereIn')->once()->with('ancestor', m::on(function ($closure) use($query) {
             $query->shouldReceive('select')->once()->with('id')->andReturnSelf();
             $query->shouldReceive('where')->once()->with('categoryId', 1)->andReturnSelf();
             call_user_func($closure, $query);
             return true;
         }))->andReturnSelf();
         $query->shouldReceive('groupBy')->once()->with('descendant')->andReturnSelf();
         $query->shouldReceive('havingRaw')->once()->with('count(*) = 1')->andReturnSelf();
         call_user_func($closure, $query);
         return true;
     }))->andReturnSelf();
     $query->shouldReceive('get')->andReturn([$mockItemEntity1, $mockItemEntity2]);
     $instance->fetchProgenitor(1);
 }
 /**
  * Get top level items by category id
  *
  * @param int $categoryId category id
  * @return array of item object
  */
 public function progenitorsByCategoryId($categoryId)
 {
     $progenitors = $this->itemRepo->fetchProgenitor($categoryId);
     return $this->sort($progenitors);
 }