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

Remove deprecated MysqlSessionInit listener

parent 7f6e19f1
...@@ -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 `Connection::ping()` returns `void`. ## BC BREAK `Connection::ping()` returns `void`.
......
<?php
declare(strict_types=1);
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)
{
$collation = $this->collation ? ' COLLATE ' . $this->collation : '';
$args->getConnection()->executeUpdate('SET NAMES ' . $this->charset . $collation);
}
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
{
return [Events::postConnect];
}
}
<?php
declare(strict_types=1);
namespace Doctrine\Tests\DBAL\Events;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Event\ConnectionEventArgs;
use Doctrine\DBAL\Event\Listeners\MysqlSessionInit;
use Doctrine\DBAL\Events;
use Doctrine\Tests\DbalTestCase;
class MysqlSessionInitTest extends DbalTestCase
{
public function testPostConnect() : void
{
$connectionMock = $this->createMock(Connection::class);
$connectionMock->expects($this->once())
->method('executeUpdate')
->with($this->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