'cookie'], file_get_contents(__DIR__ . '/fixtures/home.html')), new Response(200, [], file_get_contents(__DIR__ . '/fixtures/login-success.json')), new Response(200, [], file_get_contents(__DIR__ . '/fixtures/live.json')), ]); $handlerStack = HandlerStack::create($mock); $client = new Client(['handler' => $handlerStack]); $api = new Api($cachePool, $client); // clear cache $api->logout('username'); $api->login('username', 'password'); $live = $api->getLive('pgrimaud'); $this->assertInstanceOf(\StdClass::class, $live->getBroadcastDict()); $this->assertSame(17911201561913683, $live->getBroadcastId()); $arrayResult = $live->toArray(); $this->assertCount(2, $arrayResult); $this->assertCount(2, $live->__serialize()); $api->logout('username'); } public function testGetLiveWithError() { $this->expectException(InstagramFetchException::class); $cachePool = new FilesystemAdapter('Instagram', 0, __DIR__ . '/cache'); $mock = new MockHandler([ new Response(200, ['Set-Cookie' => 'cookie'], file_get_contents(__DIR__ . '/fixtures/home.html')), new Response(200, [], file_get_contents(__DIR__ . '/fixtures/login-success.json')), new Response(404, []), ]); $handlerStack = HandlerStack::create($mock); $client = new Client(['handler' => $handlerStack]); $api = new Api($cachePool, $client); // clear cache $api->logout('username'); $api->login('username', 'password'); $api->getLive('thisuserdoesnotexist'); } public function testGetLiveWithInvalidJson() { $this->expectException(InstagramFetchException::class); $cachePool = new FilesystemAdapter('Instagram', 0, __DIR__ . '/cache'); $mock = new MockHandler([ new Response(200, ['Set-Cookie' => 'cookie'], file_get_contents(__DIR__ . '/fixtures/home.html')), new Response(200, [], file_get_contents(__DIR__ . '/fixtures/login-success.json')), new Response(200, [], ''), ]); $handlerStack = HandlerStack::create($mock); $client = new Client(['handler' => $handlerStack]); $api = new Api($cachePool, $client); // clear cache $api->logout('username'); $api->login('username', 'password'); $api->getLive('thisuserdoesnotexist'); } }