Created
August 8, 2011 23:56
-
-
Save tystr/1133081 to your computer and use it in GitHub Desktop.
Symfony2 PHPUnit Bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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