public function testReply() { $pool = new Pool(); $twitter = new Twitter($this->configTwitter, $pool); $text = __METHOD__ . ' ' . microtime(true) . ' ' . php_uname(); $ret = $twitter->reply($text)->text(); $this->assertEquals(trim(substr($text, 0, 140)), $ret); }
public function testTwitterPost() { $pool = new Pool(); $configYahooWeather = array('url' => 'http://weather.yahooapis.com/forecastrss', 'degree' => Weather::DEGREE_CELSIUS); $configTwitter = array('strict' => false, 'format' => 'json', 'oauth' => array('consumer_key' => 'zw9T8W42BBQFwRvJXMw', 'consumer_secret' => 'qe3IiWO4KWLK41Em559NMDuvDafv1kXwvbq0lUJQWAA', 'access_token' => '582166477-sQNHyG7vkNX80GF0TptiN7Ui53nrUcM618XCxANc', 'access_token_secret' => 'oqkSS8VPp3QKxGA4KOQi6lCwRIHhlfkC6xaB6I3jA', 'signature_method' => 'HMAC-SHA1', 'version' => '1.0')); $yahooWeather = new Weather($configYahooWeather, $pool); $weatherY = $yahooWeather->getByCode(Weather::CODE_MUNICH); $current = $weatherY->current(); $today = $weatherY->forecast(0); $tomorrow = $weatherY->forecast(1); $text = 'Jetzt: ' . $current['temp'] . '°C ' . $current['text'] . " (" . $weatherY->atmosphere('humidity') . '% Lf.)' . "\n" . 'Heute: ' . $today['low'] . ' bis ' . $today['high'] . '°C ' . $today['text'] . '' . "\n" . 'Morgen: ' . $tomorrow['low'] . ' bis ' . $tomorrow['high'] . '°C ' . $tomorrow['text'] . ' ' . "\n" . '#münchen #wetter'; sleep(1); $twitter = new Twitter($configTwitter, $pool); $timeline = $twitter->timelineUser(array('count' => 1, 'exclude_replies' => true)); if (!$timeline->isEmpty() && $timeline->first()->timestamp() > time() - 3600) { #die('Aktuelles Wetter vor weniger als einer Stunde gepostet!'); } $text = microtime(true) . ' ' . $text; while (mb_strlen($text) > 140) { $text = preg_replace('/\\s+\\S+$/u', '', $text); } $twitter->reply($text)->text(); $this->assertEquals($text, $text); }