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'); }