Skip to content

Instantly share code, notes, and snippets.

@shama
Created October 26, 2011 21:02
Show Gist options
  • Save shama/1317838 to your computer and use it in GitHub Desktop.
Save shama/1317838 to your computer and use it in GitHub Desktop.
Mocking up CakeFTP
/**
* 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