Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde28661

Browse files
committed
introduced legacy tests and style fixes
work
1 parenta6a83b7 commitde28661

File tree

3 files changed

+164
-38
lines changed

3 files changed

+164
-38
lines changed

‎src/Symfony/Component/HttpFoundation/CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CHANGELOG
88
disabling`Range` and`Content-Length` handling, switching to chunked encoding instead
99
* added the`Cookie::fromString()` method that allows to create a cookie from a
1010
raw header string
11-
* PdoSessionHandler: Deprecated thethe`lifetime` column
11+
* PdoSessionHandler: Deprecated the`lifetime` column
1212

1313
3.1.0
1414
-----

‎src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ public function __construct($pdoOrDsn = null, array $options = array())
196196
$this->connectionOptions =isset($options['db_connection_options']) ?$options['db_connection_options'] :$this->connectionOptions;
197197
$this->lockMode =isset($options['lock_mode']) ?$options['lock_mode'] :$this->lockMode;
198198

199-
if ($this->lifetimeCol !==false) {
200-
@trigger_error('Using the "db_lifetime_col" option is deprecated since version 3.3as it willberemovedin 4.0.',E_USER_DEPRECATED);
199+
if (false !==$this->lifetimeCol) {
200+
@trigger_error(sprintf('The "%s" column is deprecated since version 3.3and won\'tbeused anymorein 4.0. Migrate your session database then set the "db_lifetime_col" option to false to opt-in for the new behavior.',$this->lifetimeCol),E_USER_DEPRECATED);
201201
}
202202
}
203203

@@ -217,7 +217,7 @@ public function createTable()
217217
// connect if we are not yet
218218
$this->getConnection();
219219

220-
if ($this->lifetimeCol ===false) {
220+
if (false ===$this->lifetimeCol) {
221221
switch ($this->driver) {
222222
case'mysql':
223223
// We use varbinary for the ID column because it prevents unwanted conversions:
@@ -228,7 +228,7 @@ public function createTable()
228228
$sql ="CREATE TABLE$this->table ($this->idCol VARBINARY(128) NOT NULL PRIMARY KEY,$this->dataCol BLOB NOT NULL,$this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8_bin, ENGINE = InnoDB";
229229
break;
230230
case'sqlite':
231-
$sql ="CREATE TABLE$this->table ($this->idCol TEXT NOT NULL PRIMARY KEY,$this->dataCol BLOB NOT NULL,$this->timeCol INTEGER NOT NULL)";
231+
$sql ="BEGIN;CREATE TABLE$this->table ($this->idCol TEXT NOT NULL PRIMARY KEY,$this->dataCol BLOB NOT NULL,$this->timeCol INTEGER NOT NULL); CREATE INDEX{$this->table}_{$this->timeCol}_idx ON$this->table ($this->timeCol); COMMIT;";
232232
break;
233233
case'pgsql':
234234
$sql ="CREATE TABLE$this->table ($this->idCol VARCHAR(128) NOT NULL PRIMARY KEY,$this->dataCol BYTEA NOT NULL,$this->timeCol INTEGER NOT NULL)";
@@ -245,11 +245,6 @@ public function createTable()
245245
}else {
246246
switch ($this->driver) {
247247
case'mysql':
248-
// We use varbinary for the ID column because it prevents unwanted conversions:
249-
// - character set conversions between server and client
250-
// - trailing space removal
251-
// - case-insensitivity
252-
// - language processing like é == e
253248
$sql ="CREATE TABLE$this->table ($this->idCol VARBINARY(128) NOT NULL PRIMARY KEY,$this->dataCol BLOB NOT NULL,$this->lifetimeCol MEDIUMINT NOT NULL,$this->timeCol INTEGER UNSIGNED NOT NULL) COLLATE utf8_bin, ENGINE = InnoDB";
254249
break;
255250
case'sqlite':
@@ -426,6 +421,7 @@ public function close()
426421
$this->gcCalled =false;
427422

428423
// delete the session records that have expired
424+
// $sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol < :time";
429425
$sql ="DELETE FROM$this->table WHERE$this->timeCol < :time";
430426

431427
$stmt =$this->pdo->prepare($sql);
@@ -699,7 +695,7 @@ private function getMergeStatement($sessionId, $data, $maxlifetime)
699695
{
700696
$mergeSql =null;
701697

702-
if ($this->lifetimeCol ===false) {
698+
if (false ===$this->lifetimeCol) {
703699
switch (true) {
704700
case'mysql' ===$this->driver:
705701
$mergeSql ="INSERT INTO$this->table ($this->idCol,$this->dataCol,$this->timeCol) VALUES (:id, :data, :time)".

‎src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php‎

Lines changed: 157 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,60 @@ protected function getPersistentSqliteDsn()
3737
return'sqlite:'.$this->dbFile;
3838
}
3939

40-
protectedfunctiongetMemorySqlitePdo()
40+
protectedfunctiongetPdoMemorySqlite(array$attributes =array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION))
4141
{
4242
$pdo =new \PDO('sqlite::memory:');
43-
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
44-
$storage =newPdoSessionHandler($pdo,array('db_lifetime_col' =>false));
45-
$storage->createTable();
43+
44+
foreach ($attributesas$i =>$v) {
45+
$pdo->setAttribute($i,$v);
46+
}
4647

4748
return$pdo;
4849
}
4950

51+
privatefunctiongetSessionHandler($pdoOrDsn =null,array$options =array('db_lifetime_col' =>false),$createTable =true)
52+
{
53+
if (null ===$pdoOrDsn) {
54+
$pdoOrDsn =$this->getPdoMemorySqlite();
55+
}
56+
57+
$storage =newPdoSessionHandler($pdoOrDsn,$options);
58+
59+
if (true ===$createTable) {
60+
$storage->createTable();
61+
}
62+
63+
return$storage;
64+
}
65+
5066
/**
5167
* @expectedException \InvalidArgumentException
5268
*/
5369
publicfunctiontestWrongPdoErrMode()
5470
{
55-
$pdo =$this->getMemorySqlitePdo();
56-
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT);
71+
$this->getSessionHandler($this->getPdoMemorySqlite(array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_SILENT)));
72+
}
5773

58-
$storage =newPdoSessionHandler($pdo,array('db_lifetime_col' =>false));
74+
/**
75+
* @expectedException \RuntimeException
76+
*/
77+
publicfunctiontestNonexistentTable()
78+
{
79+
$this->doTestNonexistentTable($this->getSessionHandler(null,array('db_lifetime_col' =>false,'db_table' =>'nonexistent_table'),false));
5980
}
6081

6182
/**
83+
* @group legacy
84+
* @expectedDeprecation The "%s" column is deprecated since version 3.3 and won't be used anymore in 4.0. Migrate your session database then set the "db_lifetime_col" option to false to opt-in for the new behavior.
6285
* @expectedException \RuntimeException
6386
*/
64-
publicfunctiontestInexistentTable()
87+
publicfunctiontestLegacyNonexistentTable()
88+
{
89+
$this->doTestNonexistentTable($this->getSessionHandler(null,array('db_lifetime_col' =>'foobar','db_table' =>'nonexistent_table'),false));
90+
}
91+
92+
privatefunctiondoTestNonexistentTable(PdoSessionHandler$storage)
6593
{
66-
$storage =newPdoSessionHandler($this->getMemorySqlitePdo(),array('db_table' =>'inexistent_table','db_lifetime_col' =>false));
6794
$storage->open('','sid');
6895
$storage->read('id');
6996
$storage->write('id','data');
@@ -75,16 +102,23 @@ public function testInexistentTable()
75102
*/
76103
publicfunctiontestCreateTableTwice()
77104
{
78-
$storage =newPdoSessionHandler($this->getMemorySqlitePdo(),array('db_lifetime_col' =>false));
105+
$storage =$this->getSessionHandler();
79106
$storage->createTable();
80107
}
81108

82-
publicfunctiontestWithLazyDsnConnection()
109+
/**
110+
* @group legacy
111+
* @expectedException \RuntimeException
112+
*/
113+
publicfunctiontestLegacyCreateTableTwice()
83114
{
84-
$dsn =$this->getPersistentSqliteDsn();
85-
86-
$storage =newPdoSessionHandler($dsn,array('db_lifetime_col' =>false));
115+
$storage =$this->getSessionHandler();
87116
$storage->createTable();
117+
}
118+
119+
publicfunctiontestWithLazyDsnConnection()
120+
{
121+
$storage =$this->getSessionHandler($this->getPersistentSqliteDsn());
88122
$storage->open('','sid');
89123
$data =$storage->read('id');
90124
$storage->write('id','data');
@@ -98,11 +132,24 @@ public function testWithLazyDsnConnection()
98132
}
99133

100134
publicfunctiontestWithLazySavePathConnection()
135+
{
136+
$this->doTestReadWriteReadWithNullByte($this->getSessionHandler(null,array('db_lifetime_col' =>false),false));
137+
}
138+
139+
/**
140+
* @group legacy
141+
* @expectedDeprecation The "%s" column is deprecated since version 3.3 and won't be used anymore in 4.0. Migrate your session database then set the "db_lifetime_col" option to false to opt-in for the new behavior.
142+
*/
143+
publicfunctiontestLegacyWithLazySavePathConnection()
144+
{
145+
$this->doTestReadWriteReadWithNullByte($this->getSessionHandler(null,array('db_lifetime_col' =>'foobar'),false));
146+
}
147+
148+
privatefunctiondoTestWithLazySavePathConnection(PdoSessionHandler$storage)
101149
{
102150
$dsn =$this->getPersistentSqliteDsn();
103151

104152
// Open is called with what ini_set('session.save_path', $dsn) would mean
105-
$storage =newPdoSessionHandler(null,array('db_lifetime_col' =>false));
106153
$storage->open($dsn,'sid');
107154
$storage->createTable();
108155
$data =$storage->read('id');
@@ -117,11 +164,25 @@ public function testWithLazySavePathConnection()
117164
}
118165

119166
publicfunctiontestReadWriteReadWithNullByte()
167+
{
168+
$this->doTestReadWriteReadWithNullByte($this->getSessionHandler(null,array('db_lifetime_col' =>false),false));
169+
}
170+
171+
/**
172+
* @group legacy
173+
* @expectedDeprecation The "%s" column is deprecated since version 3.3 and won't be used anymore in 4.0. Migrate your session database then set the "db_lifetime_col" option to false to opt-in for the new behavior.
174+
*/
175+
publicfunctiontestLegacyReadWriteReadWithNullByte()
176+
{
177+
$this->doTestReadWriteReadWithNullByte($this->getSessionHandler(null,array('db_lifetime_col' =>'foobar'),false));
178+
}
179+
180+
privatefunctiondoTestReadWriteReadWithNullByte(PdoSessionHandler$storage)
120181
{
121182
$sessionData ='da'."\0".'ta';
122183

123-
$storage =newPdoSessionHandler($this->getMemorySqlitePdo(),array('db_lifetime_col' =>false));
124184
$storage->open('','sid');
185+
$storage->createTable();
125186
$readData =$storage->read('id');
126187
$storage->write('id',$sessionData);
127188
$storage->close();
@@ -190,7 +251,20 @@ public function testReadLockedConvertsStreamToString()
190251

191252
publicfunctiontestReadingRequiresExactlySameId()
192253
{
193-
$storage =newPdoSessionHandler($this->getMemorySqlitePdo(),array('db_lifetime_col' =>false));
254+
$this->doTestReadingRequiresExactlySameId($this->getSessionHandler());
255+
}
256+
257+
/**
258+
* @group legacy
259+
* @expectedDeprecation The "%s" column is deprecated since version 3.3 and won't be used anymore in 4.0. Migrate your session database then set the "db_lifetime_col" option to false to opt-in for the new behavior.
260+
*/
261+
publicfunctiontestLegacyReadingRequiresExactlySameId()
262+
{
263+
$this->doTestReadingRequiresExactlySameId($this->getSessionHandler(null,array('db_lifetime_col' =>'foobar')));
264+
}
265+
266+
privatefunctiondoTestReadingRequiresExactlySameId(PdoSessionHandler$storage)
267+
{
194268
$storage->open('','sid');
195269
$storage->write('id','data');
196270
$storage->write('test','data');
@@ -210,13 +284,26 @@ public function testReadingRequiresExactlySameId()
210284
$this->assertSame('',$readDataExtraSpace,'Retrieval by ID requires spaces as-is');
211285
}
212286

287+
publicfunctiontestWriteDifferentSessionIdThanRead()
288+
{
289+
$this->doTestWriteDifferentSessionIdThanRead($this->getSessionHandler());
290+
291+
}
292+
293+
/**
294+
* @group legacy
295+
* @expectedDeprecation The "%s" column is deprecated since version 3.3 and won't be used anymore in 4.0. Migrate your session database then set the "db_lifetime_col" option to false to opt-in for the new behavior.
296+
*/
297+
publicfunctiontestLegacyWriteDifferentSessionIdThanRead()
298+
{
299+
$this->doTestWriteDifferentSessionIdThanRead($this->getSessionHandler(null,array('db_lifetime_col' =>'foobar')));
300+
}
301+
213302
/**
214303
* Simulates session_regenerate_id(true) which will require an INSERT or UPDATE (replace).
215304
*/
216-
publicfunctiontestWriteDifferentSessionIdThanRead()
305+
privatefunctiondoTestWriteDifferentSessionIdThanRead(PdoSessionHandler$storage)
217306
{
218-
$storage =newPdoSessionHandler($this->getMemorySqlitePdo(),array('db_lifetime_col' =>false));
219-
$storage->open('','sid');
220307
$storage->open('','sid');
221308
$storage->read('id');
222309
$storage->destroy('id');
@@ -232,8 +319,20 @@ public function testWriteDifferentSessionIdThanRead()
232319

233320
publicfunctiontestWrongUsageStillWorks()
234321
{
235-
// wrong method sequence that should no happen, but still works
236-
$storage =newPdoSessionHandler($this->getMemorySqlitePdo(),array('db_lifetime_col' =>false));
322+
$this->doTestWrongUsageStillWorks($this->getSessionHandler());
323+
}
324+
325+
/**
326+
* @group legacy
327+
* @expectedDeprecation The "%s" column is deprecated since version 3.3 and won't be used anymore in 4.0. Migrate your session database then set the "db_lifetime_col" option to false to opt-in for the new behavior.
328+
*/
329+
publicfunctiontestLegacyWrongUsageStillWorks()
330+
{
331+
$this->doTestWrongUsageStillWorks($this->getSessionHandler(null,array('db_lifetime_col' =>'foobar')));
332+
}
333+
334+
privatefunctiondoTestWrongUsageStillWorks(PdoSessionHandler$storage)
335+
{
237336
$storage->write('id','data');
238337
$storage->write('other_id','other_data');
239338
$storage->destroy('inexistent');
@@ -248,9 +347,24 @@ public function testWrongUsageStillWorks()
248347

249348
publicfunctiontestSessionDestroy()
250349
{
251-
$pdo =$this->getMemorySqlitePdo();
252-
$storage =newPdoSessionHandler($pdo,array('db_lifetime_col' =>false));
350+
$storage =$this->getSessionHandler($pdo =$this->getPdoMemorySqlite());
351+
352+
$this->doTestSessionDestroy($pdo,$storage);
353+
}
354+
355+
/**
356+
* @group legacy
357+
* @expectedDeprecation The "%s" column is deprecated since version 3.3 and won't be used anymore in 4.0. Migrate your session database then set the "db_lifetime_col" option to false to opt-in for the new behavior.
358+
*/
359+
publicfunctiontestLegacySessionDestroy()
360+
{
361+
$storage =$this->getSessionHandler($pdo =$this->getPdoMemorySqlite(),array('db_lifetime_col' =>'foobar'));
362+
363+
$this->doTestSessionDestroy($pdo,$storage);
364+
}
253365

366+
privatefunctiondoTestSessionDestroy(\PDO$pdo,PdoSessionHandler$storage)
367+
{
254368
$storage->open('','sid');
255369
$storage->read('id');
256370
$storage->write('id','data');
@@ -270,10 +384,26 @@ public function testSessionDestroy()
270384
}
271385

272386
publicfunctiontestSessionGC()
387+
{
388+
$storage =$this->getSessionHandler($pdo =$this->getPdoMemorySqlite());
389+
390+
$this->doTestSessionGC($pdo,$storage);
391+
}
392+
393+
/**
394+
* @group legacy
395+
* @expectedDeprecation The "%s" column is deprecated since version 3.3 and won't be used anymore in 4.0. Migrate your session database then set the "db_lifetime_col" option to false to opt-in for the new behavior.
396+
*/
397+
publicfunctiontestLegacySessionGC()
398+
{
399+
$storage =$this->getSessionHandler($pdo =$this->getPdoMemorySqlite(),array('db_lifetime_col' =>'foobar'));
400+
401+
$this->doTestSessionGC($pdo,$storage);
402+
}
403+
404+
privatefunctiondoTestSessionGC(\PDO$pdo,PdoSessionHandler$storage)
273405
{
274406
$previousLifeTime =ini_set('session.gc_maxlifetime',1000);
275-
$pdo =$this->getMemorySqlitePdo();
276-
$storage =newPdoSessionHandler($pdo,array('db_lifetime_col' =>false));
277407

278408
$storage->open('','sid');
279409
$storage->read('id');
@@ -300,7 +430,7 @@ public function testSessionGC()
300430

301431
publicfunctiontestGetConnection()
302432
{
303-
$storage =newPdoSessionHandler($this->getMemorySqlitePdo(),array('db_lifetime_col' =>false));
433+
$storage =$this->getSessionHandler();
304434

305435
$method =new \ReflectionMethod($storage,'getConnection');
306436
$method->setAccessible(true);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp