merged branch drak/frameworkbundle_moretests (PR #2904)

Commits
-------

9b8cdab [FrameworkBundle] Prove client insulation and non-insulation works in session tests.
ce66548 [FrameworkBundle] Add tests to prove functional testing works with simultaneous clients.
ff0412a [FrameworkBundle] Small changes to test setup.

Discussion
----------

[FrameworkBundle] Added functional tests to prove multiple clients and client insulation.

Bug fix: no
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
References: #2898
Todo: -

@fabpot: I don't know what happened with the previous PR #2989 - seemed like some weird corruption as the tests passed locally and on travis except until after I fetched from the repo.  I suspect something was corrupted.  I asked @Seldaek to confirm the tests pass on his local setup before I submitted this PR.  I only got rid of the errors locally after recloning the repo!

http://travis-ci.org/#!/drak/symfony/builds/413515

[![Build Status](https://secure.travis-ci.org/drak/symfony.png)](http://travis-ci.org/drak/symfony?branch=frameworkbundle_moretests)
This commit is contained in:
Fabien Potencier 2011-12-16 18:27:38 +01:00
commit 8579c6314b
4 changed files with 79 additions and 10 deletions

View File

@ -17,12 +17,16 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
class SessionTest extends WebTestCase
{
/**
* Tests session attributes persist.
*
* @dataProvider getConfigs
*/
public function testWelcome($config)
public function testWelcome($config, $insulate)
{
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
$client->insulate();
if ($insulate) {
$client->insulate();
}
// no session
$crawler = $client->request('GET', '/session');
@ -46,12 +50,16 @@ class SessionTest extends WebTestCase
}
/**
* Tests flash messages work in practice.
*
* @dataProvider getConfigs
*/
public function testFlash($config)
public function testFlash($config, $insulate)
{
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
$client->insulate();
if ($insulate) {
$client->insulate();
}
// set flash
$crawler = $client->request('GET', '/session_setflash/Hello%20world.');
@ -64,10 +72,69 @@ class SessionTest extends WebTestCase
$this->assertContains('No flash was set.', $crawler->text());
}
/**
* See if two separate insulated clients can run without
* polluting eachother's session data.
*
* @dataProvider getConfigs
*/
public function testTwoClients($config, $insulate)
{
// start first client
$client1 = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
if ($insulate) {
$client1->insulate();
}
// start second client
$client2 = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
if ($insulate) {
$client2->insulate();
}
// new session, so no name set.
$crawler1 = $client1->request('GET', '/session');
$this->assertContains('You are new here and gave no name.', $crawler1->text());
// set name of client1
$crawler1 = $client1->request('GET', '/session/client1');
$this->assertContains('Hello client1, nice to meet you.', $crawler1->text());
// no session for client2
$crawler2 = $client2->request('GET', '/session');
$this->assertContains('You are new here and gave no name.', $crawler2->text());
// remember name client2
$crawler2 = $client2->request('GET', '/session/client2');
$this->assertContains('Hello client2, nice to meet you.', $crawler2->text());
// prove remembered name of client1
$crawler1 = $client1->request('GET', '/session');
$this->assertContains('Welcome back client1, nice to meet you.', $crawler1->text());
// prove remembered name of client2
$crawler2 = $client2->request('GET', '/session');
$this->assertContains('Welcome back client2, nice to meet you.', $crawler2->text());
// clear client1
$crawler1 = $client1->request('GET', '/session_logout');
$this->assertContains('Session cleared.', $crawler1->text());
// prove client1 data is cleared
$crawler1 = $client1->request('GET', '/session');
$this->assertContains('You are new here and gave no name.', $crawler1->text());
// prove remembered name of client2 remains untouched.
$crawler2 = $client2->request('GET', '/session');
$this->assertContains('Welcome back client2, nice to meet you.', $crawler2->text());
}
public function getConfigs()
{
return array(
array('config.yml'),
// configfile, insulate
array('config.yml', true),
array('config.yml', false),
);
}

View File

@ -18,7 +18,7 @@ class WebTestCase extends BaseWebTestCase
{
static public function assertRedirect($response, $location)
{
self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: '.substr($response, 0, 2000));
self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: '.$response->getStatusCode());
self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
}

View File

@ -17,12 +17,12 @@ $lastDir = null;
while ($dir !== $lastDir) {
$lastDir = $dir;
if (is_file($dir.'/autoload.php')) {
if (file_exists($dir.'/autoload.php')) {
require_once $dir.'/autoload.php';
break;
}
if (is_file($dir.'/autoload.php.dist')) {
if (file_exists($dir.'/autoload.php.dist')) {
require_once $dir.'/autoload.php.dist';
break;
}
@ -52,7 +52,7 @@ class AppKernel extends Kernel
$this->testCase = $testCase;
$fs = new Filesystem();
if (!$fs->isAbsolutePath($rootConfig) && !is_file($rootConfig = __DIR__.'/'.$testCase.'/'.$rootConfig)) {
if (!$fs->isAbsolutePath($rootConfig) && !file_exists($rootConfig = __DIR__.'/'.$testCase.'/'.$rootConfig)) {
throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $rootConfig));
}
$this->rootConfig = $rootConfig;
@ -62,7 +62,7 @@ class AppKernel extends Kernel
public function registerBundles()
{
if (!is_file($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
if (!file_exists($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
}

View File

@ -8,7 +8,9 @@ framework:
form: ~
test: ~
session:
default_locale: en
auto_start: true
storage_id: session.storage.filesystem
services:
logger: { class: Symfony\Component\HttpKernel\Log\NullLogger }