OOP Wrapper for Facebook Test Users API

If you have a tight Facebook integration in your project and it's time for tests, there's a useful test users API with a simple GUI as well as a programmatic access.

Since I worked on automatic testing with behat BDD framework, I've created a simple oop wrapper with Guzzle for their json API. It's easy to install and configure, just use composer

$ php composer.phar require --dev rinatio/Facebook:~0.1

then configure namespaces, set your Facebook application credentials

use rinatio\Facebook\Test\User as TestUser;
use rinatio\Facebook\Facebook;

Facebook::setAppId('fbAppId');
Facebook::setAppSecret('fbAppSecret');

and you're ready to go:

// create a user
$user = TestUser::create(array(
    'name' => 'Jack Black'
));
echo $user->access_token;
echo $user->login_url;

// add a friend
$friend = TestUser::create(array(
    'name' => 'John White'
));
$user->addFriend($friend);

// Get full user profile
$user->fetchProfile();
echo $user->username;
echo $user->gender;

// Get all test users created in your app
$users = TestUser::all();

// Delete a user
$user->delete();

// Or delete all of them
TestUser::deleteAll();
comments powered by Disqus
Made with in SPb