/**
  * @inheritDoc
  */
 public function preProcessAuthenticate(array $args)
 {
     if (!isset($args[0]) && !is_object($args[0])) {
         return ["FAILURE"];
     }
     $authInfo = $args[0];
     if (isset($authInfo->authid) && isset($authInfo->signature)) {
         // lookup the user
         $query = (new \React\MySQL\Query("SELECT id FROM users WHERE login = ? AND password = ?"))->bindParams($authInfo->authid, $authInfo->signature);
         $deferred = new \React\Promise\Deferred();
         $this->mysqlConnection->query($query->getSql(), function ($command, $conn) use($deferred) {
             if ($command->hasError()) {
                 //test whether the query was executed successfully
                 //error
                 $error = $command->getError();
                 // get the error object, instance of Exception.
                 $this->resolve(['FAILURE']);
             } else {
                 $results = $command->resultRows;
                 //get the results
                 $fields = $command->resultFields;
                 // get table fields
                 if (count($results) > 0) {
                     $deferred->resolve(['SUCCESS']);
                 } else {
                     $deferred->resolve(['FAILURE']);
                 }
             }
         });
         return $deferred->promise();
     }
     return ["FAILURE"];
 }
 public function testConnectWithValidPass()
 {
     $this->expectOutputString('endclose');
     $loop = \React\EventLoop\Factory::create();
     $conn = new Connection($loop, $this->connectOptions);
     $conn->on('end', function ($conn) {
         $this->assertInstanceOf('React\\MySQL\\Connection', $conn);
         echo 'end';
     });
     $conn->on('close', function ($conn) {
         $this->assertInstanceOf('React\\MySQL\\Connection', $conn);
         echo 'close';
     });
     $conn->connect(function ($err, $conn) use($loop) {
         $this->assertEquals(null, $err);
         $this->assertInstanceOf('React\\MySQL\\Connection', $conn);
     });
     $conn->ping(function ($err, $conn) use($loop) {
         $this->assertEquals(null, $err);
         $conn->close(function ($conn) {
             $this->assertEquals($conn::STATE_CLOSED, $conn->getState());
         });
         //$loop->stop();
     });
     $loop->run();
 }