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, ['Set-Cookie' => 'cookie'], ''), ]); $handlerStack = HandlerStack::create($mock); $client = new Client(['handler' => $handlerStack]); $api = new Api($cachePool, $client); // clear cache $api->logout('username'); $api->login('username', 'password'); $api->follow(1234567); } public function testFollowAndUnfollowUser() { $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, ['Set-Cookie' => 'cookie'], file_get_contents(__DIR__ . '/fixtures/home.html')), new Response(200, [], file_get_contents(__DIR__ . '/fixtures/follow.json')), new Response(200, ['Set-Cookie' => 'cookie'], file_get_contents(__DIR__ . '/fixtures/home.html')), new Response(200, [], file_get_contents(__DIR__ . '/fixtures/unfollow.json')), ]); $handlerStack = HandlerStack::create($mock); $client = new Client(['handler' => $handlerStack]); $api = new Api($this->generateCookiesForFollow(), $client); // clear cache $api->login('username', 'password'); $result = $api->follow(1234567); $this->assertSame('ok', $result); $result = $api->unfollow(1234567); $this->assertSame('ok', $result); $api->logout('username'); } public function testFollowUserWithError() { $this->expectException(InstagramFetchException::class); $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, ['Set-Cookie' => 'cookie'], file_get_contents(__DIR__ . '/fixtures/home.html')), new Response(200, []), ]); $handlerStack = HandlerStack::create($mock); $client = new Client(['handler' => $handlerStack]); $api = new Api($this->generateCookiesForFollow(), $client); // clear cache $api->login('username', 'password'); $result = $api->follow(1234567); $this->assertSame('ok', $result); $result = $api->unfollow(1234567); $this->assertSame('ok', $result); $api->logout('username'); } public function testFollowUserWithWrongResultStatus() { $this->expectException(InstagramFetchException::class); $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, ['Set-Cookie' => 'cookie'], file_get_contents(__DIR__ . '/fixtures/home.html')), new Response(200, [], '{"status": ""}'), ]); $handlerStack = HandlerStack::create($mock); $client = new Client(['handler' => $handlerStack]); $api = new Api($this->generateCookiesForFollow(), $client); // clear cache $api->login('username', 'password'); $result = $api->follow(1234567); $this->assertSame('ok', $result); $result = $api->unfollow(1234567); $this->assertSame('ko', $result); $this->assertTrue(true); } }