Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function transform($value)
 {
     if (!is_array($value) && !is_null($value)) {
         throw new UnexpectedTypeException($value, 'array');
     }
     if (empty($value)) {
         return new ArrayCollection();
     }
     return new ArrayCollection($this->productRepository->findBy(['code' => $value]));
 }
 /**
  * @param ProductInterface $owner
  *
  * @return string[]
  */
 private function getAssociatedProductsAsArray(ProductInterface $owner)
 {
     $products = $this->productRepository->findBy(['mainTaxon' => $owner->getMainTaxon()]);
     $products = $this->faker->randomElements($products, 3);
     $associatedProducts = [];
     /** @var ProductInterface $product */
     foreach ($products as $product) {
         $associatedProducts[] = $product->getCode();
     }
     return $associatedProducts;
 }
 function it_transforms_only_existing_products(ProductRepositoryInterface $productRepository, ProductInterface $bow)
 {
     $productRepository->findBy(['code' => ['bow', 'sword']])->willReturn([$bow]);
     $products = new ArrayCollection([$bow->getWrappedObject()]);
     $this->transform(['bow', 'sword'])->shouldBeCollection($products);
 }