예제 #1
0
 /**
  * @return Products[]
  * @param string $categoryName
  */
 public function getProductsByCategoryName($categoryName)
 {
     if (!isset($this->categoryService) || empty($this->categoryService)) {
         return self::CATEGORY_SERVICE_IS_NOT_AVAILABLE;
     }
     return $this->categoryService->getProductsByCategoryName($categoryName);
 }
예제 #2
0
 public function testCategoryServiceReturnsNotFoundCategoryWhenCategoryNameIsNotFound()
 {
     $repository = $this->getMockBuilder(ObjectRepository::class)->getMock();
     $repository->expects(self::once())->method('findOneBy')->willThrowException(new \Exception());
     $service = new CategoryService($repository);
     $category = $service->getCategoryByName('unknown category');
     self::assertEquals(CategoryService::CATEGORY_NOT_FOUND, $category->getName());
 }
예제 #3
0
 /**
  * @test
  */
 public function getAllSuccess()
 {
     $categories = new ArrayCollection();
     $categories->add($this->createCategory(1, 'test1'), $this->createCategory(2, 'test2'));
     $this->repository->expects($this->once())->method('findAll')->will($this->returnValue($categories));
     $result = $this->category_service->getAll();
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $result);
     $this->assertInstanceOf('AppBundle\\Entity\\Category', $result->get(0));
     $this->assertTrue(1 === $result->get(0)->getId());
 }
 /**
  * @Route("/", name="category_registration_save")
  * @Method("post")
  */
 public function saveAction(Request $request)
 {
     $form = $this->form_factory->create('category');
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->service->add($form->getData());
         return $this->redirect($this->generateUrl('app_admin_category_complete'));
     }
     return $this->render('Admin/Category/Registration/index.html.twig', ['form' => $form->createView()]);
 }
예제 #5
0
 /**
  * @Route("/{id}", name="category_edit_post")
  * @ParamConverter("category", class="AppBundle:Category")
  * @Method("post")
  */
 public function editPostAction(Request $request, Category $category)
 {
     $form = $this->form_factory->create('category', $category);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $this->service->update();
         return $this->redirect($this->generateUrl('admin_category'));
     }
     return $this->render('Admin/Category/Registration/index.html.twig', ['form' => $form->createView()]);
 }
예제 #6
0
 /**
  * @Route("/{id}", name="category_remove")
  * @ParamConverter("category", class="AppBundle:Category")
  * @Method("get")
  */
 public function removeAction(Category $category)
 {
     $this->service->remove($category);
     return $this->render('Admin/Category/index.html.twig');
 }
예제 #7
0
 /**
  * @Route("/", name="admin_category")
  * @Method("get")
  */
 public function indexAction()
 {
     $categories = $this->service->getAll();
     return $this->render('Admin/Category/index.html.twig', ['categories' => $categories]);
 }