/** * @covers ::transferFiles */ public function testTransferFiles() { $shops = array(119200, 1321); $tmpDir = '/tmp/dir'; $docContent1 = 'data1'; $docContent2 = 'data2'; $docContent3 = 'data3'; $vendor1 = new Vendor('*****@*****.**', mt_rand(), mt_rand(), 771); $vendor2 = new Vendor('*****@*****.**', mt_rand(), mt_rand(), 772); $document1 = new Document(2006); $document2 = new Document(3011); // Getting documents list $this->mirakl->getFiles($shops)->willReturn(Mirakl::getShopDocuments($shops))->shouldBeCalled(); // Retrieving vendors $this->vendorManager->findByMiraklId(119200)->willReturn($vendor1)->shouldBeCalledTimes(1); $this->vendorManager->findByMiraklId(1321)->willReturn($vendor2)->shouldBeCalledTimes(1); // Checking documents $this->documentManager->findByVendor($vendor1)->willReturn(array(new Document(2008, "LEGAL_IDENTITY_OF_REPRESENTATIVE")))->shouldBeCalledTimes(1); $this->documentManager->findByVendor($vendor2)->willReturn(array(new Document(3006, "ALL_PROOF_OF_BANK_ACCOUNT")))->shouldBeCalledTimes(1); // Download missing documents $this->mirakl->downloadDocuments(array(2006), Argument::any())->willReturn($docContent1)->shouldBeCalledTimes(1); $this->mirakl->downloadDocuments(array(3008), Argument::any())->willReturn($docContent2)->shouldBeCalledTimes(1); $this->mirakl->downloadDocuments(array(3011), Argument::any())->willReturn($docContent3)->shouldBeCalledTimes(1); // Save files on disk $prophet = new PHPProphet(); $prophecy = $prophet->prophesize('HiPay\\Wallet\\Mirakl\\Vendor'); $prophecy->file_put_contents(Argument::containingString('/tmp/dir/'), Argument::containingString('data'))->willReturn(true)->shouldBeCalledTimes(3); $prophecy->reveal(); // Sending documents to HiPay Wallet $this->hipay->uploadDocument(771, HiPay::DOCUMENT_ALL_PROOF_OF_BANK_ACCOUNT, Argument::any(), Argument::any())->shouldBeCalledTimes(1); $this->hipay->uploadDocument(772, HiPay::DOCUMENT_LEGAL_IDENTITY_OF_REPRESENTATIVE, Argument::any(), Argument::any())->willThrow(new ClientErrorResponseException())->shouldBeCalledTimes(1); $this->hipay->uploadDocument(772, HiPay::DOCUMENT_LEGAL_PROOF_OF_REGISTRATION_NUMBER, Argument::any(), Argument::any())->shouldBeCalledTimes(1); // Save document in DB $this->documentManager->create(2006, Argument::type("DateTime"), "ALL_PROOF_OF_BANK_ACCOUNT", $vendor1)->willReturn($document1)->shouldBeCalledTimes(1); $this->documentManager->create(3011, Argument::type("DateTime"), "LEGAL_PROOF_OF_REGISTRATION_NUMBER", $vendor2)->willReturn($document2)->shouldBeCalledTimes(1); $this->documentManager->save(Argument::exact($document1))->shouldBeCalledTimes(1); $this->documentManager->save(Argument::exact($document2))->shouldBeCalledTimes(1); $this->vendorProcessor->transferFiles($shops, $tmpDir); $prophet->checkPredictions(); }
protected function defineFunction($namespace, $functionName) { PHPProphet::define($namespace, $functionName); }