public function testHandle() { $pricing = $this->dummyData->getPricing(); $productService = $this->mockService->getProductService(); $dtoBuilderFactory = $this->getDTOBuilderFactory(); $request = new GetProductRequest(self::UUID_HEX); $response = new GetProductResponse($pricing); $handler = new GetProductHandler($productService, $dtoBuilderFactory); $handler->handle(new GetProductQuery($request, $response)); $this->assertTrue($response->getProductDTO() instanceof ProductDTO); $handler->handle(new GetProductQuery($request, $response)); $this->assertTrue($response->getProductDTOWithAllData() instanceof ProductDTO); }
/** * @param string $slug * @param string $productId * @return \Illuminate\Http\RedirectResponse */ public function show($slug, $productId) { $request = new GetProductRequest($productId); $response = new GetProductResponse($this->getPricing()); $this->dispatchQuery(new GetProductQuery($request, $response)); $productDTO = $response->getProductDTOWithAllData(); if ($slug !== $productDTO->slug) { return redirect()->route('product.show', ['slug' => $productDTO->slug, 'productId' => $productDTO->id->getHex()]); } $request = new GetRandomProductsRequest(4); $response = new GetRandomProductsResponse($this->getPricing()); $this->dispatchQuery(new GetRandomProductsQuery($request, $response)); $relatedProductDTOs = $response->getProductDTOs(); return $this->renderTemplate('product/show.twig', ['product' => $productDTO, 'relatedProducts' => $relatedProductDTOs]); }
/** * @return $productDTO */ protected function getDummyProduct($name = null, $isVisible = true) { $faker = \Faker\Factory::create(); if ($name === null) { $name = $faker->name; } $productDTO = new ProductDTO(); $productDTO->name = $name; $productDTO->description = $faker->paragraph(5); $productDTO->defaultImage = $faker->imageUrl(); $productDTO->sku = $faker->randomNumber(5); $productDTO->unitPrice = $faker->numberBetween(100, 2000); $productDTO->isVisible = $isVisible; $productDTO->isActive = true; $productDTO->rating = $faker->numberBetween(100, 500); $productDTO->shippingWeight = $faker->numberBetween(10, 40); $command = new CreateProductCommand($productDTO); $this->dispatch($command); $productId = $command->getProductId()->getHex(); $request = new GetProductRequest($productId); $response = new GetProductResponse($this->getPricing()); $this->dispatchQuery(new GetProductQuery($request, $response)); return $response->getProductDTO(); }