Sonata\Component\Basket\BasketManager::save PHP Method

save() public method

public save ( $entity, $andFlush = true )
    public function save($entity, $andFlush = true)
    {
        foreach ($entity->getBasketElements() as $element) {
            $element->setBasket($entity);
        }
        parent::save($entity, $andFlush);
    }

Usage Example

 public function testSave()
 {
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $em->expects($this->once())->method('persist');
     $em->expects($this->once())->method('flush');
     $registry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry');
     $registry->expects($this->any())->method('getManagerForClass')->will($this->returnValue($em));
     $basketMgr = new BasketManager('Sonata\\Component\\Basket\\Basket', $registry);
     $basket = new Basket();
     $basketMgr->save($basket);
 }