/** * Display a listing of the resource. * * @param $alias string * @return \Illuminate\Http\Response */ public function index($alias) { $items = $this->itemsService->getCategoryItems($alias); if (is_null($items)) { abort(404); } return $items; }
/** * @dataProvider categoryItemsProvider */ public function testGetCategoryItems($alias, array $aliasCategories, array $expectedItems) { $itemStorageMock = $this->getMock('\\App\\Contracts\\Storages\\ItemStorageContract', ['getCategoriesItems']); $serviceMock = $this->getMockBuilder('\\App\\Services\\CategoriesService')->disableOriginalConstructor()->setMethods(['getCategoriesByAlias'])->getMock(); $categoryIDs = array_map(function (Category $category) { return $category->id; }, $aliasCategories); $itemStorageMock->expects(static::any())->method('getCategoriesItems')->with($categoryIDs)->willReturn($expectedItems); $serviceMock->expects(static::once())->method('getCategoriesByAlias')->with($alias)->willReturn($aliasCategories); $itemsService = new ItemsService($itemStorageMock, $serviceMock); $items = $itemsService->getCategoryItems($alias); static::assertEquals($expectedItems, $items); }