public function showAction() { $serializer = new Serializer([new ObjectNormalizer()], [new JsonEncode()]); $data = $this->productService->getAll(); $jsonData = $serializer->serialize($data, 'json'); return $this->templateEngine->renderResponse('AppBundle:admin:productList.html.twig', array('products' => $jsonData)); }
public function testProductServiceGetProductById() { $productId = 5; $repository = $this->getMockBuilder(ObjectRepository::class)->getMock(); $product = new Product(); $repository->expects(self::once())->method('findOneBy')->with(['id' => $productId])->will(self::returnValue($product->setId($productId))); $service = new ProductService($repository); self::assertEquals($product->setId($productId), $service->getProductById($productId)); }
public function testProductStatusWillBeSetToSuspendedWhenProductServiceSuspendingProduct() { $product = new Product('test'); $this->productService->suspend($product); self::assertEquals(ProductStatus::SUSPENDED, $product->getStatus()); }