mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Added Hyperf\Database\Schema\Blueprint::tinyText()
. (#7071)
Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
parent
8763ac81fc
commit
a8f21f685e
@ -1,5 +1,9 @@
|
||||
# v3.1.44 - TBD
|
||||
|
||||
## Added
|
||||
|
||||
- [#7071](https://github.com/hyperf/hyperf/pull/7071) Added `Hyperf\Database\Schema\Blueprint::tinyText()`.
|
||||
|
||||
# v3.1.43 - 2024-10-10
|
||||
|
||||
## Fixed
|
||||
|
@ -552,6 +552,17 @@ class Blueprint
|
||||
return $this->addColumn('string', $column, compact('length'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new tiny text column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return ColumnDefinition
|
||||
*/
|
||||
public function tinyText($column)
|
||||
{
|
||||
return $this->addColumn('tinyText', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new text column on the table.
|
||||
*
|
||||
|
@ -637,6 +637,16 @@ class MySqlGrammar extends Grammar
|
||||
return "varchar({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a tiny text type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTinyText(Fluent $column)
|
||||
{
|
||||
return 'tinytext';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a text type.
|
||||
*
|
||||
|
@ -541,6 +541,16 @@ class MySqlSchemaGrammarTest extends TestCase
|
||||
$this->assertSame('alter table `users` add `foo` varchar(100) null default CURRENT TIMESTAMP', $statements[0]);
|
||||
}
|
||||
|
||||
public function testAddTinyText()
|
||||
{
|
||||
$blueprint = new Blueprint('users');
|
||||
$blueprint->tinyText('foo');
|
||||
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
|
||||
|
||||
$this->assertCount(1, $statements);
|
||||
$this->assertSame('alter table `users` add `foo` tinytext not null', $statements[0]);
|
||||
}
|
||||
|
||||
public function testAddingText()
|
||||
{
|
||||
$blueprint = new Blueprint('users');
|
||||
|
@ -23,8 +23,10 @@ use Hyperf\DbConnection\Connection;
|
||||
use Hyperf\DbConnection\Pool\PoolFactory;
|
||||
use Hyperf\Support\Reflection\ClassInvoker;
|
||||
use HyperfTest\DbConnection\Stubs\ConnectionStub;
|
||||
use HyperfTest\DbConnection\Stubs\ConnectionStub2;
|
||||
use HyperfTest\DbConnection\Stubs\ContainerStub;
|
||||
use HyperfTest\DbConnection\Stubs\PDOStub;
|
||||
use HyperfTest\DbConnection\Stubs\PDOStub2;
|
||||
use Mockery;
|
||||
use PHPUnit\Framework\Attributes\CoversNothing;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@ -127,9 +129,9 @@ class ConnectionTest extends TestCase
|
||||
$config = $container->get(ConfigInterface::class)->get('databases.default');
|
||||
|
||||
$callables = [
|
||||
function ($connection) {
|
||||
function (Connection $connection) {
|
||||
$connection->selectOne('SELECT 1;');
|
||||
}, function ($connection) {
|
||||
}, function (Connection $connection) {
|
||||
$connection->table('user')->leftJoin('user_ext', 'user.id', '=', 'user_ext.id')->get();
|
||||
},
|
||||
];
|
||||
@ -142,16 +144,16 @@ class ConnectionTest extends TestCase
|
||||
},
|
||||
];
|
||||
|
||||
Context::set(PDOStub::class . '::destruct', 0);
|
||||
Context::set(PDOStub2::class . '::destruct', 0);
|
||||
$count = 0;
|
||||
foreach ($callables as $callable) {
|
||||
foreach ($closes as $closure) {
|
||||
$connection = new ConnectionStub($container, $pool, $config);
|
||||
$connection->setPdo(new PDOStub('', '', '', []));
|
||||
$connection = new ConnectionStub2($container, $pool, $config);
|
||||
$connection->setPdo(new PDOStub2('', '', '', []));
|
||||
$callable($connection);
|
||||
$this->assertSame($count, Context::get(PDOStub::class . '::destruct', 0));
|
||||
$this->assertSame($count, Context::get(PDOStub2::class . '::destruct', 0));
|
||||
$closure($connection);
|
||||
$this->assertSame(++$count, Context::get(PDOStub::class . '::destruct', 0));
|
||||
$this->assertSame(++$count, Context::get(PDOStub2::class . '::destruct', 0));
|
||||
}
|
||||
}
|
||||
}, 10);
|
||||
|
@ -32,6 +32,7 @@ class RelationTest extends TestCase
|
||||
{
|
||||
Mockery::close();
|
||||
Context::set('database.connection.default', null);
|
||||
Register::unsetConnectionResolver();
|
||||
}
|
||||
|
||||
public function testPivot()
|
||||
|
28
src/db-connection/tests/Stubs/ConnectionStub2.php
Normal file
28
src/db-connection/tests/Stubs/ConnectionStub2.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace HyperfTest\DbConnection\Stubs;
|
||||
|
||||
use Hyperf\DbConnection\Connection;
|
||||
|
||||
class ConnectionStub2 extends Connection
|
||||
{
|
||||
/**
|
||||
* Refresh pdo and readPdo for current connection.
|
||||
*/
|
||||
protected function refresh(\Hyperf\Database\Connection $connection)
|
||||
{
|
||||
$connection->disconnect();
|
||||
$connection->setPdo(new PDOStub2('', '', '', []));
|
||||
$connection->setReadPdo(new PDOStub2('', '', '', []));
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ use Hyperf\Contract\StdoutLoggerInterface;
|
||||
use Hyperf\Database\ConnectionResolverInterface;
|
||||
use Hyperf\Database\Connectors\ConnectionFactory;
|
||||
use Hyperf\Database\Connectors\MySqlConnector;
|
||||
use Hyperf\Database\Model\Register;
|
||||
use Hyperf\DbConnection\ConnectionResolver;
|
||||
use Hyperf\DbConnection\Frequency;
|
||||
use Hyperf\DbConnection\Pool\PoolFactory;
|
||||
@ -43,6 +44,8 @@ class ContainerStub
|
||||
$resolver = new ConnectionResolver($container);
|
||||
$container->shouldReceive('get')->with(ConnectionResolverInterface::class)->andReturn($resolver);
|
||||
|
||||
Register::setConnectionResolver($resolver);
|
||||
|
||||
$config = new Config([
|
||||
StdoutLoggerInterface::class => [
|
||||
'log_level' => [
|
||||
|
@ -1,121 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace HyperfTest\DbConnection\Stubs;
|
||||
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
|
||||
class PDOStatementStub extends PDOStatement
|
||||
{
|
||||
public $statement;
|
||||
|
||||
public function __construct($statement)
|
||||
{
|
||||
$this->statement = $statement;
|
||||
}
|
||||
|
||||
public function execute($input_parameters = null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function fetch($fetch_style = null, $cursor_orientation = PDO::FETCH_ORI_NEXT, $cursor_offset = 0)
|
||||
{
|
||||
parent::fetch($fetch_style, $cursor_orientation, $cursor_offset);
|
||||
}
|
||||
|
||||
public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = null, $driver_options = null)
|
||||
{
|
||||
parent::bindParam($parameter, $variable, $data_type, $length, $driver_options);
|
||||
}
|
||||
|
||||
public function bindColumn($column, &$param, $type = null, $maxlen = null, $driverdata = null)
|
||||
{
|
||||
parent::bindColumn($column, $param, $type, $maxlen, $driverdata);
|
||||
}
|
||||
|
||||
public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR)
|
||||
{
|
||||
parent::bindValue($parameter, $value, $data_type);
|
||||
}
|
||||
|
||||
public function rowCount()
|
||||
{
|
||||
parent::rowCount();
|
||||
}
|
||||
|
||||
public function fetchColumn($column_number = 0)
|
||||
{
|
||||
parent::fetchColumn($column_number);
|
||||
}
|
||||
|
||||
public function fetchAll($fetch_style = null, $fetch_argument = null, $ctor_args = null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function fetchObject($class_name = 'stdClass', $ctor_args = null)
|
||||
{
|
||||
parent::fetchObject($class_name, $ctor_args);
|
||||
}
|
||||
|
||||
public function errorCode()
|
||||
{
|
||||
parent::errorCode();
|
||||
}
|
||||
|
||||
public function errorInfo()
|
||||
{
|
||||
parent::errorInfo();
|
||||
}
|
||||
|
||||
public function setAttribute($attribute, $value)
|
||||
{
|
||||
parent::setAttribute($attribute, $value);
|
||||
}
|
||||
|
||||
public function getAttribute($attribute)
|
||||
{
|
||||
parent::getAttribute($attribute);
|
||||
}
|
||||
|
||||
public function columnCount()
|
||||
{
|
||||
parent::columnCount();
|
||||
}
|
||||
|
||||
public function getColumnMeta($column)
|
||||
{
|
||||
parent::getColumnMeta($column);
|
||||
}
|
||||
|
||||
public function setFetchMode($mode, $params = null)
|
||||
{
|
||||
parent::setFetchMode($mode, $params);
|
||||
}
|
||||
|
||||
public function nextRowset()
|
||||
{
|
||||
parent::nextRowset();
|
||||
}
|
||||
|
||||
public function closeCursor()
|
||||
{
|
||||
parent::closeCursor();
|
||||
}
|
||||
|
||||
public function debugDumpParams()
|
||||
{
|
||||
parent::debugDumpParams();
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ namespace HyperfTest\DbConnection\Stubs;
|
||||
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
use ReturnTypeWillChange;
|
||||
|
||||
class PDOStatementStubPHP8 extends PDOStatement
|
||||
{
|
||||
@ -24,98 +25,45 @@ class PDOStatementStubPHP8 extends PDOStatement
|
||||
$this->statement = $statement;
|
||||
}
|
||||
|
||||
public function execute($input_parameters = null): bool
|
||||
#[ReturnTypeWillChange]
|
||||
public function execute(?array $params = null): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function fetch($fetch_style = null, $cursor_orientation = PDO::FETCH_ORI_NEXT, $cursor_offset = 0): mixed
|
||||
#[ReturnTypeWillChange]
|
||||
public function fetch(int $mode = PDO::FETCH_DEFAULT, int $cursorOrientation = PDO::FETCH_ORI_NEXT, int $cursorOffset = 0): mixed
|
||||
{
|
||||
return parent::fetch($fetch_style, $cursor_orientation, $cursor_offset);
|
||||
return null;
|
||||
}
|
||||
|
||||
public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = null, $driver_options = null): bool
|
||||
#[ReturnTypeWillChange]
|
||||
public function bindParam(int|string $param, mixed &$var, int $type = PDO::PARAM_STR, ?int $maxLength = 0, mixed $driverOptions = null): bool
|
||||
{
|
||||
return parent::bindParam($parameter, $variable, $data_type, $length, $driver_options);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function bindColumn($column, &$param, $type = null, $maxlen = null, $driverdata = null): bool
|
||||
#[ReturnTypeWillChange]
|
||||
public function bindColumn(int|string $column, mixed &$var, int $type = PDO::PARAM_STR, int $maxLength = 0, mixed $driverOptions = null): bool
|
||||
{
|
||||
return parent::bindColumn($column, $param, $type, $maxlen, $driverdata);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function bindValue($parameter, $value, $data_type = PDO::PARAM_STR): bool
|
||||
#[ReturnTypeWillChange]
|
||||
public function bindValue(int|string $param, mixed $value, int $type = PDO::PARAM_STR): bool
|
||||
{
|
||||
return parent::bindValue($parameter, $value, $data_type);
|
||||
}
|
||||
|
||||
public function rowCount(): int
|
||||
{
|
||||
return parent::rowCount();
|
||||
}
|
||||
|
||||
public function fetchColumn($column_number = 0): mixed
|
||||
{
|
||||
return parent::fetchColumn($column_number);
|
||||
return true;
|
||||
}
|
||||
|
||||
#[ReturnTypeWillChange]
|
||||
public function fetchAll(int $mode = PDO::FETCH_BOTH, mixed ...$args): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function fetchObject($class_name = 'stdClass', $ctor_args = null): object
|
||||
{
|
||||
return parent::fetchObject($class_name, $ctor_args);
|
||||
}
|
||||
|
||||
public function errorCode(): ?string
|
||||
{
|
||||
return parent::errorCode();
|
||||
}
|
||||
|
||||
public function errorInfo(): array
|
||||
{
|
||||
return parent::errorInfo();
|
||||
}
|
||||
|
||||
public function setAttribute($attribute, $value): bool
|
||||
{
|
||||
return parent::setAttribute($attribute, $value);
|
||||
}
|
||||
|
||||
public function getAttribute($attribute): mixed
|
||||
{
|
||||
return parent::getAttribute($attribute);
|
||||
}
|
||||
|
||||
public function columnCount(): int
|
||||
{
|
||||
return parent::columnCount();
|
||||
}
|
||||
|
||||
public function getColumnMeta($column): array
|
||||
{
|
||||
return parent::getColumnMeta($column);
|
||||
}
|
||||
|
||||
#[ReturnTypeWillChange]
|
||||
public function setFetchMode($mode, $className = null, ...$params)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function nextRowset(): bool
|
||||
{
|
||||
return parent::nextRowset();
|
||||
}
|
||||
|
||||
public function closeCursor(): bool
|
||||
{
|
||||
return parent::closeCursor();
|
||||
}
|
||||
|
||||
public function debugDumpParams(): ?bool
|
||||
{
|
||||
return parent::debugDumpParams();
|
||||
}
|
||||
}
|
||||
|
@ -12,80 +12,25 @@ declare(strict_types=1);
|
||||
|
||||
namespace HyperfTest\DbConnection\Stubs;
|
||||
|
||||
use Hyperf\Context\Context;
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
use ReturnTypeWillChange;
|
||||
|
||||
if (PHP_VERSION_ID >= 80300) {
|
||||
class PDOStub extends PDO
|
||||
class PDOStub extends PDO
|
||||
{
|
||||
public function __construct(public string $dsn, public ?string $username = null, public ?string $password = null, public ?array $options = null)
|
||||
{
|
||||
public $dsn;
|
||||
|
||||
public $username;
|
||||
|
||||
public $passwd;
|
||||
|
||||
public $options;
|
||||
|
||||
public function __construct($dsn, $username, $passwd, $options)
|
||||
{
|
||||
$this->dsn = $dsn;
|
||||
$this->username = $username;
|
||||
$this->passwd = $passwd;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$key = PDOStub::class . '::destruct';
|
||||
$count = Context::get($key, 0);
|
||||
Context::set($key, $count + 1);
|
||||
}
|
||||
|
||||
public function prepare($statement, $driver_options = null): false|PDOStatement
|
||||
{
|
||||
return new PDOStatementStubPHP8($statement);
|
||||
}
|
||||
|
||||
public function exec($statement): false|int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
class PDOStub extends PDO
|
||||
|
||||
#[ReturnTypeWillChange]
|
||||
public function prepare(string $query, array $options = []): bool|PDOStatement
|
||||
{
|
||||
public $dsn;
|
||||
return new PDOStatementStubPHP8($query);
|
||||
}
|
||||
|
||||
public $username;
|
||||
|
||||
public $passwd;
|
||||
|
||||
public $options;
|
||||
|
||||
public function __construct($dsn, $username, $passwd, $options)
|
||||
{
|
||||
$this->dsn = $dsn;
|
||||
$this->username = $username;
|
||||
$this->passwd = $passwd;
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$key = PDOStub::class . '::destruct';
|
||||
$count = Context::get($key, 0);
|
||||
Context::set($key, $count + 1);
|
||||
}
|
||||
|
||||
public function prepare($statement, $driver_options = null)
|
||||
{
|
||||
return new PDOStatementStubPHP8($statement);
|
||||
}
|
||||
|
||||
public function exec($statement)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#[ReturnTypeWillChange]
|
||||
public function exec(string $statement): bool|int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
44
src/db-connection/tests/Stubs/PDOStub2.php
Normal file
44
src/db-connection/tests/Stubs/PDOStub2.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of Hyperf.
|
||||
*
|
||||
* @link https://www.hyperf.io
|
||||
* @document https://hyperf.wiki
|
||||
* @contact group@hyperf.io
|
||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
namespace HyperfTest\DbConnection\Stubs;
|
||||
|
||||
use Hyperf\Context\Context;
|
||||
use PDO;
|
||||
use PDOStatement;
|
||||
use ReturnTypeWillChange;
|
||||
|
||||
class PDOStub2 extends PDO
|
||||
{
|
||||
public function __construct(public string $dsn, public ?string $username = null, public ?string $password = null, public ?array $options = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$key = PDOStub2::class . '::destruct';
|
||||
$count = Context::get($key, 0);
|
||||
Context::set($key, $count + 1);
|
||||
}
|
||||
|
||||
#[ReturnTypeWillChange]
|
||||
public function prepare(string $query, array $options = []): bool|PDOStatement
|
||||
{
|
||||
return new PDOStatementStubPHP8($query);
|
||||
}
|
||||
|
||||
#[ReturnTypeWillChange]
|
||||
public function exec(string $statement): bool|int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user