Пример #1
0
 private function createRemoteDestFolder($name)
 {
     $command = new Ssh\Command($this->destSsh);
     $folderPath = $this->getDestPath($name);
     $command->exec("mkdir " . escapeshellarg($folderPath));
     if ($command->failure()) {
         $this->markTestSkipped("Could not create remote dest folder.");
     }
     return $folderPath;
 }
 public function setUp()
 {
     /*
      * Create dest ssh connection
      */
     $destSsh = @ssh2_connect(getenv("SSH_HOST"), getenv("SSH_PORT"), array('hostkey' => 'ssh-rsa'));
     if (!is_resource($destSsh)) {
         $this->markTestSkipped("Couldn't connect to dest.");
     }
     if (!@ssh2_auth_agent($destSsh, getenv("SSH_USER"))) {
         $this->markTestSkipped("Couldn't authenticate dest. You might need to: eval `ssh-agent -s` && ssh-add");
     }
     $this->destSsh = $destSsh;
     /*
      * Create source ssh connection
      */
     $sourceSsh = @ssh2_connect(getenv("SSH_HOST"), getenv("SSH_PORT"), array('hostkey' => 'ssh-rsa'));
     if (!is_resource($sourceSsh)) {
         $this->markTestSkipped("Couldn't connect to source.");
     }
     if (!@ssh2_auth_agent($sourceSsh, getenv("SSH_USER"))) {
         $this->markTestSkipped("Couldn't authenticate source. You might need to: eval `ssh-agent -s` && ssh-add");
     }
     $this->sourceSsh = $sourceSsh;
     /*
      * Set up the local dest database connection
      */
     try {
         $this->destDbh = $destDbh = new \PDO(sprintf("mysql:host=%s;dbname=%s", $this->getMachineParams()['local']['dest']['db']['host'], $this->getMachineParams()['local']['dest']['db']['name']), $this->getMachineParams()['local']['dest']['db']['username'], $this->getMachineParams()['local']['dest']['db']['password']);
     } catch (\Exception $e) {
         $this->markTestSkipped("Couldn't connect to local dest database: {$e}");
         return;
     }
     /*
      * Set up the local source database
      */
     try {
         $this->sourceDbh = $sourceDbh = new \PDO(sprintf("mysql:host=%s;dbname=%s", $this->getMachineParams()['local']['source']['db']['host'], $this->getMachineParams()['local']['source']['db']['name']), $this->getMachineParams()['local']['source']['db']['username'], $this->getMachineParams()['local']['source']['db']['password']);
     } catch (\Exception $e) {
         $this->markTestSkipped("Couldn't connect to local source database: {$e}");
         return;
     }
     $sourceDbh->query("\n            CREATE TABLE wp_deploy_synctest (\n                id  INT UNSIGNED  NOT NULL  AUTO_INCREMENT,\n                name VARCHAR(255) NULL,\n                content TEXT NULL,\n                PRIMARY KEY (id)\n            )\n        ") or $this->markTestSkipped("Couldn't create local source test table.");
     // Insert some database values
     $sourceDbh->query("INSERT INTO wp_deploy_synctest (name, content) VALUES ('test_value_one', 'test_content_one')") or $this->markTestSkipped("Couldn't add data to local source test table.");
     /*
      * Set up remote source database
      */
     $remoteSourceCmd = new Ssh\Command($this->sourceSsh);
     $remoteMysql = CommandUtil::buildMysqlCommand($this->getMachineParams()['remote']['source']['db']);
     $remoteCreateCommand = "{$remoteMysql} -e 'CREATE TABLE wp_deploy_synctest (\n                id  INT UNSIGNED  NOT NULL  AUTO_INCREMENT,\n                name VARCHAR(255) NULL,\n                content TEXT NULL,\n                PRIMARY KEY (id)\n            )'";
     $remoteSourceCmd->exec($remoteCreateCommand);
     if ($remoteSourceCmd->failure()) {
         $this->markTestSkipped("Couldn't create remote source test table.");
     }
     // Insert some database values
     $destInsertCommand = "{$remoteMysql} -e 'INSERT INTO wp_deploy_synctest (name, content) VALUES (\"test_value_one\", \"test_content_one\")'";
     $remoteSourceCmd->exec($destInsertCommand);
     if ($remoteSourceCmd->failure()) {
         $this->markTestSkipped("Couldn't insert data into remote source test table.");
     }
 }
Пример #3
0
 public function testFailure()
 {
     $command = new Command($this->session);
     $command->exec("ls a/path/that/hopefully/doesnt/exist/if/it/does/craziness");
     $this->assertTrue($command->failure());
 }