Skip to content

Instantly share code, notes, and snippets.

@tystr
Created August 8, 2011 23:56
Show Gist options
  • Save tystr/1133081 to your computer and use it in GitHub Desktop.
Save tystr/1133081 to your computer and use it in GitHub Desktop.
Symfony2 PHPUnit Bootstrap
<?php
// include symfony2 bootstrap
include 'bootstrap.php.cache';
abstract class BaseTestCase extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase
{
protected $client;
public function setUp()
{
$this->client = $this->getAuthenticatedClient('username', 'pass');
}
/**
* Log in without running any tests. Provides an authenticated client for the rest of the tests
* @param $username
* @param $password
* @return Client an authenticated client
*/
private function getAuthenticatedClient($username, $password)
{
$client = $this->createClient();
$crawler = $client->request('POST', 'login');
$form = $crawler->selectButton('submit')->form();
$client->submit($form, array(
'_username' => $username,
'_password' => $password
));
return $client;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment