php/pecl-networking-ssh2 — pull request #3 by mageekguy (2013-12-10 08:54:59+00:00)
Title: Add reflection API support.

Currently, `ssh2` function does not support reflection API.
So, it's not possible to retrieve theirs parameters and it's a problem in unit tests (for example) because it's not possible to mock correctly these functions and assert on them efficiently.
So, this PR add reflection API support, so it's now possible to do:
```php
fch@Mageekbook:~/Pecl/Ssh2(master *)
26> php -a
Interactive shell

php > $f = new reflectionFunction('ssh2_exec');
php > var_dump($f->getParameters());
array(7) {
[0]=>
&object(ReflectionParameter)#2 (1) {
["name"]=>
string(7) "session"
}
[1]=>
&object(ReflectionParameter)#3 (1) {
["name"]=>
string(7) "command"
}
[2]=>
&object(ReflectionParameter)#4 (1) {
["name"]=>
string(3) "pty"
}
[3]=>
&object(ReflectionParameter)#5 (1) {
["name"]=>
string(3) "env"
}
[4]=>
&object(ReflectionParameter)#6 (1) {
["name"]=>
string(5) "width"
}
[5]=>
&object(ReflectionParameter)#7 (1) {
["name"]=>
string(6) "height"
}
[6]=>
&object(ReflectionParameter)#8 (1) {
["name"]=>
string(17) "width_height_type"
}
}
php >
```
And with atoum, you can do:
```php
public function testOpen()
{
$this
->given($session = $this->getTestedClassInstance())

->if($this->function->ssh2_connect = false)
->then
->exception(function() use ($session) { $session->open(); })
->isInstanceOf('ssh\session\exception')
->hasMessage('Unable to open a SSH session on \'' . $session->getHost() . '\' on port \'' . $session->getPort() . '\'')
->function('ssh2_connect')->wasCalledWithArguments($session->getHost(), $session->getPort())->once()

->if(
$this->function->ssh2_connect = $resource = uniqid(),
$this->function->ssh2_auth_pubkey_file = false
)
->then
->exception(function() use ($session) { $session->open(); })
->isInstanceOf('ssh\session\exception')
->hasMessage('Unable to authenticate user \'' . $session->getUsername() . '\' on host \'' . $session->getHost() . '\' on port \'' . $session->getPort() . '\'')
->function('ssh2_connect')
->wasCalledWithArguments($session->getHost(), $session->getPort())
->before($this->function('ssh2_auth_pubkey_file')->wasCalledWithArguments($resource, $session->getUsername(), $session->getPublicKeyFile(), $session->getPrivateKeyFile())->once())
->once()
;
}
```