if (!file_exists($srcPath)) { mkdir($srcPath, 0777, true); } $sourceFile = $srcPath . '/temp-dfp-source-file.txt'; //file_put_contents($sourceFile, 'Some-data'); //$sourceFile = 'file://' . $sourceFile; echo $sourceFile . PHP_EOL; // Get a testing destination path. $destinationDirectory = $sysTmpDir . '/dfp-dst'; if (!file_exists($destinationDirectory)) { mkdir($destinationDirectory, 0777, true); } /** * Instantiate the trasfer component. */ $transfer = new Dfp_Datafeed_Transfer(); /** * Create an instance of the Stream adapter. */ $adapter = new Dfp_Datafeed_Transfer_Adapter_Stream(); /** * Set the destination directory. */ $adapter->setBasePath($destinationDirectory); /** * Set the source stream scheme to file://. */ $adapter->setSchema('file'); /** * Get the path of the source file. */
$tempPath .= DS . 'dfp'; echo 'Temporary File Path: ' . $tempPath . PHP_EOL; $tmpfpath = tempnam($tempPath, "dfp"); $tmpfname = trim(str_replace($tempPath, '', $tmpfpath), DIRECTORY_SEPARATOR); echo 'File name: ' . $tmpfname . PHP_EOL; 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);
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')); }