Created
November 8, 2009 03:01
-
-
Save sousk/229067 to your computer and use it in GitHub Desktop.
php doctest helper: getting an authenticated user instance
This file contains hidden or 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
/** | |
* #test test_user | |
* <code> | |
* #diag('expect error'); | |
* try { | |
* $u = test_user('peko'); | |
* #fail('should raise error'); | |
* } | |
* catch(Exception $e) { | |
* #ok($e,$e->getMessage()); | |
* } | |
* #diag("exipect ok"); | |
* #ok($u = test_user(), "ok"); | |
* #isa_ok($u, 'myUser', 'myUser'); | |
* #is($u->getUserId(), 1); | |
* #is($u->getUsername(), 'john'); | |
* </code> | |
*/ | |
function test_user($username='john', $pwd='hoge') | |
{ | |
$error = ""; $con = sfContext::getInstance(); | |
$con->getRequest()->setParameter('password', $pwd); | |
$validator = new sfGuardUserValidator; | |
$validator->initialize($con); | |
$validator->execute($username, $error); | |
$u = $con->getUser(); | |
if (strlen($error) > 0) { | |
throw new sfException('failed to authenticate, test user has missed: '. $error); | |
} | |
return $u; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment