Jyxo\Beholder\TestCase\Pgsql::run PHP Метод

run() публичный Метод

Performs the test.
public run ( ) : Result
Результат Jyxo\Beholder\Result
    public function run() : \Jyxo\Beholder\Result
    {
        // The pgsql extension is required
        if (!extension_loaded('pgsql')) {
            return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, 'Extension pgsql missing');
        }
        // Status label
        $description = sprintf('%s@%s:%s/%s', $this->user, $this->host, $this->port, $this->database);
        // Connection
        $db = pg_connect(sprintf('host=%s port=%d dbname=%s user=%s password=%s connect_timeout=%d', $this->host, $this->port, $this->database, $this->user, $this->password, $this->timeout));
        if (false === $db) {
            return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Connection error %s', $description));
        }
        // Query (the leading space is because of pgpool)
        $result = pg_query($db, ' ' . $this->query);
        if (false === $result) {
            pg_close($db);
            return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Query error %s', $description));
        }
        pg_free_result($result);
        pg_close($db);
        // OK
        return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, $description);
    }