diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f6c07ad --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: php +php: + - "5.3.4" + +before_install: + - composer self-update + +before_script: + - composer install + +script: + - phpunit --configuration phpunit.xml \ No newline at end of file diff --git a/composer.json b/composer.json index 2032224..ff020a2 100644 --- a/composer.json +++ b/composer.json @@ -1,18 +1,28 @@ { - "name": "j7mbo/twitter-api-php", - "description": "Simple PHP Wrapper for Twitter API v1.1 calls", - "version": "0.1", - "type": "library", - "keywords": ["twitter", "PHP", "API"], - "homepage": "https://github.com/j7mbo/twitter-api-php", - "license": "GNU Public License", - "authors": [ - { - "name": "James Mallison", - "homepage": "https://github.com/j7mbo/twitter-api-php" + "require": { + "ext-curl": "*" + }, + "require-dev": { + "phpunit/phpunit": "4.5.1" + }, + "name": "j7mbo/twitter-api-php", + "description": "Simple PHP Wrapper for Twitter API v1.1 calls", + "version": "1.0.0", + "type": "library", + "keywords": [ + "twitter", + "PHP", + "API" + ], + "homepage": "https://github.com/j7mbo/twitter-api-php", + "license": "GNU Public License", + "authors": [ + { + "name": "James Mallison", + "homepage": "https://github.com/j7mbo/twitter-api-php" + } + ], + "autoload": { + "files": ["TwitterAPIExchange.php"] } - ], - "autoload": { - "files": ["TwitterAPIExchange.php"] - } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..ee5a42b --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,18 @@ + + + + + ./test/ + + + \ No newline at end of file diff --git a/test/TwitterAPIExchangeTest.php b/test/TwitterAPIExchangeTest.php new file mode 100644 index 0000000..1eb2cf1 --- /dev/null +++ b/test/TwitterAPIExchangeTest.php @@ -0,0 +1,273 @@ +getConstants() as $key => $value) + { + $settings[strtolower($key)] = $value; + } + + $this->exchange = new \TwitterAPIExchange($settings); + } + + /** + * GET statuses/mentions_timeline + * + * @see https://dev.twitter.com/rest/reference/get/statuses/mentions_timeline + */ + public function testStatusesMentionsTimeline() + { + $this->markTestSkipped(); + $url = 'https://api.twitter.com/1.1/statuses/mentions_timeline.json'; + $method = 'GET'; + $params = '?max_id=595150043381915648'; + + $data = $this->exchange->request($url, $method, $params); + $expected = "@j7php Test mention"; + + $this->assertContains($expected, $data); + } + + /** + * GET statuses/user_timeline + * + * @see https://dev.twitter.com/rest/reference/get/statuses/user_timeline + */ + public function testStatusesUserTimeline() + { + $this->markTestSkipped(); + $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'; + $method = 'GET'; + $params = '?user_id=3232926711'; + + $data = $this->exchange->request($url, $method, $params); + $expected = "Test Tweet"; + + $this->assertContains($expected, $data); + } + + /** + * GET statuses/home_timeline + * + * @see https://dev.twitter.com/rest/reference/get/statuses/home_timeline + */ + public function testStatusesHomeTimeline() + { + $this->markTestSkipped(); + $url = 'https://api.twitter.com/1.1/statuses/home_timeline.json'; + $method = 'GET'; + $params = '?user_id=3232926711'; + + $data = $this->exchange->request($url, $method, $params); + $expected = "Test Tweet"; + + $this->assertContains($expected, $data); + } + + /** + * GET statuses/retweets_of_me + * + * @see https://dev.twitter.com/rest/reference/get/statuses/retweets_of_me + */ + public function testStatusesRetweetsOfMe() + { + $this->markTestSkipped(); + $url = 'https://api.twitter.com/1.1/statuses/retweets_of_me.json'; + $method = 'GET'; + + $data = $this->exchange->request($url, $method); + $expected = 'travis CI and tests'; + + $this->assertContains($expected, $data); + } + + /** + * GET statuses/retweets/:id + * + * @see https://api.twitter.com/1.1/statuses/retweets/:id.json + */ + public function testStatusesRetweetsOfId() + { + $this->markTestSkipped(); + $url = 'https://api.twitter.com/1.1/statuses/retweets/595155660494471168.json'; + $method = 'GET'; + + $data = $this->exchange->request($url, $method); + $expected = 'travis CI and tests'; + + $this->assertContains($expected, $data); + } + + /** + * GET Statuses/Show/:id + * + * @see https://dev.twitter.com/rest/reference/get/statuses/show/:id + */ + public function testStatusesShowId() + { + $this->markTestSkipped(); + $url = 'https://api.twitter.com/1.1/statuses/show.json'; + $method = 'GET'; + $params = '?id=595155660494471168'; + + $data = $this->exchange->request($url, $method, $params); + $expected = 'travis CI and tests'; + + $this->assertContains($expected, $data); + } + + /** + * POST media/upload + * + * @see https://dev.twitter.com/rest/reference/post/media/upload + * + * @note Uploaded unattached media files will be available for attachment to a tweet for 60 minutes + */ + public function testMediaUpload() + { + /** + *========= + * ========= + * This test is currently failing because media/upload doesn't work yet + * ========= + *========= + */ + $file = file_get_contents(__DIR__ . '/img.png'); + $data = base64_encode($file); + + $url = 'https://upload.twitter.com/1.1/media/upload.json'; + $method = 'POST'; + $params = [ + 'media_data' => $data + ]; + + $data = $this->exchange->request($url, $method, $params); + $expected = 'image/png'; + + $this->assertContains($expected, $data); + + /** Store the media id for later **/ + $data = @json_decode($data, true); + + $this->assertArrayHasKey('media_id', is_array($data) ? $data : []); + + self::$mediaId = $data['media_id']; + + var_dump(self::$mediaId); + } + + /** + * POST statuses/update + * + * @see https://dev.twitter.com/rest/reference/post/statuses/update + */ + public function testStatusesUpdate() + { + $this->markTestSkipped(); + if (!self::$mediaId) + { + $this->fail('Cannot /update status because /upload failed'); + } + + $url = 'https://api.twitter.com/1.1/statuses/update.json'; + $method = 'POST'; + $params = [ + 'status' => 'TEST TWEET TO BE DELETED' . rand() + ]; + + $data = $this->exchange->request($url, $method, $params); + $expected = 'TEST TWEET TO BE DELETED'; + + $this->assertContains($expected, $data); + + /** Store the tweet id for testStatusesDestroy() **/ + $data = @json_decode($data, true); + + $this->assertArrayHasKey('id_str', is_array($data) ? $data : []); + + self::$tweetId = $data['id_str']; + + /** We've done this now, yay **/ + self::$mediaId = null; + } + + /** + * POST statuses/destroy/:id + * + * @see https://dev.twitter.com/rest/reference/post/statuses/destroy/%3Aid + */ + public function testStatusesDestroy() + { + $this->markTestSkipped(); + if (!self::$tweetId) + { + $this->fail('Cannot /destroy status because /update failed'); + } + + $url = sprintf('https://api.twitter.com/1.1/statuses/destroy/%d.json', self::$tweetId); + $method = 'POST'; + $params = [ + 'id' => self::$tweetId + ]; + + $data = $this->exchange->request($url, $method, $params); + $expected = 'TEST TWEET TO BE DELETED'; + + $this->assertContains($expected, $data); + + /** We've done this now, yay **/ + self::$tweetId = null; + } +} \ No newline at end of file diff --git a/test/img.png b/test/img.png new file mode 100644 index 0000000..85f8ce3 Binary files /dev/null and b/test/img.png differ