public function testProcessValidData() { $appendedContact = new Contact(); $appendedContact->setId(1); $removedContact = new Contact(); $removedContact->setId(2); $this->entity->addContact($removedContact); $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)); $this->form->expects($this->once())->method('has')->with('contacts')->will($this->returnValue(true)); $contactsForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $appendForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $appendForm->expects($this->once())->method('getData')->will($this->returnValue(array($appendedContact))); $contactsForm->expects($this->at(0))->method('get')->with('added')->will($this->returnValue($appendForm)); $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $removeForm->expects($this->once())->method('getData')->will($this->returnValue(array($removedContact))); $contactsForm->expects($this->at(1))->method('get')->with('removed')->will($this->returnValue($removeForm)); $this->form->expects($this->exactly(1))->method('get')->with('contacts')->will($this->returnValue($contactsForm)); $this->manager->expects($this->once())->method('persist')->with($this->entity); $this->manager->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->entity)); $actualContacts = $this->entity->getContacts()->toArray(); $this->assertCount(1, $actualContacts); $this->assertEquals($appendedContact, current($actualContacts)); }
public function testGetPhoneNumbers() { $entity = new Account(); $contact1 = $this->getMockBuilder('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact')->disableOriginalConstructor()->getMock(); $contact2 = $this->getMockBuilder('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact')->disableOriginalConstructor()->getMock(); $entity->setDefaultContact($contact1); $entity->addContact($contact1); $entity->addContact($contact2); $this->rootProvider->expects($this->at(0))->method('getPhoneNumbers')->with($this->identicalTo($contact1))->will($this->returnValue([['123-123', $contact1], ['456-456', $contact1]])); $this->rootProvider->expects($this->at(1))->method('getPhoneNumbers')->with($this->identicalTo($contact2))->will($this->returnValue([['789-789', $contact2], ['111-111', $contact2]])); $this->assertEquals([['123-123', $contact1], ['456-456', $contact1], ['789-789', $contact2], ['111-111', $contact2]], $this->provider->getPhoneNumbers($entity)); }
public function testRemoveContact() { $account = new Account(); $account->setId(1); $contact = new Contact(); $contact->setId(2); $account->addContact($contact); $this->assertCount(1, $account->getContacts()->toArray()); $account->removeContact($contact); $this->assertEmpty($account->getContacts()->toArray()); }
/** * Append contacts to account * * @param Account $account * @param Contact[] $contacts */ protected function appendContacts(Account $account, array $contacts) { foreach ($contacts as $contact) { $account->addContact($contact); } }