public function testMarshall() { $customerDto = new CustomerDto(); $customerDto->setDeskId(1111111); $customerDto->setWebptId(232); $customerDto->setFirstName('Imma'); $customerDto->setLastName('Tool'); $customerDto->setEmail('*****@*****.**'); $customerDto->setDeskCompanyId(99); $customerDto->setUserType('short'); /** @var \PHPUnit_Framework_MockObject_MockObject|\DeskModule\Client\ClientCommand $clientCommand */ $clientCommand = $this->getMock('\\DeskModule\\Client\\ClientCommand', array('prepareOperation'), array(), '', false); $clientCommand->setCommand(new EmbeddedCommand()); $clientCommand->expects($this->once())->method('prepareOperation')->with(Reflection::invoke($this->marshaller, 'getOperation'))->will($this->returnValue($clientCommand)); /** @var \PHPUnit_Framework_MockObject_MockObject $factory */ $factory = $this->getMock('DeskModule\\Client\\Factory'); $factory->expects($this->once())->method('get')->will($this->returnValue($clientCommand)); $this->marshaller->setClientFactory($factory); /** @var \DeskModule\Client\ClientCommand $result */ $result = $this->marshaller->marshall($customerDto); $this->assertInstanceOf('\\DeskModule\\Client\\ClientCommand', $result); $command = $clientCommand->getCommand(); $this->assertEquals($customerDto->getDeskId(), $command->get('id')); $this->assertEquals($customerDto->getWebptId(), $command->get('external_id')); $this->assertEquals($customerDto->getFirstName(), $command->get('first_name')); $this->assertEquals($customerDto->getLastName(), $command->get('last_name')); $this->assertEquals($customerDto->getDeskCompanyId(), $command->get('company_id')); $emails = $command->get('emails'); $this->assertCount(1, $emails); $this->assertEquals($customerDto->getEmail(), $emails[0]->value); $customFields = $command->get('custom_fields'); $this->assertEquals($customerDto->getUserType(), $customFields['user_type']); }
/** * @expectedException \DeskModule\Client\Customer\Exception\CreateFailed */ public function testMarshallThrowsExceptionWhenNonNumericDeskCompanyId() { $customerDto = new CustomerDto(); $customerDto->setWebptId(232); $customerDto->setFirstName('Imma'); $customerDto->setLastName('Tool'); $customerDto->setEmail('*****@*****.**'); $customerDto->setDeskCompanyId('desk_99'); $customerDto->setUserType('short'); /** @var \Desk\Relationship\Resource\EmbeddedCommand $result */ $this->marshaller->marshall($customerDto); }
public function testExecuteActionCallCustomerServiceStore() { $entity = 'a customer'; $customerDto = new CustomerDto(); $customerDto->setDeskCompanyId(1); /** @var \PHPUnit_Framework_MockObject_MockObject|\DeskModule\Queue\Marshal\Customer\JsonToCustomerDto $marshaller */ $marshaller = $this->getService()->getJsonToCustomerMarshaller(); $marshaller->expects($this->once())->method('marshall')->with($entity)->will($this->returnValue($customerDto)); $action = new ActionModel(); $action->setAction(ActionModel::ACTION_SYNC)->setEntityType(ActionModel::ENTITY_TYPE_CUSTOMER)->setEntity($entity); /** @var \PHPUnit_Framework_MockObject_MockObject|\DeskModule\Customer\Customer $customerService */ $customerService = $this->getService()->getCustomerService(); $customerService->expects($this->once())->method('store')->with($customerDto); $this->getService()->setCurrentAction($action); Reflection::invoke($this->getService(), 'executeAction'); }