/** * @dataProvider aliasCatepories */ public function testGetCategoriesByAlias($alias, $expectedCategories) { $categoryStorageMock = $this->getMock('\\App\\Contracts\\Storages\\CategoryStorageContract', ['getHighLevelCategories', 'getByAlias']); $categoryStorageMock->expects(self::once())->method('getByAlias')->with($alias)->willReturn($expectedCategories); $categoriesService = new CategoriesService($categoryStorageMock); $categories = $categoriesService->getCategoriesByAlias($alias); self::assertEquals($expectedCategories, $categories); }
/** * Returns category items * * @param string $alias * @return array */ public function getCategoryItems($alias) { $categories = $this->categoryService->getCategoriesByAlias($alias); if (count($categories) === 0) { return []; } $categoryIDs = array_map(function (Category $category) { return $category->id; }, $categories); return $this->itemStorage->getCategoriesItems($categoryIDs); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return response()->json($this->categoriesService->getHighLevelCategories()); }