public function testSuccessfulShorten() { $client = new Client(); $content = Stream::factory('{"kind": "urlshortener#url", "id": "http://goo.gl/mR2d", "longUrl": "http://google.com/"}'); $mock = new Mock([new Response(200, [], $content)]); $client->getEmitter()->attach($mock); $url = new \badams\GoogleUrl\GoogleUrl($key = '123', $client); $resource = $url->expand('http://goo.gl/mR2d'); $this->assertInstanceOf('\\badams\\GoogleUrl\\Resources\\Url', $resource); $this->assertEquals('http://goo.gl/mR2d', $resource->id); $this->assertEquals('http://google.com/', $resource->longUrl); }
public function testFullAnalytics() { $client = new Client(); $json = file_get_contents(__DIR__ . '/data/analytics-full.json'); $content = Stream::factory($json); $mock = new Mock([new Response(200, [], $content)]); $client->getEmitter()->attach($mock); $url = new \badams\GoogleUrl\GoogleUrl($key = '123', $client); $resource = $url->expand('http://goo.gl/mR2d', Analytics::FULL); $this->assertInstanceOf('\\badams\\GoogleUrl\\Resources\\Url', $resource); $this->assertEquals('http://goo.gl/mR2d', $resource->id); $this->assertEquals('http://google.com/', $resource->longUrl); $this->assertInstanceOf('\\badams\\GoogleUrl\\Resources\\Analytics', $resource->analytics); $this->assertEquals("929824", $resource->analytics->allTime->shortUrlClicks); $this->assertEquals("34972779", $resource->analytics->allTime->longUrlClicks); $this->assertTrue(is_array($resource->analytics->allTime->referrers)); $this->assertTrue(is_array($resource->analytics->allTime->platforms)); $this->assertTrue(is_array($resource->analytics->allTime->browsers)); $this->assertEquals("953", $resource->analytics->month->shortUrlClicks); $this->assertEquals("1660967", $resource->analytics->month->longUrlClicks); $this->assertTrue(is_array($resource->analytics->allTime->referrers)); $this->assertTrue(is_array($resource->analytics->allTime->platforms)); $this->assertTrue(is_array($resource->analytics->allTime->browsers)); }