123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- /**
- * 生成表.
- * User: Administrator
- * Date: 2019/11/3 0003
- * Time: 0:28
- */
- namespace EasySwoole\ORM\Tests;
- use PHPUnit\Framework\TestCase;
- use EasySwoole\Mysqli\QueryBuilder;
- use EasySwoole\ORM\Db\Config;
- use EasySwoole\ORM\Db\Connection;
- use EasySwoole\ORM\DbManager;
- use EasySwoole\ORM\Utility\Schema\Table;
- use EasySwoole\ORM\Utility\TableObjectGeneration;
- class TimeStampTableGenerationTest extends TestCase
- {
- /**
- * @var $generation TableObjectGeneration
- */
- protected $generation;
- /**
- * @var $connection Connection
- */
- protected $connection;
- protected $tableName = 'tiamstamp_test';
- protected function setUp(): void
- {
- parent::setUp(); // TODO: Change the autogenerated stub
- $config = new Config(MYSQL_CONFIG);
- $connection = new Connection($config);
- $this->connection = $connection;
- $this->generation = new TableObjectGeneration($connection, $this->tableName);
- $this->createTestTable();
- }
- function createTestTable()
- {
- $sql = "DROP TABLE if exists {$this->tableName};";
- $query = new QueryBuilder();
- $query->raw($sql);
- $data = $this->connection->defer()->query($query);
- $this->assertTrue($data->getResult());
- $tableDDL = new Table($this->tableName);
- $tableDDL->colInt('id', 11)->setIsPrimaryKey()->setIsAutoIncrement();
- $tableDDL->colVarChar('name', 255);
- $tableDDL->colTinyInt('age', 1);
- $tableDDL->colDateTime('create_time')->setIsNotNull(false);
- $tableDDL->colDateTime('update_time')->setIsNotNull(false);
- $tableDDL->colInt('create_at', 10)->setIsNotNull(false);
- $tableDDL->colInt('update_at', 10)->setIsNotNull(false);
- $tableDDL->setIfNotExists();
- $sql = $tableDDL->__createDDL();
- $query->raw($sql);
- $data = $this->connection->defer()->query($query);
- $this->assertTrue($data->getResult());
- }
- function testGetTableInfo()
- {
- $data = $this->generation->getTableColumnsInfo();
- $this->assertIsArray($data);
- }
- }
|