Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the PropelBundle package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
namespace Propel\PropelBundle\Tests\Fixtures; | ||
|
||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
class UserProxy implements UserInterface | ||
{ | ||
protected $user; | ||
|
||
public function __construct($user) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
{ | ||
$this->user = $user; | ||
} | ||
|
||
public function getRoles() | ||
{ | ||
$roles = $this->getPropelUser()->getRoles(); | ||
} | ||
|
||
public function getPassword() | ||
{ | ||
return $this->getPropelUser()->getPassword(); | ||
} | ||
|
||
public function getSalt() | ||
{ | ||
return $this->getPropelUser()->getSalt(); | ||
} | ||
|
||
public function getUsername() | ||
{ | ||
return $this->getPropelUser()->getUsername(); | ||
} | ||
|
||
public function eraseCredentials() | ||
{ | ||
} | ||
|
||
public function equals(UserInterface $user) | ||
{ | ||
return $this->getPropelUser()->equals($user); | ||
} | ||
|
||
public function getAlgorithm() | ||
{ | ||
return $this->getPropelUser()->getAlgorithm(); | ||
} | ||
|
||
public function __call($method, $arguments) | ||
{ | ||
if (is_callable(array($this->user, $method))) { | ||
return call_user_func_array(array($this->user, $method), $arguments); | ||
} | ||
|
||
throw new \BadMethodCallException('Can\'t call method '.$method); | ||
} | ||
|
||
public function getPropelUser() | ||
{ | ||
return $this->user; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the PropelBundle package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
namespace Propel\PropelBundle\Tests\Security\User; | ||
|
||
use Propel\PropelBundle\Security\User\ModelUserProvider; | ||
|
||
use Propel\PropelBundle\Tests\TestCase; | ||
use Propel\PropelBundle\Tests\Fixtures\UserProxy; | ||
|
||
/** | ||
* @author William Durand <william.durand1@gmail.com> | ||
*/ | ||
class ModelUserProviderTest extends TestCase | ||
{ | ||
protected $con = null; | ||
|
||
public function setUp() | ||
{ | ||
$this->loadPropelQuickBuilder(); | ||
|
||
$schema = <<<SCHEMA | ||
<database name="users" defaultIdMethod="native"> | ||
<table name="user"> | ||
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /> | ||
<column name="username" type="varchar" size="255" primaryString="true" /> | ||
<column name="algorithm" type="varchar" size="50" /> | ||
<column name="salt" type="varchar" size="255" /> | ||
<column name="password" type="varchar" size="255" /> | ||
<column name="expires_at" type="timestamp" /> | ||
<column name="roles" type="array" /> | ||
</table> | ||
</database> | ||
SCHEMA; | ||
|
||
$builder = new \PropelQuickBuilder(); | ||
$builder->setSchema($schema); | ||
$this->con = $builder->build(); | ||
} | ||
|
||
public function testRefreshUserGetsUserByPrimaryKey() | ||
{ | ||
$user1 = new \User(); | ||
$user1->setUsername('user1'); | ||
$user1->save(); | ||
|
||
$user2 = new \User(); | ||
$user2->setUsername('user2'); | ||
$user2->save(); | ||
|
||
$provider = new ModelUserProvider('\User', 'Propel\PropelBundle\Tests\Fixtures\UserProxy', 'username'); | ||
|
||
// try to change the user identity | ||
$user1->setUsername('user2'); | ||
|
||
$resultUser = $provider->refreshUser(new UserProxy($user1)); | ||
$this->assertSame($user1, $resultUser->getPropelUser()); | ||
} | ||
} |
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
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
Should $user be typehinted to an interface? Most of your method calls within the class access this property with getPropelUser(), which then infers existence of getRoles(), getPassword(), getSalt() and getPassword().
I guess they're tests so no big deal since it's a fixture class anyway. Should've kept reading :)