/** * Test add() * * @return void */ public function testAdd() { $response = static::$twistOAuth->post("statuses/update", ["status" => "SaveTweet Test at " . time() . " / " . md5(uniqid(mt_rand(), true))]); $id = $response->id_str; $added = $this->SaveTweet->add($id); $this->assertEquals($id, $added["tweet_id"]); $this->assertEquals($response->user->screen_name, $added["user"]); $this->assertEquals($response->user->id_str, $added["user_id"]); $this->assertEquals($response->text, $added["body"]); }
if (!isset($parse["path"])) { throw new RuntimeException("Path is empty.", 400); } preg_match("#/[a-zA-Z0-9_]{1,15}/status/([0-9]+)#", $parse["path"], $matches); if (!isset($matches[1])) { throw new RuntimeException("Please send in the 'https://twitter.com/{sn}/status/{id}' format.", 400); } $id = $matches[1]; } $conf = config("twitter"); $TwistOAuth = new TwistOAuth($conf["ck"], $conf["cs"], $conf["ot"], $conf["os"]); $SaveTweet = new SaveTweet(config("db"), $TwistOAuth); if ($SaveTweet->isRegistered($id)) { throw new RuntimeException("This ID is already registered.", 400); } $result = $SaveTweet->add($id); $json = ["status" => "OK.", "id" => $result["id"], "user" => $result["user"], "user_id" => $result["user_id"], "tweet_id" => $result["tweet_id"], "body" => $result["body"]]; } catch (PDOException $e) { http_response_code(500); $json = ["error" => ["message" => config("debug") ? $e->getMessage() : "DataBase Error.", "code" => 500]]; } catch (TwistException $e) { http_response_code(500); $json = ["error" => ["message" => config("debug") ? $e->getMessage() : "Twitter API Error.", "code" => 500]]; } catch (RuntimeException $e) { $json = ["error" => ["message" => $e->getMessage(), "code" => $e->getCode() === 0 ? 500 : $e->getCode()]]; if ($e->getCode() !== 0) { http_response_code($e->getCode()); } } catch (Exception $e) { $json = ["error" => ["message" => $e->getMessage(), "code" => $e->getCode() === 0 ? 500 : $e->getCode()]]; if ($e->getCode() !== 0) {