public function tearDown()
 {
     parent::tearDown();
     $this->vendorManager->checkProphecyMethodsPredictions();
     $this->operationManager->checkProphecyMethodsPredictions();
     $this->hipay->checkProphecyMethodsPredictions();
     $this->mirakl->checkProphecyMethodsPredictions();
     $this->documentManager->checkProphecyMethodsPredictions();
 }
 /**
  * Transfer the files from Mirakl to HiPay using REST endpoint.
  *
  * @param array $shopIds
  * @param $tmpFilePath
  * @throws Exception
  */
 public function transferFiles(array $shopIds, $tmpFilePath)
 {
     if (count($shopIds) > 0) {
         // Fetches all Mirakl file names
         $allMiraklFiles = array();
         foreach (array_chunk($shopIds, 50) as $someShopIds) {
             $allMiraklFiles = array_merge($allMiraklFiles, $this->mirakl->getFiles($someShopIds));
         }
         $docTypes = $this->documentTypes;
         // We only keep the files with types we know
         $files = array_filter($allMiraklFiles, function ($aFile) use($docTypes) {
             return in_array($aFile['type'], array_keys($docTypes));
         });
         foreach ($shopIds as $shopId) {
             $this->logger->info('Will check files for Mirakl shop ' . $shopId);
             // Fetches documents already sent to HiPay Wallet
             $vendor = $this->vendorManager->findByMiraklId($shopId);
             $documents = $this->documentManager->findByVendor($vendor);
             // Keep Mirakl files for this shop only
             $theFiles = array_filter($files, function ($file) use($shopId) {
                 return $file['shop_id'] == $shopId;
             });
             $this->logger->info('Found ' . count($theFiles) . ' files on Mirakl for shop ' . $shopId);
             // Check all files for current shop
             foreach ($theFiles as $theFile) {
                 $filesAlreadyUploaded = array_values(array_filter($documents, function (DocumentInterface $document) use($theFile) {
                     return $document->getDocumentType() == $theFile['type'] && $document->getMiraklDocumentId() == $theFile['id'];
                 }));
                 // File not uploaded (or outdated)
                 if (count($filesAlreadyUploaded) === 0) {
                     $this->logger->info('Document ' . $theFile['id'] . ' (type: ' . $theFile['type'] . ') for Mirakl for shop ' . $shopId . ' is not uploaded or not up to date. Will upload');
                     $validityDate = null;
                     if (in_array($this->documentTypes[$theFile['type']], array(HiPay::DOCUMENT_SOLE_BUS_IDENTITY, HiPay::DOCUMENT_INDIVIDUAL_IDENTITY, HiPay::DOCUMENT_LEGAL_IDENTITY_OF_REPRESENTATIVE))) {
                         $validityDate = new DateTime('+1 year');
                     }
                     $tmpFile = $tmpFilePath . '/mirakl_kyc_downloaded_file.tmp';
                     file_put_contents($tmpFile, $this->mirakl->downloadDocuments(array($theFile['id'])));
                     try {
                         $this->hipay->uploadDocument($vendor->getHiPayUserSpaceId(), $this->documentTypes[$theFile['type']], $tmpFile, $validityDate);
                         $newDocument = $this->documentManager->create($theFile['id'], new \DateTime($theFile['date_uploaded']), $theFile['type'], $vendor);
                         $this->documentManager->save($newDocument);
                         $this->logger->info('Upload done. Document saved with ID: ' . $newDocument->getId());
                     } catch (ClientErrorResponseException $e) {
                         try {
                             $message = 'The document ' . $theFile['type'] . ' for Mirakl shop ' . $shopId . ' could not be uploaded to HiPay Wallet for the following reason: ';
                             $this->logger->critical($message . $e->getMessage() . ' - ' . ($e->getResponse() !== null ? $e->getResponse()->getBody(true) : ''));
                         } catch (\Exception $ex) {
                             throw $ex;
                         }
                     }
                 } else {
                     $this->logger->info('Document ' . $theFile['id'] . ' (type: ' . $theFile['type'] . ') for Mirakl for shop ' . $shopId . ' is already uploaded with ID ' . $filesAlreadyUploaded[0]->getId());
                 }
             }
         }
     }
 }