TimeStampTableGenerationTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * 生成表.
  4. * User: Administrator
  5. * Date: 2019/11/3 0003
  6. * Time: 0:28
  7. */
  8. namespace EasySwoole\ORM\Tests;
  9. use PHPUnit\Framework\TestCase;
  10. use EasySwoole\Mysqli\QueryBuilder;
  11. use EasySwoole\ORM\Db\Config;
  12. use EasySwoole\ORM\Db\Connection;
  13. use EasySwoole\ORM\DbManager;
  14. use EasySwoole\ORM\Utility\Schema\Table;
  15. use EasySwoole\ORM\Utility\TableObjectGeneration;
  16. class TimeStampTableGenerationTest extends TestCase
  17. {
  18. /**
  19. * @var $generation TableObjectGeneration
  20. */
  21. protected $generation;
  22. /**
  23. * @var $connection Connection
  24. */
  25. protected $connection;
  26. protected $tableName = 'tiamstamp_test';
  27. protected function setUp(): void
  28. {
  29. parent::setUp(); // TODO: Change the autogenerated stub
  30. $config = new Config(MYSQL_CONFIG);
  31. $connection = new Connection($config);
  32. $this->connection = $connection;
  33. $this->generation = new TableObjectGeneration($connection, $this->tableName);
  34. $this->createTestTable();
  35. }
  36. function createTestTable()
  37. {
  38. $sql = "DROP TABLE if exists {$this->tableName};";
  39. $query = new QueryBuilder();
  40. $query->raw($sql);
  41. $data = $this->connection->defer()->query($query);
  42. $this->assertTrue($data->getResult());
  43. $tableDDL = new Table($this->tableName);
  44. $tableDDL->colInt('id', 11)->setIsPrimaryKey()->setIsAutoIncrement();
  45. $tableDDL->colVarChar('name', 255);
  46. $tableDDL->colTinyInt('age', 1);
  47. $tableDDL->colDateTime('create_time')->setIsNotNull(false);
  48. $tableDDL->colDateTime('update_time')->setIsNotNull(false);
  49. $tableDDL->colInt('create_at', 10)->setIsNotNull(false);
  50. $tableDDL->colInt('update_at', 10)->setIsNotNull(false);
  51. $tableDDL->setIfNotExists();
  52. $sql = $tableDDL->__createDDL();
  53. $query->raw($sql);
  54. $data = $this->connection->defer()->query($query);
  55. $this->assertTrue($data->getResult());
  56. }
  57. function testGetTableInfo()
  58. {
  59. $data = $this->generation->getTableColumnsInfo();
  60. $this->assertIsArray($data);
  61. }
  62. }