123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /**
- * 回调事件测试
- * User: Siam
- * Date: 2019/12/10
- * Time: 9:42
- */
- namespace EasySwoole\ORM\Tests;
- use EasySwoole\Mysqli\QueryBuilder;
- use EasySwoole\ORM\Db\Config;
- use EasySwoole\ORM\Db\Connection;
- use EasySwoole\ORM\DbManager;
- use EasySwoole\ORM\Exception\Exception;
- use PHPUnit\Framework\TestCase;
- use EasySwoole\ORM\Tests\models\TestUserEventModel;
- /**
- * Class ErrorTest
- * @package EasySwoole\ORM\Tests
- */
- class EventTest extends TestCase
- {
- /**
- * @var $connection Connection
- */
- protected $connection;
- protected $tableName = 'user_test_list';
- protected function setUp(): void
- {
- parent::setUp(); // TODO: Change the autogenerated stub
- $config = new Config(MYSQL_CONFIG);
- $this->connection = new Connection($config);
- DbManager::getInstance()->addConnection($this->connection);
- $connection = DbManager::getInstance()->getConnection();
- $this->assertTrue($connection === $this->connection);
- }
- /**
- * @throws Exception
- * @throws \Throwable
- */
- public function testAdd()
- {
- $testUserModel = new TestUserEventModel();
- $testUserModel->state = 1;
- $testUserModel->name = 'Siam';
- $testUserModel->age = 100;
- $testUserModel->addTime = date('Y-m-d H:i:s');
- $data = $testUserModel->save();
- $this->assertFalse($data);
- // 更改为正常插入
- TestUserEventModel::$insert = true;
- $testUserModel = new TestUserEventModel();
- $testUserModel->state = 1;
- $testUserModel->name = 'Siam';
- $testUserModel->age = 100;
- $testUserModel->addTime = date('Y-m-d H:i:s');
- $data = $testUserModel->save();
- $this->assertIsInt($data);
- }
- /**
- * @throws Exception
- * @throws \EasySwoole\Mysqli\Exception\Exception
- * @throws \Throwable
- */
- public function testUpdate()
- {
- $model = TestUserEventModel::create()->get([
- 'name' => 'Siam',
- 'age' => 100
- ]);
- $model->age = 333;
- $res = $model->update();
- $this->assertFalse($res);
- TestUserEventModel::$update = true;
- $model = TestUserEventModel::create()->get([
- 'name' => 'Siam',
- 'age' => 100
- ]);
- $model->age = 102;
- $res = $model->update();
- $this->assertTrue($res);
- }
- /**
- * @throws Exception
- * @throws \Throwable
- */
- public function testDeleteAll()
- {
- $res = TestUserEventModel::create()->destroy(null, true);
- $this->assertFalse($res);
- TestUserEventModel::$delete = true;
- $res = TestUserEventModel::create()->destroy(null, true);
- $this->assertIsInt($res);
- }
- }
|