echo 'File path: ' . $tmpfpath . PHP_EOL; $fp = fopen($tmpfpath, "w"); fwrite($fp, "This is some demo text."); fclose($fp); /** * End: Make a temporary file and write some data --------------------- */ /** * Start: Example --------------------- */ $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. */
/** * @dataProvider setOptionsProvider */ public function testSetOptions($var, $valid, $invalid, $message, $method) { $options[$var] = $invalid; $sut = new Dfp_Datafeed_Transfer_Adapter_Ftp(); $passed = false; try { $sut->setOptions($options); } catch (Dfp_Datafeed_Transfer_Exception $e) { if ($e->getMessage = $message) { $passed = True; } } $this->assertTrue($passed, 'Exception not thrown'); $options[$var] = $valid; $sut->setOptions($options); $this->assertEquals($valid, $sut->{'get' . $method}()); }