protected function prepareServices()
 {
     $this->form->expects($this->once())->method('setData')->with($this->entity);
     $this->form->expects($this->once())->method('submit')->with($this->request);
     $this->request->setMethod('POST');
     $this->form->expects($this->once())->method('isValid')->willReturn(true);
     $this->manager->expects($this->at(0))->method('persist')->with($this->isType('object'));
     $repository = $this->getMockBuilder('OroB2B\\Bundle\\PricingBundle\\Entity\\Repository\\PriceListRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->any())->method('setPriceListToAccount')->will($this->returnCallback(function (Account $account, PriceList $priceList = null) {
         $this->entity->removeAccount($account);
         if ($priceList) {
             $this->entity->addAccount($account);
         }
     }));
     $repository->expects($this->any())->method('setPriceListToAccountGroup')->will($this->returnCallback(function (AccountGroup $accountGroup, PriceList $priceList = null) {
         $this->entity->removeAccountGroup($accountGroup);
         if ($priceList) {
             $this->entity->addAccountGroup($accountGroup);
         }
     }));
     $repository->expects($this->any())->method('setPriceListToWebsite')->will($this->returnCallback(function (Website $website, PriceList $priceList = null) {
         $this->entity->removeWebsite($website);
         if ($priceList) {
             $this->entity->addWebsite($website);
         }
     }));
     $this->manager->expects($this->any())->method('getRepository')->with($this->isType('string'))->willReturn($repository);
     $this->manager->expects($this->exactly(2))->method('flush');
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $now = new \DateTime();
     foreach ($this->data as $priceListData) {
         $priceList = new PriceList();
         $priceList->setName($priceListData['name'])->setDefault($priceListData['default'])->setCurrencies(['USD'])->setCreatedAt($now)->setUpdatedAt($now);
         foreach ($priceListData['accounts'] as $accountReference) {
             /** @var Account $account */
             $account = $this->getReference($accountReference);
             $priceList->addAccount($account);
         }
         foreach ($priceListData['groups'] as $accountGroupReference) {
             /** @var AccountGroup $accountGroup */
             $accountGroup = $this->getReference($accountGroupReference);
             $priceList->addAccountGroup($accountGroup);
         }
         foreach ($priceListData['websites'] as $websiteReference) {
             /** @var Website $website */
             $website = $this->getReference($websiteReference);
             $priceList->addWebsite($website);
         }
         foreach ($priceListData['currencies'] as $currencyCode) {
             $priceList->addCurrencyByCode($currencyCode);
         }
         $manager->persist($priceList);
         $this->setReference($priceListData['reference'], $priceList);
     }
     $manager->flush();
 }
 /**
  * @param Account $account
  * @param PriceList $priceList
  */
 public function setPriceListToAccount(Account $account, PriceList $priceList = null)
 {
     $oldPriceList = $this->getPriceListByAccount($account);
     if ($oldPriceList && $priceList && $oldPriceList->getId() === $priceList->getId()) {
         return;
     }
     if ($oldPriceList) {
         $oldPriceList->removeAccount($account);
     }
     if ($priceList) {
         $priceList->addAccount($account);
     }
 }