Unverified Commit a2f1af72 authored by Michael Moravec's avatar Michael Moravec Committed by Sergei Morozov

Remove deprecated MysqlSessionInit listener

parent f3828fbd
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Removed `json_array` type and all associated hacks. * Removed `json_array` type and all associated hacks.
* Removed `Connection::TRANSACTION_*` constants. * Removed `Connection::TRANSACTION_*` constants.
* Removed `AbstractPlatform::DATE_INTERVAL_UNIT_*` and `AbstractPlatform::TRIM_*` constants. * Removed `AbstractPlatform::DATE_INTERVAL_UNIT_*` and `AbstractPlatform::TRIM_*` constants.
* Removed `MysqlSessionInit` listener.
## BC BREAK changes the `Driver::connect()` signature ## BC BREAK changes the `Driver::connect()` signature
......
<?php
namespace Doctrine\DBAL\Event\Listeners;
use Doctrine\Common\EventSubscriber;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Events;
/**
* MySQL Session Init Event Subscriber which allows to set the Client Encoding of the Connection.
*
* @deprecated Use "charset" option to PDO MySQL Connection instead.
*/
class MysqlSessionInit implements EventSubscriber
{
/**
* The charset.
*
* @var string
*/
private $charset;
/**
* The collation, or FALSE if no collation.
*
* @var string|bool
*/
private $collation;
/**
* Configure Charset and Collation options of MySQL Client for each Connection.
*
* @param string $charset The charset.
* @param string|bool $collation The collation, or FALSE if no collation.
*/
public function __construct($charset = 'utf8', $collation = false)
{
$this->charset = $charset;
$this->collation = $collation;
}
/**
* @return void
*/
public function postConnect(ConnectionEventArgs $args)
{
$statement = 'SET NAMES ' . $this->charset;
if ($this->collation !== false) {
$statement .= ' COLLATE ' . $this->collation;
}
$args->getConnection()->executeUpdate($statement);
}
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
{
return [Events::postConnect];
}
}
<?php
namespace Doctrine\DBAL\Tests\Events;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Event\Listeners\MysqlSessionInit;
use Doctrine\DBAL\Events;
use PHPUnit\Framework\TestCase;
class MysqlSessionInitTest extends TestCase
{
public function testPostConnect(): void
{
$connectionMock = $this->createMock(Connection::class);
$connectionMock->expects(self::once())
->method('executeUpdate')
->with(self::equalTo('SET NAMES foo COLLATE bar'));
$eventArgs = new ConnectionEventArgs($connectionMock);
$listener = new MysqlSessionInit('foo', 'bar');
$listener->postConnect($eventArgs);
}
public function testGetSubscribedEvents(): void
{
$listener = new MysqlSessionInit();
self::assertEquals([Events::postConnect], $listener->getSubscribedEvents());
}
}
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