コード例 #1
0
 public function testOnPostSubmitExistingProduct()
 {
     $product = $this->createProduct(1);
     $event = $this->createEvent($product);
     $newCategory = $this->createCategory(1);
     $categoryWithProduct = $this->createCategory(2);
     $categoryWithProduct->addProduct($product);
     $this->assertCategoryAdd($event, $newCategory);
     $this->categoryRepository->expects($this->once())->method('findOneByProduct')->will($this->returnValue($categoryWithProduct));
     $this->extension->onPostSubmit($event);
     $this->assertEquals([$product], $newCategory->getProducts()->toArray());
     $this->assertEquals([], $categoryWithProduct->getProducts()->toArray());
 }
コード例 #2
0
 protected function setUp()
 {
     $this->product = new Product();
     $this->sourceProduct = new Product();
     $this->category = new Category();
     $this->doctrineHelper = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\DoctrineHelper')->disableOriginalConstructor()->getMock();
     $this->categoryRepository = $this->getMockBuilder('OroB2B\\Bundle\\CatalogBundle\\Entity\\Repository\\CategoryRepository')->disableOriginalConstructor()->getMock();
     $this->categoryRepository->expects($this->once())->method('findOneByProduct')->will($this->returnCallback(function () {
         $args = func_get_args();
         $product = $args[0];
         if ($this->category->getProducts()->contains($product)) {
             return $this->category;
         } else {
             return null;
         }
     }));
     $this->objectManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->doctrineHelper->expects($this->once())->method('getEntityRepository')->with($this->categoryClass)->will($this->returnValue($this->categoryRepository));
     $this->doctrineHelper->expects($this->any())->method('getEntityManager')->with($this->categoryClass)->will($this->returnValue($this->objectManager));
     $this->listener = new ProductDuplicateListener();
     $this->listener->setCategoryClass($this->categoryClass);
     $this->listener->setDoctrineHelper($this->doctrineHelper);
 }