Commit c24b35a5 authored by Igor Wiedler's avatar Igor Wiedler

[SessionExtension] initial test case

parent c642d13b
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Silex\Tests;
use Silex\Application;
use Silex\Extension\SessionExtension;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage;
/**
* SessionExtension test cases.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class SessionExtensionTest extends \PHPUnit_Framework_TestCase
{
public function testRegister()
{
$app = new Application();
$app->register(new SessionExtension());
$app['session.storage'] = $app->share(function() use ($app) {
return new ArraySessionStorage();
});
$app->get('/login', function() use ($app) {
$app['session']->set('logged_in', true);
return 'Logged in successfully.';
});
$app->get('/account', function() use ($app) {
if (!$app['session']->get('logged_in')) {
return 'You are not in.';
}
return 'This is your account.';
});
$request = Request::create('/login');
$response = $app->handle($request);
$this->assertEquals('Logged in successfully.', $response->getContent());
$request = Request::create('/account');
$response = $app->handle($request);
$this->assertEquals('This is your account.', $response->getContent());
}
}
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