/** * @dataProvider processValidDataProvider * * @param bool $isDataChanged */ public function testProcessValidData($isDataChanged) { $appendedAccount = new Account(); $appendedAccount->setId(1); $removedAccount = new Account(); $removedAccount->setId(2); $this->entity->addAccount($removedAccount); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $appendForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $appendForm->expects($this->once())->method('getData')->will($this->returnValue(array($appendedAccount))); $this->form->expects($this->at(3))->method('get')->with('appendAccounts')->will($this->returnValue($appendForm)); $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $removeForm->expects($this->once())->method('getData')->will($this->returnValue(array($removedAccount))); $this->form->expects($this->at(4))->method('get')->with('removeAccounts')->will($this->returnValue($removeForm)); if ($isDataChanged) { $this->manager->expects($this->once())->method('persist')->with($this->entity); } else { $this->manager->expects($this->exactly(2))->method('persist')->with($this->entity); } $this->manager->expects($this->once())->method('flush'); $this->configureUnitOfWork($isDataChanged); $this->assertTrue($this->handler->process($this->entity)); $actualAccounts = $this->entity->getAccounts()->toArray(); $this->assertCount(1, $actualAccounts); $this->assertEquals($appendedAccount, current($actualAccounts)); }
public function testHasAccounts() { $contact = new Contact(); $this->assertFalse($contact->hasAccounts()); $contact->addAccount(new Account()); $this->assertTrue($contact->hasAccounts()); }
/** * Append contacts to account * * @param Contact $contact * @param Account[] $accounts */ protected function appendAccounts(Contact $contact, array $accounts) { foreach ($accounts as $account) { $contact->addAccount($account); } }