public function testHasMany() { list($conn, $query) = $this->getMocks(); $instance = new CategoryItemRepository($conn); $targetId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; $mockItemEntity1 = m::mock('Xpressengine\\Category\\CategoryItemEntity'); $mockItemEntity2 = m::mock('Xpressengine\\Category\\CategoryItemEntity'); $conn->shouldReceive('table')->andReturn($query); $query->shouldReceive('leftJoin')->andReturnSelf(); $query->shouldReceive('where')->once()->with('used.targetId', $targetId)->andReturnSelf(); $query->shouldReceive('select')->once()->with(['node.*'])->andReturnSelf(); $query->shouldReceive('get')->once()->andReturn([$mockItemEntity1, $mockItemEntity2]); $items = $instance->hasMany($targetId); $this->assertEquals(2, count($items)); }
/** * Get a target used items * * @param string $targetId target id * @return CategoryItemEntity[] */ public function hasMany($targetId) { return $this->itemRepo->hasMany($targetId); }