/**
  * Test for Product twig extension
  */
 public function testAvailableOptions()
 {
     $product = $this->getMock('Elcodi\\Component\\Product\\Entity\\Product', [], [], '', false);
     $variant = $this->getMock('Elcodi\\Component\\Product\\Entity\\Variant', [], [], '', false);
     $attribute = $this->getMock('Elcodi\\Component\\Attribute\\Entity\\Attribute', [], [], '', false);
     $option = new Value();
     $option->setId(111);
     $option->setAttribute($attribute);
     $product->expects($this->once())->method('getVariants')->willReturn(new ArrayCollection([$variant]));
     $variant->expects($this->once())->method('getStock')->willReturn(100);
     $variant->expects($this->once())->method('IsEnabled')->willReturn(true);
     $variant->expects($this->once())->method('getOptions')->willReturn(new ArrayCollection([$option]));
     $productExtension = new ProductExtension();
     $this->assertEquals(new ArrayCollection([$option]), $productExtension->getAvailableOptions($product, $attribute));
 }
Exemple #2
0
 /**
  * Shortcut for creating a new Value / Attribute
  *
  * @param integer   $size      Collection size
  * @param Attribute $attribute Whether to use an existing Attribute for the Options
  *
  * @return ArrayCollection
  */
 private function createNewOptionCollection($size = 1, Attribute $attribute = null)
 {
     if (is_null($attribute)) {
         $attribute = new Attribute();
     }
     $optionCollection = new ArrayCollection();
     while ($size--) {
         $option = new Value();
         $option->setAttribute($attribute);
         $optionCollection->add($option);
     }
     return $optionCollection;
 }