public function testSendFile() { $mockAdapter = $this->getMock('Dfp_Datafeed_Transfer_Adapter_Interface'); $mockAdapter->expects($this->once())->method('sendFile')->with($this->equalTo('test.txt'), $this->equalTo('test.csv')); $sut = new Dfp_Datafeed_Transfer(); $passed = false; try { $sut->sendFile('test.txt', 'test.csv'); } catch (Dfp_Datafeed_Transfer_Exception $e) { $passed = true; } $this->assertTrue($passed, 'Failed to throw exception when adapter is missing'); $sut->setAdapter($mockAdapter); $sut->sendFile('test.txt', 'test.csv'); }
* Alternatively, all options can be set using setters. For example: * * @example $adapter->setBasePath($tempPath); * @example $adapter->setPassive(true); */ /** * Add the FTP adapter to the transfer component */ $transfer->setAdapter($adapter); /** * Attempt to send the file. This is wrapped in a try/catch as it can throw an * Dfp_Datafeed_Transfer_Adapter_Exception exception. If we were in a loop of * files, we would want this to continue if a file transfer failed. */ try { $transfer->sendFile($tmpfname); } catch (Dfp_Datafeed_Transfer_Adapter_Exception $e) { echo 'Dfp_Datafeed_Transfer_Adapter_Exception Occurred with Message: ' . $e->getMessage() . PHP_EOL; } /** * All errors are saved to an array which is accessable via the getErrors() method as shown below. * Even when an exception is thrown, the error is recorded. This enables you to catch the exceptions * and continue, then grab the errors to evaluate later. */ if ($transfer->hasErrors()) { echo 'Errors: ' . print_r($transfer->getErrors(), true) . PHP_EOL; } echo 'End' . PHP_EOL; /** * End: Example --------------------- */