8000 merged branch drak/frameworkbundle_moretests (PR #2904) · symfony/symfony@8579c63 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8579c63

Browse files
committed
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)
2 parents af9ddc0 + 9b8cdab commit 8579c63

File tree

4 files changed

+79
-10
lines changed

4 files changed

+79
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SessionTest.php

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
class SessionTest extends WebTestCase
1818
{
1919
/**
20+
* Tests session attributes persist.
21+
*
2022
* @dataProvider getConfigs
2123
*/
22-
public function testWelcome($config)
24+
public function testWelcome($config, $insulate)
2325
{
2426
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
25-
$client->insulate();
27+
if ($insulate) {
28+
$client->insulate();
29+
}
2630

2731
// no session
2832
$crawler = $client->request('GET', '/session');
@@ -46,12 +50,16 @@ public function testWelcome($config)
4650
}
4751

4852
/**
53+
* Tests flash messages work in practice.
54+
*
4955
* @dataProvider getConfigs
5056
*/
51-
public function testFlash($config)
57+
public function testFlash($config, $insulate)
5258
{
5359
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
54-
$client->insulate();
60+
if ($insulate) {
61+
$client->insulate();
62+
}
5563

5664
// set flash
5765
$crawler = $client->request('GET', '/session_setflash/Hello%20world.');
@@ -64,10 +72,69 @@ public function testFlash($config)
6472
$this->assertContains('No flash was set.', $crawler->text());
6573
}
6674

75+
/**
76+
* See if two separate insulated clients can run without
77+
* polluting eachother's session data.
78+
*
79+
* @dataProvider getConfigs
80+
*/
81+
public function testTwoClients($config, $insulate)
82+
{
83+
// start first client
84+
$client1 = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
85+
if ($insulate) {
86+
$client1->insulate();
87+
}
88+
89+
// start second client
90+
$client2 = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
91+
if ($insulate) {
92+
$client2->insulate();
93+
}
94+
95+
// new session, so no name set.
96+
$crawler1 = $client1->request('GET', '/session');
97+
$this->assertContains('You are new here and gave no name.', $crawler1->text());
98+
99+
// set name of client1
100+
$crawler1 = $client1->request('GET', '/session/client1');
101+
$this->assertContains('Hello client1, nice to meet you.', $crawler1->text());
102+
103+
// no session for client2
104+
$crawler2 = $client2->request('GET', '/session');
105+
$this->assertContains('You are new here and gave no name.', $crawler2->text());
106+
107+
// remember name client2
108+
$crawler2 = $client2->request('GET', '/session/client2');
109+
$this->assertContains('Hello client2, nice to meet you.', $crawler2->text());
110+
111+
// prove remembered name of client1
112+
$crawler1 = $client1->request('GET', '/session');
113+
$this->assertContains('Welcome back client1, nice to meet you.', $crawler1->text());
114+
115+
// prove remembered name of client2
116+
$crawler2 = $client2->request('GET', '/session');
117+
$this->assertContains('Welcome back client2, nice to meet you.', $crawler2->text());
118+
119+
// clear client1
120+
$crawler1 = $client1->request('GET', '/session_logout');
121+
$this->assertContains('Session cleared.', $crawler1->text());
122+
123+
// prove client1 data is cleared
124+
$crawler1 = $client1->request('GET', '/session');
125+
$this->assertContains('You are new here and gave no name.', $crawler1->text());
126+
127+
// prove remembered name of client2 remains untouched.
128+
$crawler2 = $client2->request('GET', '/session');
129+
$this->assertContains('Welcome back client2, nice to meet you.', $crawler2->text());
130+
}
131+
67132
public function getConfigs()
68133
{
69134
return array(
70-
array('config.yml'),
135+
// configfile, insulate
136+
array('config.yml', true),
137+
array('config.yml', false),
71138
);
72139
}
73140

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/WebTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class WebTestCase extends BaseWebTestCase
1818
{
1919
static public function assertRedirect($response, $location)
2020
{
21-
self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: '.substr($response, 0, 2000));
21+
self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: '.$response->getStatusCode());
2222
self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
2323
}
2424

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AppKernel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
while ($dir !== $lastDir) {
1818
$lastDir = $dir;
1919

20-
if (is_file($dir.'/autoload.php')) {
20+
if (file_exists($dir.'/autoload.php')) {
2121
require_once $dir.'/autoload.php';
2222
break;
2323
}
2424

25-
if (is_file($dir.'/autoload.php.dist')) {
25+
if (file_exists($dir.'/autoload.php.dist')) {
2626
require_once $dir.'/autoload.php.dist';
2727
break;
2828
}
@@ -52,7 +52,7 @@ public function __construct($testCase, $rootConfig, $environment, $debug)
5252
$this->testCase = $testCase;
5353

5454
$fs = new Filesystem();
55-
if (!$fs->isAbsolutePath($rootConfig) && !is_file($rootConfig = __DIR__.'/'.$testCase.'/'.$rootConfig)) {
55+
if (!$fs->isAbsolutePath($rootConfig) && !file_exists($rootConfig = __DIR__.'/'.$testCase.'/'.$rootConfig)) {
5656
throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $rootConfig));
5757
}
5858
$this->rootConfig = $rootConfig;
@@ -62,7 +62,7 @@ public function __construct($testCase, $rootConfig, $environment, $debug)
6262

6363
public function registerBundles()
6464
{
65-
if (!is_file($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
65+
if (!file_exists($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
6666
throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
6767
}
6868

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/config/framework.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ framework:
88
form: ~
99
test: ~
1010
session:
11+
default_locale: en
1112
auto_start: true
1213
storage_id: session.storage.filesystem
14+
1315
services:
1416
logger: { class: Symfony\Component\HttpKernel\Log\NullLogger }

0 commit comments

Comments
 (0)
0