* 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 --------------------- */
public function testGetErrors() { $sut = new Dfp_Datafeed_Transfer(); $this->assertEmpty($sut->getErrors()); $mockAdapter = $this->getMock('Dfp_Datafeed_Transfer_Adapter_Interface'); $mockAdapter->expects($this->once())->method('getErrors')->will($this->returnValue(array('error'))); $sut->setAdapter($mockAdapter); $this->assertEquals(array('error'), $sut->getErrors()); }