Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing facebook login with FOSFacebookBundle (functional test)
# ...
fos_facebook:
class:
api: Acme\DemoBundle\Test\FacebookSessionPersistenceStub
security:
firewalls:
frontend:
fos_facebook:
require_previous_session: false
<?php
namespace Acme\DemoBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DefaultControllerTest extends WebTestCase
{
public function testLoginOK()
{
$client = static::createClient();
$crawler = $client->request('GET', '/');
$this->assertTrue($client->getResponse()->isSuccessful());
$crawler = $client->request('POST', '/loginfb_check');
$crawler = $client->followRedirect();
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertCount(1, $crawler->filter('strong:contains("Mallo")'));
}
}
<?php
namespace Acme\DemoBundle\Test;
use Symfony\Component\HttpFoundation\Session\Session;
/**
* Stub of FOS\FacebookBundle\Facebook\FacebookSessionPersistence
*
* @codeCoverageIgnore
* @SuppressWarnings('unused')
*/
class FacebookSessionPersistenceStub extends \BaseFacebook
{
public function __construct($config, Session $session, $prefix = '')
{
}
public function getLoginUrl($params = array())
{
return '';
}
public function api()
{
return array(
'id' => 123456,
'first_name' => 'Mallo',
'last_name' => 'Di Noce',
'email' => 'utente_fb@example.org',
);
}
protected function clearAllPersistentData()
{
}
protected function clearPersistentData($key)
{
}
protected function setPersistentData($key, $value)
{
}
protected function getPersistentData($key, $default = false)
{
if ($key == 'user_id') {
return 123456;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment