Commit 979e7924 authored by Fabien Potencier's avatar Fabien Potencier

minor #1093 Improve code coverage of SecurityTrait (SofHad)

This PR was merged into the 1.2 branch.

Discussion
----------

Improve code coverage of SecurityTrait

Additional tests to cover:
- Empty token: https://github.com/silexphp/Silex/blob/1.2/src/Silex/Application/SecurityTrait.php#L33-35
- Invalid user: https://github.com/silexphp/Silex/blob/1.2/src/Silex/Application/SecurityTrait.php#L37-39

Commits
-------

95023886 Add tests
parents a6ff46de 95023886
...@@ -40,6 +40,50 @@ class SecurityTraitTest extends \PHPUnit_Framework_TestCase ...@@ -40,6 +40,50 @@ class SecurityTraitTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('fabien', $app->user()->getUsername()); $this->assertEquals('fabien', $app->user()->getUsername());
} }
public function testUserWithNoToken()
{
$request = Request::create('/');
$app = new SecurityApplication();
$app['security'] = $this->getMockBuilder('Symfony\Component\Security\Core\SecurityContext')
->disableOriginalConstructor()
->getMock();
$app['security']->expects($this->any())
->method('getToken')
->will($this->returnValue(null));
$app->get('/', function () { return 'foo'; });
$app->handle($request);
$this->assertNull($app->user());
}
public function testUserWithInvalidUser()
{
$request = Request::create('/');
$app = new SecurityApplication();
$app['security'] = $this->getMockBuilder('Symfony\Component\Security\Core\SecurityContext')
->disableOriginalConstructor()
->getMock();
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken')
->disableOriginalConstructor()
->getMock();
$token->expects($this->once())
->method('getUser')
->will($this->returnValue(array()));
$app['security']->expects($this->any())
->method('getToken')
->will($this->returnValue($token));
$app->get('/', function () { return 'foo'; });
$app->handle($request);
$this->assertNull($app->user());
}
public function testEncodePassword() public function testEncodePassword()
{ {
$app = $this->createApplication(); $app = $this->createApplication();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment