Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Session/Storage/Handler/PdoSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public function configureSchema(Schema $schema, ?\Closure $isSameDatabase = null
$table->addColumn($this->dataCol, Types::BLOB)->setNotnull(true);
$table->addColumn($this->lifetimeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
$table->addColumn($this->timeCol, Types::INTEGER)->setUnsigned(true)->setNotnull(true);
$table->addOption('charset', 'utf8mb4');
$table->addOption('collate', 'utf8mb4_bin');
$table->addOption('engine', 'InnoDB');
break;
Expand Down
16 changes: 16 additions & 0 deletions Tests/Session/Storage/Handler/PdoSessionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,22 @@ public function testConfigureSchemaTableExistsPdo()
$this->assertEmpty($table->getColumns(), 'The table was not overwritten');
}

public function testConfigureSchemaSetsUtf8mb4CharsetForMysql()
{
$pdo = new MockPdo('mysql');
$pdo->prepareResult = $this->createMock(\PDOStatement::class);

$schema = new Schema();

$pdoSessionHandler = new PdoSessionHandler($pdo);
$pdoSessionHandler->configureSchema($schema, fn () => true);

$this->assertTrue($schema->hasTable('sessions'));
$table = $schema->getTable('sessions');
$this->assertSame('utf8mb4', $table->getOption('charset'));
$this->assertSame('utf8mb4_bin', $table->getOption('collate'));
}

public static function provideUrlDsnPairs()
{
yield ['mysql://localhost/test', 'mysql:host=localhost;dbname=test;'];
Expand Down