$transfer = new Dfp_Datafeed_Transfer(); $adapter = new Dfp_Datafeed_Transfer_Adapter_Ftp(); /** * Options can either be set using the key in this array or using setters. */ $adapter->setOptions(array('username' => '<your-ftp-username>', 'password' => '<your-ftp-password>', 'host' => '<your-ftp-host>', 'timeout' => 120, 'basePath' => $tempPath, 'passive' => true)); /** * 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. */
public function testSetErrors() { $sut = new Dfp_Datafeed_Transfer(); $passed = false; try { $sut->setErrors(array('error', 'error2')); } catch (Dfp_Datafeed_Transfer_Exception $e) { $passed = true; } $this->assertTrue($passed, 'Failed to throw exception when adapter is missing'); $mockAdapter = $this->getMock('Dfp_Datafeed_Transfer_Adapter_Interface'); $mockAdapter->expects($this->once())->method('setErrors')->with($this->equalTo(array('error', 'error2'))); $sut->setAdapter($mockAdapter); $sut->setErrors(array('error', 'error2')); }