ModelCloneCreateTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Siam
  5. * Date: 2020/7/26 0026
  6. * Time: 8:12
  7. */
  8. namespace EasySwoole\ORM\Tests;
  9. use EasySwoole\Mysqli\QueryBuilder;
  10. use EasySwoole\ORM\Db\Config;
  11. use EasySwoole\ORM\Db\Connection;
  12. use EasySwoole\ORM\DbManager;
  13. use EasySwoole\ORM\Exception\Exception;
  14. use EasySwoole\ORM\Tests\models\TestRelationModel;
  15. use EasySwoole\ORM\Tests\models\TestTimeStampModel;
  16. use EasySwoole\ORM\Utility\Schema\Table;
  17. use PHPUnit\Framework\TestCase;
  18. class ModelCloneCreateTest extends TestCase
  19. {
  20. /**
  21. * @var $connection Connection
  22. */
  23. protected $connection;
  24. protected $tableName = 'test_user_model';
  25. protected function setUp(): void
  26. {
  27. parent::setUp(); // TODO: Change the autogenerated stub
  28. $config = new Config(MYSQL_CONFIG);
  29. $this->connection = new Connection($config);
  30. DbManager::getInstance()->addConnection($this->connection);
  31. $connection = DbManager::getInstance()->getConnection();
  32. $this->assertTrue($connection === $this->connection);
  33. }
  34. /**
  35. * @throws Exception
  36. * @throws \EasySwoole\Mysqli\Exception\Exception
  37. * @throws \Throwable
  38. */
  39. public function testGet()
  40. {
  41. TestTimeStampModel::create([
  42. 'name' => 'siam_test_clone',
  43. 'age' => 22,
  44. ])->save();
  45. $model = new TestRelationModel();
  46. $cloneModel = $model->tableName("tiamstamp_test")->get();
  47. $this->assertEquals($cloneModel->getTableName(), 'tiamstamp_test');
  48. }
  49. /**
  50. * @throws Exception
  51. * @throws \EasySwoole\Mysqli\Exception\Exception
  52. * @throws \Throwable
  53. */
  54. public function testSaveAll()
  55. {
  56. $model = new TestRelationModel();
  57. $model->tableName("tiamstamp_test")->saveAll([
  58. [
  59. 'name' => 'siam_test_clone_1',
  60. 'age' => 22,
  61. ],
  62. [
  63. 'name' => 'siam_test_clone_2',
  64. 'age' => 22,
  65. ]
  66. ]);
  67. $com = TestTimeStampModel::create()->get([
  68. 'name' => 'siam_test_clone_2'
  69. ]);
  70. $this->assertEquals($com->name, "siam_test_clone_2");
  71. }
  72. public function testAfter()
  73. {
  74. TestTimeStampModel::create()->destroy(null, true);
  75. }
  76. }