mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 03:37:44 +08:00
Added test cases.
This commit is contained in:
parent
0eaa14c13f
commit
7aea1ffbe6
@ -106,6 +106,29 @@ class ConnectionTest extends TestCase
|
||||
$this->assertSame('mysql:host=192.168.1.1;dbname=hyperf', $pdo->dsn);
|
||||
}
|
||||
|
||||
public function testPdoDontDestruct()
|
||||
{
|
||||
$callables = [function ($connection) {
|
||||
$connection->selectOne('SELECT 1;');
|
||||
}, function ($connection) {
|
||||
$connection->table('user')->leftJoin('user_ext', 'user.id', '=', 'user_ext.id')->get();
|
||||
}];
|
||||
foreach ($callables as $callable) {
|
||||
PDOStub::$destruct = 0;
|
||||
$container = ContainerStub::mockContainer();
|
||||
$pool = $container->get(PoolFactory::class)->getPool('default');
|
||||
$config = $container->get(ConfigInterface::class)->get('databases.default');
|
||||
$connection = new ConnectionStub($container, $pool, $config);
|
||||
$connection->setPdo(new PDOStub('', '', '', []));
|
||||
|
||||
$callable($connection);
|
||||
|
||||
$this->assertSame(0, PDOStub::$destruct);
|
||||
$connection->close();
|
||||
$this->assertSame(1, PDOStub::$destruct);
|
||||
}
|
||||
}
|
||||
|
||||
public function testConnectionSticky()
|
||||
{
|
||||
$container = ContainerStub::mockReadWriteContainer();
|
||||
|
@ -58,7 +58,7 @@ class ContainerStub
|
||||
'databases' => [
|
||||
'default' => [
|
||||
'driver' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'host' => '127.0.0.1',
|
||||
'database' => 'hyperf',
|
||||
'username' => 'root',
|
||||
'password' => '',
|
||||
|
@ -21,6 +21,8 @@ class PDOStub extends \PDO
|
||||
|
||||
public $options;
|
||||
|
||||
public static $destruct = 0;
|
||||
|
||||
public function __construct(string $dsn, string $username, string $passwd, array $options)
|
||||
{
|
||||
$this->dsn = $dsn;
|
||||
@ -37,4 +39,9 @@ class PDOStub extends \PDO
|
||||
public function exec($statement)
|
||||
{
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
self::$destruct++;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user