/** * Tweet by optionally uploading media and updating status. * * @param Tweet $tweet */ public function tweet(Tweet $tweet) { if ($tweet->getMedia() instanceof StreamInterface) { $tweet = $this->mediaUploader->upload($tweet); } $this->statusUpdater->update($tweet); }
/** * Test a Tweet with media. */ public function testTweeterWithMedia() { $stream = $this->getMock('Psr\\Http\\Message\\StreamInterface'); $tweet = $this->getMock('JimLind\\Pie7o\\Tweet'); $tweet->method('getMedia')->willReturn($stream); $taggedTweet = $this->getMock('JimLind\\Pie7o\\Tweet'); $this->mediaUploader->expects($this->once())->method('upload')->with($tweet)->willReturn($taggedTweet); $this->statusUpdater->expects($this->once())->method('update')->with($taggedTweet); $this->fixture->tweet($tweet); }
/** * Test GuzzleClient with good response. */ public function testGuzzleClientResponseGood() { $mediaId = rand(); $expected = rand(); $response = $this->getMock('GuzzleHttp\\Psr7\\Response'); $response->method('getStatusCode')->willReturn(200); $response->method('getBody')->willReturn('{"media_id":' . $mediaId . '}'); $this->guzzleClient->method('send')->willReturn($response); $stream = $this->getMock('Psr\\Http\\Message\\StreamInterface'); $tweet = $this->getMock('JimLind\\Pie7o\\Tweet'); $tweet->method('getMedia')->willReturn($stream); $tweet->expects($this->once())->method('withMediaId')->with($mediaId)->willReturn($expected); $actual = $this->fixture->upload($tweet); $this->assertEquals($expected, $actual); }