Пример #1
0
 /**
  * Shmock the class {@see self::shmock()} and then register that shmock
  * to be returned by @see \Bart\Diesel
  *
  * @param string $className FQCN to shmock and reigster with Diesel
  * @param callable $configureShmock Closure that will configure all expectations on \Shmock\PHPUnitSpec
  * @param boolean $noConstructor Disable original constructor?
  * @return mixed The shmocked class
  */
 public function shmockAndDieselify($className, $configureShmock, $noConstructor = false)
 {
     $shmock = $this->shmock($className, $configureShmock, $noConstructor);
     Diesel::registerInstantiator($className, function () use($shmock) {
         return $shmock;
     });
     return $shmock;
 }
Пример #2
0
 public function testGetNewCommand()
 {
     Diesel::registerInstantiator('Bart\\Shell', function () {
         // Just let Shell do its magic
         return new Shell();
     });
     $host = 'www.example.com';
     $ssh = new SshWrapper($host);
     $command = $ssh->createShellCommand('who -r');
     $expectedSshCommand = "ssh 'www.example.com' -q -p '22' -o 'UserKnownHostsFile=/dev/null' -o 'StrictHostKeyChecking=no' 'who -r'";
     $this->assertEquals($expectedSshCommand, "{$command}", 'the command string');
 }
Пример #3
0
 public function testFailedSearch()
 {
     if ($this->skipIfNoLdap()) {
         return;
     }
     $mock = $this->getMock('Bart\\PHPLDAP');
     $mock->expects($this->exactly(2))->method('ldap_bind')->will($this->returnValueMap(array(array('conn', 'binduser', 'bindpw', true), array('conn', $this->brayDN, 'jbraynardpwd', false))));
     $this->stubSearchSequence($mock);
     Diesel::registerInstantiator('Bart\\PHPLDAP', function () use($mock) {
         return $mock;
     });
     $ldap = new Ldap($this->config);
     $ldap->connect();
     $this->assertThrows('\\Bart\\LdapException', "LDAP Auth: failure, username/password did not match for {$this->brayDN}", function () use($mock, $ldap) {
         $ldap->auth_user('jbraynard', 'jbraynardpwd');
     });
 }
Пример #4
0
 public function test_get_current_user()
 {
     $server = 'server';
     $cmd = 'whoami';
     $confStub = array('connection' => array('user' => 'jbraynard', 'key_file_location' => 'path/to/private_key'));
     // =( ...until there's a better way to match commands to results
     $sshCmd = "ssh -q -p 22  -i {$confStub['connection']['key_file_location']}" . "   -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" . " {$confStub['connection']['user']}@{$server} {$cmd} 2>&1";
     $mockShell = new Stub\MockShell($this);
     $mockShell->expectExec($sshCmd, array('Anything'), 0, 0);
     $mockConfig = $this->getMock('\\Bart\\Config_Parser', array(), array(), '', false);
     $mockConfig->expects($this->once())->method('parse_conf_file')->will($this->returnValue($confStub));
     Diesel::registerInstantiator('Bart\\Shell', function () use($mockShell) {
         return $mockShell;
     });
     Diesel::registerInstantiator('Bart\\Config_Parser', function () use($mockConfig) {
         return $mockConfig;
     });
     $ssh = new Ssh($server);
     $ssh->use_auto_user();
     $result = $ssh->execute($cmd);
     $this->assertEquals(0, $result['exit_status'], 'Wrong exit_status');
     $this->assertEquals(array('Anything'), $result['output'], 'Wrong output');
 }
Пример #5
0
 public function testOnlyExistingClassesCanBeRegistered()
 {
     $this->assertThrows('\\Bart\\DieselException', 'Cannot register instantiator for Braynard because it does not exist', function () {
         Diesel::registerInstantiator('Braynard', '');
     });
 }
Пример #6
0
 private function setupMockCurl($testUrl, $testPort)
 {
     $mockCurl = $this->getMock('\\Bart\\Curl', array(), array($testUrl, $testPort));
     $phpu = $this;
     Diesel::registerInstantiator('\\Bart\\Curl', function ($urlParam, $portParam) use($phpu, $mockCurl, $testUrl, $testPort) {
         $phpu->assertEquals($testUrl, $urlParam, 'url');
         $phpu->assertEquals($testPort, $portParam, 'port');
         return $mockCurl;
     });
     return $mockCurl;
 }