<?php
/**
 * 空属性字段
 * User: Administrator
 * Date: 2019/10/28 0028
 * Time: 18:52
 */

namespace EasySwoole\ORM\Tests;

use EasySwoole\ORM\Db\Config;
use EasySwoole\ORM\Db\Connection;
use EasySwoole\ORM\DbManager;
use PHPUnit\Framework\TestCase;


use EasySwoole\ORM\Tests\models\TestUserListModel;

class EmptyTest 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);
    }

    public function testAdd()
    {
        $testUserModel = new TestUserListModel();
        $testUserModel->state = 1;
        $testUserModel->name = 'Siam';
        $testUserModel->age = 18;
        $testUserModel->addTime = date('Y-m-d H:i:s');
        $data = $testUserModel->save();
        $this->assertIsInt($data);
    }

    public function testEmpty()
    {
        $test = TestUserListModel::create()->where(['name' => 'Siam'])->get();
        $res = !empty($test->name);
        $resNot = !empty($test->testaaa);

        $this->assertTrue($res);
        $this->assertNotTrue($resNot);
    }

    public function testIsset()
    {
        $test = TestUserListModel::create()->where(['name' => 'Siam'])->get();
        $res = isset($test->name);
        $resNot = isset($test->testaaa);

        $this->assertTrue($res);
        $this->assertNotTrue($resNot);
    }


    public function testDeleteAll()
    {
        $res = TestUserListModel::create()->destroy(null, true);
        $this->assertIsInt($res);
    }

}