Jyxo\Beholder\TestCase\Smtp::run PHP Method

run() public method

Performs the test.
public run ( ) : Result
return Jyxo\Beholder\Result
    public function run() : \Jyxo\Beholder\Result
    {
        // The \Jyxo\Mail\Sender\Smtp class is required
        if (!class_exists(\Jyxo\Mail\Sender\Smtp::class)) {
            return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::NOT_APPLICABLE, sprintf('Class %s missing', \Jyxo\Mail\Sender\Smtp::class));
        }
        try {
            $header = 'From: ' . $this->from . "\n";
            $header .= 'To: ' . $this->to . "\n";
            $header .= 'Subject: Beholder' . "\n";
            $header .= 'Date: ' . date(DATE_RFC822) . "\n";
            $smtp = new \Jyxo\Mail\Sender\Smtp($this->host, 25, $this->host, $this->timeout);
            $smtp->connect()->from($this->from)->recipient($this->to)->data($header, 'Beholder SMTP Test')->disconnect();
        } catch (\Exception $e) {
            $smtp->disconnect();
            return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::FAILURE, sprintf('Send error %s', $this->host));
        }
        // OK
        return new \Jyxo\Beholder\Result(\Jyxo\Beholder\Result::SUCCESS, $this->host);
    }