Created
October 26, 2011 21:02
-
-
Save shama/1317838 to your computer and use it in GitHub Desktop.
Mocking up CakeFTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* testConnect | |
*/ | |
public function testConnect() { | |
// FTP FAILED CONNECT | |
$this->FtpSource = $this->getMock('FtpSource', array('_ftp'), array($this->defaultConfig)); | |
$callback = create_function('$method,$params', <<<END | |
if (\$method == "ftp_connect") { | |
return false; | |
} | |
return true; | |
END | |
); | |
$this->FtpSource->expects($this->any()) | |
->method('_ftp') | |
->will($this->returnCallback($callback)); | |
try { | |
$this->assertFalse($this->FtpSource->connect()); | |
} catch (Exception $e) { | |
$this->assertEqual($e->getMessage(), 'Failed to connect'); | |
} | |
// FTP FAILED LOGIN | |
$this->FtpSource = $this->getMock('FtpSource', array('_ftp'), array($this->defaultConfig)); | |
$callback = create_function('$method,$params', <<<END | |
if (\$method == "ftp_login") { | |
return false; | |
} | |
return true; | |
END | |
); | |
$this->FtpSource->expects($this->any()) | |
->method('_ftp') | |
->will($this->returnCallback($callback)); | |
try { | |
$this->assertFalse($this->FtpSource->connect()); | |
} catch (Exception $e) { | |
$this->assertEqual($e->getMessage(), 'Login failed'); | |
} | |
// FTP SUCCESS | |
$this->FtpSource = $this->getMock('FtpSource', array('_ftp'), array($this->defaultConfig)); | |
$callback = create_function('$method,$params', 'return true;'); | |
$this->FtpSource->expects($this->any()) | |
->method('_ftp') | |
->will($this->returnCallback($callback)); | |
$this->assertTrue($this->FtpSource->connect()); | |
// TODO: ADD SFTP | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment