/**
  * Upload a file that contain a batch of members
  * 
  * @param MemberFileImport $memberFileImport
  *
  * @throws \Exception
  */
 public function uploadFile(MemberFileImport $memberFileImport)
 {
     $this->uploadFileCheckSupportedOptions($memberFileImport);
     $this->uploadFileCheckMandatoryOptions($memberFileImport);
     $options = $memberFileImport->getOptions();
     $fileContent = $options->getParameterByName('file');
     $criteria = $options->getParameterByName('criteria');
     $dateFormat = $options->getParameterByName('dateFormat');
     $skipFirstLine = $options->getParameterByName('skipFirstLine');
     $mapping = $options->getParameterByName('mapping');
     $fileEncoding = $memberFileImport->getFileEncoding();
     $separator = $memberFileImport->getSeparator();
     if (null === $criteria) {
         $criteria = self::CRITERIA_DEFAULT;
     }
     if (null === $fileEncoding) {
         $fileEncoding = self::ENCODING_DEFAULT;
     }
     if (null === $separator) {
         $separator = self::SEPARATOR_DEFAULT;
     }
     if (null === $dateFormat) {
         $dateFormat = self::DATEFORMAT_DEFAULT;
     }
     if (null === $skipFirstLine) {
         $skipFirstLine = self::SKIPFIRSTLINE_DEFAULT;
     }
     if (null !== $mapping) {
         $mapping = $mapping->getValue();
     } else {
         // Auto-mapping
         $mapping = $this->autoMapColumn($fileContent->getValue(), $separator);
     }
     $this->service->uploadFileMerge($fileContent->getValue(), $memberFileImport->getFileName(), $criteria, $this->handleMappingOption($mapping), $fileEncoding, $separator, $skipFirstLine, $dateFormat);
 }
 public function testUploadFileMerge()
 {
     $response = $this->getXMLFileMock('uploadFileMergeResponse.xml');
     $fileContent = 'EMAIL|EXTRATEST username@mail.com|0';
     $filename = 'file.csv';
     $criteria = 'LOWER(EMAIL)';
     $mapping = '<mapping>' . '<column>' . '<colNum>1</colNum>' . '<fieldName>EMAIL</fieldName>' . '</column>' . '<column>' . '<colNum>2</colNum>' . '<fieldName>EXTRATEST</fieldName>' . '<toReplace>true</toReplace>' . '</column>' . '</mapping>';
     $fileEncoding = 'UTF-8';
     $separator = '|';
     $skipFirsLine = false;
     $dateFormat = 'mm/dd/yyyy';
     $parameters['mergeUpload'] = ['fileName' => $filename, 'fileEncoding' => $fileEncoding, 'separator' => $separator, 'skipFirstLine' => $skipFirsLine, 'dateFormat' => $dateFormat, 'criteria' => $criteria, 'mapping' => $mapping, 'file' => $fileContent];
     $apiClient = $this->getMockBuilder('\\MyLittle\\CampaignCommander\\API\\SOAP\\APIClient')->disableOriginalConstructor()->getMock();
     $apiClient->expects($this->once())->method('doCall')->with('uploadFileMerge', $parameters)->will($this->returnValue($response));
     $this->clientFactory->expects($this->any())->method('createClient')->will($this->returnValue($apiClient));
     $service = new BatchMemberService($this->clientFactory);
     $this->assertEquals($response, $service->uploadFileMerge($fileContent, $filename, $criteria, $mapping, $fileEncoding, $separator, $skipFirsLine, $dateFormat));
 }