diff --git a/src/Entity/Mysql/Schema.php b/src/Entity/Mysql/Schema.php index 571edbb..af0877f 100644 --- a/src/Entity/Mysql/Schema.php +++ b/src/Entity/Mysql/Schema.php @@ -27,7 +27,7 @@ class Schema extends \Swoft\Db\Entity\Schema 'number' => 'Types::NUMBER', 'decimal' => 'Types::NUMBER', 'bool' => 'Types::BOOLEAN', - 'tinyint' => 'Types::BOOLEAN', + 'tinyint' => 'Types::INT', ]; /** @@ -43,6 +43,6 @@ class Schema extends \Swoft\Db\Entity\Schema 'number' => self::TYPE_INT, 'decimal' => self::TYPE_INT, 'bool' => self::TYPE_BOOL, - 'tinyint' => self::TYPE_BOOL + 'tinyint' => self::TYPE_INT ]; } diff --git a/src/Entity/SetGetGenerator.php b/src/Entity/SetGetGenerator.php index 6097ebd..519e1ad 100644 --- a/src/Entity/SetGetGenerator.php +++ b/src/Entity/SetGetGenerator.php @@ -173,9 +173,6 @@ private function parseProperty(string $propertyStub, array $fieldInfo) $this->checkAliasProperty($aliasProperty); $formatComment = " * @var {$phpType} \${$aliasProperty} {$comment}\n"; - if (!empty($comment)) { - $formatComment = " * @var {$phpType} \${$aliasProperty}\n"; - } $this->propertyStub .= PHP_EOL . str_replace([ "{{comment}}\n", @@ -208,6 +205,7 @@ private function parseProperty(string $propertyStub, array $fieldInfo) private function parseSetter(string $setterStub, array $fieldInfo) { $property = $fieldInfo['name']; + $comment = $fieldInfo['column_comment']; $aliasProperty = $property; $this->checkAliasProperty($aliasProperty); $function = explode('_', $aliasProperty); @@ -219,11 +217,13 @@ private function parseSetter(string $setterStub, array $fieldInfo) $primaryKey = $fieldInfo['key'] === 'PRI'; $type = $this->schema->phpSchema[$fieldInfo['type']] ?? 'mixed'; $this->setterStub .= PHP_EOL . str_replace([ + '{{comment}}', '{{function}}', '{{attribute}}', '{{type}}', '{{hasReturnType}}' ], [ + $comment, $function, $aliasProperty, $type !== 'mixed' ? "{$type} " : '', @@ -241,6 +241,7 @@ private function parseSetter(string $setterStub, array $fieldInfo) private function parseGetter(string $getterStub, array $fieldInfo) { $property = $fieldInfo['name']; + $comment = $fieldInfo['column_comment']; $aliasProperty = $property; $this->checkAliasProperty($aliasProperty); $function = explode('_', $aliasProperty); @@ -253,11 +254,13 @@ private function parseGetter(string $getterStub, array $fieldInfo) $primaryKey = $fieldInfo['key'] === 'PRI'; $returnType = $this->schema->phpSchema[$fieldInfo['type']] ?? 'mixed'; $this->getterStub .= PHP_EOL . str_replace([ + '{{comment}}', '{{function}}', '{{attribute}}', '{{coReturnType}}', '{{returnType}}', ], [ + $comment, $function, $aliasProperty, $returnType, diff --git a/src/Entity/Stub/Getter.stub b/src/Entity/Stub/Getter.stub index 217b419..49ee1f4 100644 --- a/src/Entity/Stub/Getter.stub +++ b/src/Entity/Stub/Getter.stub @@ -1,6 +1,5 @@ /** - * {{function}} - * + * {{comment}} * @return {{coReturnType}} */ public function {{function}}(){{returnType}} diff --git a/src/Entity/Stub/Setter.stub b/src/Entity/Stub/Setter.stub index 1c713c0..4781d58 100644 --- a/src/Entity/Stub/Setter.stub +++ b/src/Entity/Stub/Setter.stub @@ -1,8 +1,6 @@ /** - * {{function}} - * + * {{comment}} * @param {{type}}$value - * * @return $this */ public function {{function}}({{type}}$value){{hasReturnType}} diff --git a/test/.env b/test/.env index 2084edc..6dbcea5 100644 --- a/test/.env +++ b/test/.env @@ -11,7 +11,7 @@ TEST_PROVIDER=c1 # the pool of master nodes pool DB_NAME=master2 -DB_URI=127.0.0.1:3306/test?user=root&password=123456&charset=utf8,127.0.0.1:3306/test?user=root&password=123456&charset=utf8 +DB_URI=127.0.0.1:3306/test?user=root&password=&charset=utf8,127.0.0.1:3306/test?user=root&password=&charset=utf8 DB_MIN_ACTIVE=1 DB_MAX_ACTIVE=30 DB_MAX_WAIT=10 @@ -24,7 +24,7 @@ DB_PROVIDER=consul2 # the pool of slave nodes pool DB_SLAVE_NAME=slave2 -DB_SLAVE_URI=127.0.0.1:3306/test?user=root&password=123456&charset=utf8,127.0.0.1:3306/test?user=root&password=123456&charset=utf8 +DB_SLAVE_URI=127.0.0.1:3306/test?user=root&password=&charset=utf8,127.0.0.1:3306/test?user=root&password=&charset=utf8 DB_SLAVE_MIN_ACTIVE=1 DB_SLAVE_MAX_ACTIVE=30 DB_SLAVE_MAX_WAIT=10 diff --git a/test/Cases/DbTestCase.php b/test/Cases/AbstractDbTestCase.php similarity index 76% rename from test/Cases/DbTestCase.php rename to test/Cases/AbstractDbTestCase.php index b9e9d8e..91f36d5 100644 --- a/test/Cases/DbTestCase.php +++ b/test/Cases/AbstractDbTestCase.php @@ -2,7 +2,6 @@ namespace Swoft\Db\Test\Cases; -use PHPUnit\Framework\TestCase; use Swoft\Db\EntityManager; use Swoft\Db\Pool; use Swoft\Db\QueryBuilder; @@ -12,7 +11,7 @@ /** * DbTestCache */ -class DbTestCase extends TestCase +abstract class AbstractDbTestCase extends AbstractTestCase { public function arSave(string $group = Pool::GROUP) { @@ -22,25 +21,25 @@ public function arSave(string $group = Pool::GROUP) $user->setDesc('this my desc'); $user->setAge(mt_rand(1, 100)); - $id = $user->save($group)->getResult(); + $id = $user->save($group)->getResult(); $reuslt = $id > 0; $this->assertTrue($reuslt); } /** - * @param int $id + * @param int $id * @param string $group */ public function arDelete(int $id, string $group = Pool::GROUP) { /* @var User $user */ - $user = User::findById($id, $group)->getResult(User::class); + $user = User::findById($id, $group)->getResult(User::class); $result = $user->delete($group)->getResult(); $this->assertEquals(1, $result); } /** - * @param int $id + * @param int $id * @param string $group */ public function arDeleteById(int $id, string $group = Pool::GROUP) @@ -50,7 +49,7 @@ public function arDeleteById(int $id, string $group = Pool::GROUP) } /** - * @param array $ids + * @param array $ids * @param string $group */ public function arDeleteByIds(array $ids, string $group = Pool::GROUP) @@ -60,7 +59,7 @@ public function arDeleteByIds(array $ids, string $group = Pool::GROUP) } /** - * @param int $id + * @param int $id * @param string $group */ public function arUpdate(int $id, string $group = Pool::GROUP) @@ -78,7 +77,7 @@ public function arUpdate(int $id, string $group = Pool::GROUP) } /** - * @param int $id + * @param int $id * @param string $group */ public function arFindById(int $id, string $group = Pool::GROUP) @@ -88,7 +87,7 @@ public function arFindById(int $id, string $group = Pool::GROUP) } /** - * @param int $id + * @param int $id * @param string $group */ public function arFindByIdClass(int $id, string $group = Pool::GROUP) @@ -99,7 +98,7 @@ public function arFindByIdClass(int $id, string $group = Pool::GROUP) } /** - * @param array $ids + * @param array $ids * @param string $group */ public function arFindByIds(array $ids, string $group = Pool::GROUP) @@ -131,7 +130,12 @@ public function arFindByIdsByClass(array $ids, string $group = Pool::GROUP) public function arQuery(array $ids, string $group = Pool::GROUP) { - $result = User::query($group)->select('*')->orderBy('id', QueryBuilder::ORDER_BY_DESC)->limit(2)->execute()->getResult(); + $result = User::query($group) + ->select('*') + ->orderBy('id', QueryBuilder::ORDER_BY_DESC) + ->limit(2) + ->execute() + ->getResult(); $this->assertCount(2, $result); } @@ -152,14 +156,14 @@ public function emSave(string $group = Pool::GROUP) } /** - * @param int $id + * @param int $id * @param string $group */ public function emDelete(int $id, string $group = Pool::GROUP) { /* @var User $user */ - $user = User::findById($id, $group)->getResult(User::class); + $user = User::findById($id, $group)->getResult(User::class); $em = EntityManager::create($group); $result = $em->delete($user)->getResult(); $em->close(); @@ -168,7 +172,7 @@ public function emDelete(int $id, string $group = Pool::GROUP) } /** - * @param int $id + * @param int $id * @param string $group */ public function emDeleteById(int $id, string $group = Pool::GROUP) @@ -181,7 +185,7 @@ public function emDeleteById(int $id, string $group = Pool::GROUP) } /** - * @param array $ids + * @param array $ids * @param string $group */ public function emDeleteByIds(array $ids, string $group = Pool::GROUP) @@ -194,7 +198,7 @@ public function emDeleteByIds(array $ids, string $group = Pool::GROUP) } /** - * @param int $id + * @param int $id * @param string $group */ public function emUpdate(int $id, string $group = Pool::GROUP) @@ -229,7 +233,7 @@ public function emFindById(int $id, string $group = Pool::GROUP) } /** - * @param array $ids + * @param array $ids * @param string $group */ public function emFindByIds(array $ids, string $group = Pool::GROUP) @@ -249,62 +253,75 @@ public function emFindByIds(array $ids, string $group = Pool::GROUP) public function emQuery(array $ids, string $group = Pool::GROUP) { $em = EntityManager::create($group); - $result = $em->createQuery()->select('*')->from(User::class)->orderBy('id', QueryBuilder::ORDER_BY_DESC)->limit(2)->execute()->getResult(); + $result = $em->createQuery() + ->select('*') + ->from(User::class) + ->orderBy('id', QueryBuilder::ORDER_BY_DESC) + ->limit(2) + ->execute() + ->getResult(); $em->close(); $this->assertCount(2, $result); } - public function emSql(array $ids, string $group = Pool::GROUP){ + public function emSql(array $ids, string $group = Pool::GROUP) + { $em = EntityManager::create($group); $result = $em->createQuery('select * from user where id in(?, ?) and name = ? order by id desc limit 2') - ->setParameter(0, $ids[0]) - ->setParameter(1, $ids[1]) - ->setParameter(2, 'stelin') - ->execute()->getResult(); + ->setParameter(0, $ids[0]) + ->setParameter(1, $ids[1]) + ->setParameter(2, 'stelin') + ->execute() + ->getResult(); $em->close(); $em = EntityManager::create($group); $result2 = $em->createQuery('select * from user where id in(?, ?) and name = ? order by id desc limit 2') - ->setParameter(0, $ids[0]) - ->setParameter(1, $ids[1]) - ->setParameter(2, 'stelin', Types::STRING) - ->execute()->getResult(); + ->setParameter(0, $ids[0]) + ->setParameter(1, $ids[1]) + ->setParameter(2, 'stelin', Types::STRING) + ->execute() + ->getResult(); $em->close(); $em = EntityManager::create($group); $result3 = $em->createQuery('select * from user where id in(?, ?) and name = ? order by id desc limit 2') - ->setParameters([$ids[0], $ids[1], 'stelin']) - ->execute()->getResult(); + ->setParameters([$ids[0], $ids[1], 'stelin']) + ->execute() + ->getResult(); $em->close(); $em = EntityManager::create($group); $result4 = $em->createQuery('select * from user where id in(:id1, :id2) and name = :name order by id desc limit 2') - ->setParameter(':id1', $ids[0]) - ->setParameter('id2', $ids[1]) - ->setParameter('name', 'stelin') - ->execute()->getResult(); + ->setParameter(':id1', $ids[0]) + ->setParameter('id2', $ids[1]) + ->setParameter('name', 'stelin') + ->execute() + ->getResult(); $em->close(); $em = EntityManager::create($group); $result5 = $em->createQuery('select * from user where id in(:id1, :id2) and name = :name order by id desc limit 2') - ->setParameters([ - 'id1' => $ids[0], - ':id2' => $ids[1], - 'name' => 'stelin' - ]) - ->execute()->getResult(); + ->setParameters([ + 'id1' => $ids[0], + ':id2' => $ids[1], + 'name' => 'stelin' + ]) + ->execute() + ->getResult(); $em->close(); $em = EntityManager::create($group); $result6 = $em->createQuery('select * from user where id in(:id1, :id2) and name = :name order by id desc limit 2') - ->setParameters([ - ['id1', $ids[0]], - [':id2', $ids[1], Types::INT], - ['name', 'stelin', Types::STRING], - ]) - ->execute()->getResult(); + ->setParameters([ + ['id1', $ids[0]], + [':id2', $ids[1], Types::INT], + ['name', 'stelin', Types::STRING], + ]) + ->execute() + ->getResult(); $em->close(); $this->assertCount(2, $result); @@ -322,7 +339,7 @@ public function addUsers(string $group = Pool::GROUP) $user->setSex(1); $user->setDesc('this my desc'); $user->setAge(mt_rand(1, 100)); - $id = $user->save($group)->getResult(); + $id = $user->save($group)->getResult(); $id2 = $user->save($group)->getResult(); return [ diff --git a/test/Cases/AbstractTestCase.php b/test/Cases/AbstractTestCase.php new file mode 100644 index 0000000..31c4aa6 --- /dev/null +++ b/test/Cases/AbstractTestCase.php @@ -0,0 +1,20 @@ +attr(); }); } @@ -60,7 +58,7 @@ public function attr() 'desc' => 'this is my desc2', 'age' => 99, ]; - $user = new User(); + $user = new User(); $user->fill($attrs); $result = $user->save()->getResult(); @@ -75,7 +73,6 @@ public function attr() /** * @dataProvider mysqlProvider - * * @param int $id */ public function testModelSelect(int $id) @@ -85,12 +82,11 @@ public function testModelSelect(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testModelCoSelect(int $id) { - go(function () use ($id){ + go(function () use ($id) { $this->modelSelect($id); }); } @@ -103,7 +99,6 @@ public function modelSelect($id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testModelDelete(int $id) @@ -113,12 +108,11 @@ public function testModelDelete(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testModelCoDelete(int $id) { - go(function () use ($id){ + go(function () use ($id) { $this->modelDelete($id); }); } @@ -135,7 +129,6 @@ public function modelDelete(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testModelUpdate(int $id) @@ -145,12 +138,11 @@ public function testModelUpdate(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testModelCoUpdate(int $id) { - go(function () use ($id){ + go(function () use ($id) { $this->modelUpdate($id); }); } @@ -158,16 +150,16 @@ public function testModelCoUpdate(int $id) public function modelUpdate(int $id) { $data = [ - 'name' => 'stelin7872', - 'sex' => 18, + 'name' => 'stelin7872', + 'sex' => 18, 'description' => 'descc', - 'age' => 100, + 'age' => 100, ]; $result = User::query()->update()->set($data)->where('id', $id)->execute()->getResult(); $this->assertEquals(1, $result); - /* @var User $user*/ + /* @var User $user */ $user = User::findById($id)->getResult(User::class); $this->assertEquals($user->getName(), 'stelin7872'); $this->assertEquals($user->getSex(), 18); @@ -186,7 +178,7 @@ public function testModelInsert() */ public function testModelCoInsert() { - go(function (){ + go(function () { $this->modelInsert(); }); } @@ -196,16 +188,16 @@ public function testModelCoInsert() public function modelInsert() { $data = [ - 'name' => 'stelin666', - 'sex' => 19, + 'name' => 'stelin666', + 'sex' => 19, 'description' => '1212', - 'age' => 100, + 'age' => 100, ]; $id = User::query()->insert()->set($data)->execute()->getResult(); $this->assertFalse(empty($id)); - /* @var User $user*/ + /* @var User $user */ $user = User::findById($id)->getResult(User::class); $this->assertEquals($user->getName(), 'stelin666'); $this->assertEquals($user->getSex(), 19); diff --git a/test/Cases/MysqlArTest.php b/test/Cases/MysqlArTest.php index 82260bd..1fa1b1e 100644 --- a/test/Cases/MysqlArTest.php +++ b/test/Cases/MysqlArTest.php @@ -5,7 +5,7 @@ /** * SyncMysqlArTest */ -class MysqlArTest extends DbTestCase +class MysqlArTest extends AbstractDbTestCase { public function testSave() { @@ -21,7 +21,6 @@ public function testCoSave() /** * @dataProvider mysqlProvider - * * @param int $id */ public function testDelete(int $id) @@ -31,7 +30,6 @@ public function testDelete(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoDelete(int $id) @@ -43,7 +41,6 @@ public function testCoDelete(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testDeleteById(int $id) @@ -53,7 +50,6 @@ public function testDeleteById(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoDeleteById(int $id) @@ -65,7 +61,6 @@ public function testCoDeleteById(int $id) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testDeleteByIds(array $ids) @@ -75,7 +70,6 @@ public function testDeleteByIds(array $ids) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testCoDeleteByIds(array $ids) @@ -87,7 +81,6 @@ public function testCoDeleteByIds(array $ids) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testUpdate(int $id) @@ -97,7 +90,6 @@ public function testUpdate(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoUpdate(int $id) @@ -109,7 +101,6 @@ public function testCoUpdate(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testFindById(int $id) @@ -119,7 +110,6 @@ public function testFindById(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoFindById(int $id) @@ -131,7 +121,6 @@ public function testCoFindById(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testFindByIdClass(int $id) @@ -142,7 +131,6 @@ public function testFindByIdClass(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoFindByIdClass(int $id) @@ -154,7 +142,6 @@ public function testCoFindByIdClass(int $id) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testFindByIds(array $ids) @@ -164,7 +151,6 @@ public function testFindByIds(array $ids) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testCoFindByIds(array $ids) @@ -176,7 +162,6 @@ public function testCoFindByIds(array $ids) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testFindByIdsByClass(array $ids) @@ -186,7 +171,6 @@ public function testFindByIdsByClass(array $ids) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testCoFindByIdsByClass(array $ids) @@ -198,7 +182,6 @@ public function testCoFindByIdsByClass(array $ids) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testQuery(array $ids) @@ -208,7 +191,6 @@ public function testQuery(array $ids) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testCoQuery(array $ids) diff --git a/test/Cases/MysqlEmTest.php b/test/Cases/MysqlEmTest.php index 77d4783..71ce2ae 100644 --- a/test/Cases/MysqlEmTest.php +++ b/test/Cases/MysqlEmTest.php @@ -5,7 +5,7 @@ /** * SyncMysqlEmTest */ -class MysqlEmTest extends DbTestCase +class MysqlEmTest extends AbstractDbTestCase { public function testSave() { @@ -21,7 +21,6 @@ public function testCoSave() /** * @dataProvider mysqlProvider - * * @param int $id */ public function testDelete(int $id) @@ -31,7 +30,6 @@ public function testDelete(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoDelete(int $id) @@ -43,7 +41,6 @@ public function testCoDelete(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testDeleteById(int $id) @@ -53,7 +50,6 @@ public function testDeleteById(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoDeleteById(int $id) @@ -65,7 +61,6 @@ public function testCoDeleteById(int $id) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testDeleteByIds(array $ids) @@ -75,7 +70,6 @@ public function testDeleteByIds(array $ids) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testCoDeleteByIds(array $ids) @@ -87,7 +81,6 @@ public function testCoDeleteByIds(array $ids) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testUpdate(int $id) @@ -97,7 +90,6 @@ public function testUpdate(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoUpdate(int $id) @@ -109,7 +101,6 @@ public function testCoUpdate(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testFindById(int $id) @@ -119,7 +110,6 @@ public function testFindById(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoFindById(int $id) @@ -131,7 +121,6 @@ public function testCoFindById(int $id) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testFindByIds(array $ids) @@ -141,7 +130,6 @@ public function testFindByIds(array $ids) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testCoFindByIds(array $ids) @@ -153,7 +141,6 @@ public function testCoFindByIds(array $ids) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testQuery(array $ids) @@ -163,7 +150,6 @@ public function testQuery(array $ids) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testSql(array $ids) @@ -173,19 +159,17 @@ public function testSql(array $ids) /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testCoSql(array $ids) { - go(function () use ($ids){ + go(function () use ($ids) { $this->emSql($ids); }); } /** * @dataProvider mysqlProviders - * * @param array $ids */ public function testCoQuery(array $ids) diff --git a/test/Cases/PoolTest.php b/test/Cases/PoolTest.php index 8e25711..bbe84ce 100644 --- a/test/Cases/PoolTest.php +++ b/test/Cases/PoolTest.php @@ -2,7 +2,6 @@ namespace Swoft\Db\Test\Cases; -use PHPUnit\Framework\TestCase; use Swoft\App; use Swoft\Db\Test\Testing\Pool\DbEnvPoolConfig; use Swoft\Db\Test\Testing\Pool\DbPptPoolConfig; @@ -12,7 +11,7 @@ /** * PoolTest */ -class PoolTest extends TestCase +class PoolTest extends AbstractTestCase { public function testDbPpt() { @@ -40,8 +39,8 @@ public function testDbEnv() $this->assertEquals($pConfig->getProvider(), 'consul2'); $this->assertEquals($pConfig->getTimeout(), 2); $this->assertEquals($pConfig->getUri(), [ - '127.0.0.1:3306/test?user=root&password=123456&charset=utf8', - '127.0.0.1:3306/test?user=root&password=123456&charset=utf8', + '127.0.0.1:3306/test?user=root&password=&charset=utf8', + '127.0.0.1:3306/test?user=root&password=&charset=utf8', ]); $this->assertEquals($pConfig->getBalancer(), 'random'); $this->assertEquals($pConfig->getMaxActive(), 30); @@ -75,8 +74,8 @@ public function testDbSlaveEnv() $this->assertEquals($pConfig->getProvider(), 'consul2'); $this->assertEquals($pConfig->getTimeout(), 3); $this->assertEquals($pConfig->getUri(), [ - '127.0.0.1:3306/test?user=root&password=123456&charset=utf8', - '127.0.0.1:3306/test?user=root&password=123456&charset=utf8', + '127.0.0.1:3306/test?user=root&password=&charset=utf8', + '127.0.0.1:3306/test?user=root&password=&charset=utf8', ]); $this->assertEquals($pConfig->getBalancer(), 'random'); $this->assertEquals($pConfig->getMaxActive(), 30); diff --git a/test/Cases/SqlMysqlTest.php b/test/Cases/SqlMysqlTest.php index 52c3a71..8e7ea38 100644 --- a/test/Cases/SqlMysqlTest.php +++ b/test/Cases/SqlMysqlTest.php @@ -8,11 +8,10 @@ /** * SqlMysqlTest */ -class SqlMysqlTest extends DbTestCase +class SqlMysqlTest extends AbstractDbTestCase { /** * @dataProvider mysqlProvider - * * @param int $id */ public function testUpdate(int $id) @@ -22,7 +21,6 @@ public function testUpdate(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testDelete(int $id) @@ -32,7 +30,6 @@ public function testDelete(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoDelete(int $id) @@ -46,7 +43,6 @@ public function testCoDelete(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoUpdate(int $id) @@ -58,7 +54,6 @@ public function testCoUpdate(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testSelect(int $id) @@ -68,7 +63,6 @@ public function testSelect(int $id) /** * @dataProvider mysqlProvider - * * @param int $id */ public function testCoSelect(int $id) @@ -92,14 +86,18 @@ public function testCoInsert() private function insert() { - $name = "swoft insert"; - $result = Db::query('insert into user(name, sex,description, age) values("' . $name . '", 1, "xxxx", 99)')->execute()->getResult(); - $user = User::findById($result)->getResult(); + $name = "swoft insert"; + $result = Db::query('insert into user(name, sex,description, age) values("' . $name . '", 1, "xxxx", 99)') + ->execute() + ->getResult(); + $user = User::findById($result)->getResult(); $this->assertEquals($user['name'], $name); - $result = Db::query('INSERT into user(name, sex,description, age) values("' . $name . '", 1, "xxxx", 99)')->execute()->getResult(); - $user = User::findById($result)->getResult(); + $result = Db::query('INSERT into user(name, sex,description, age) values("' . $name . '", 1, "xxxx", 99)') + ->execute() + ->getResult(); + $user = User::findById($result)->getResult(); $this->assertEquals($user['name'], $name); } @@ -120,11 +118,11 @@ private function delete($id) private function update($id) { - $name = 'update name1'; + $name = 'update name1'; $result = Db::query('update user set name="' . $name . '" where id=' . $id)->execute()->getResult(); $this->assertEquals(1, $result); - $name = 'update name 协程框架'; + $name = 'update name 协程框架'; $result = Db::query('UPDATE user set name="' . $name . '" where id=' . $id)->execute()->getResult(); $this->assertEquals(1, $result); diff --git a/test/Cases/TsTest.php b/test/Cases/TsTest.php index 3297157..d73bd6a 100644 --- a/test/Cases/TsTest.php +++ b/test/Cases/TsTest.php @@ -6,7 +6,7 @@ use Swoft\Db\EntityManager; use Swoft\Db\Test\Testing\Entity\User; -class TsTest extends DbTestCase +class TsTest extends AbstractDbTestCase { public function testTsRollback() { @@ -26,7 +26,7 @@ public function rollback() $em = EntityManager::create(); $em->beginTransaction(); - $uid = $em->save($user)->getResult(); + $uid = $em->save($user)->getResult(); $uid2 = $user->save()->getResult(); $em->rollback(); @@ -58,7 +58,7 @@ public function commit() $em = EntityManager::create(); $em->beginTransaction(); - $uid = $em->save($user)->getResult(); + $uid = $em->save($user)->getResult(); $uid2 = $user->save()->getResult(); $em->commit(); @@ -74,13 +74,13 @@ public function commit() /** * @dataProvider mysqlProviders - * * @param array $ids */ - public function testDbBuilder(array $ids){ + public function testDbBuilder(array $ids) + { $this->builder(); - go(function (){ + go(function () { $this->builder(); }); } @@ -96,14 +96,22 @@ public function builder() $result = Db::query('select * from user order by id desc limit 2')->execute()->getResult(); $result2 = Db::query('select * from user order by id desc limit 2')->execute()->getResult(User::class); - $result3 = Db::query()->select('*')->from(User::class)->where('name', 'stelin')->orderBy('id', 'DESC')->limit(1)->execute()->getResult(); - $result4 = Db::query()->select('*') - ->from(User::class) - ->where('name', 'stelin') - ->orderBy('id', 'DESC') - ->limit(1) - ->execute() - ->getResult(User::class); + $result3 = Db::query() + ->select('*') + ->from(User::class) + ->where('name', 'stelin') + ->orderBy('id', 'DESC') + ->limit(1) + ->execute() + ->getResult(); + $result4 = Db::query() + ->select('*') + ->from(User::class) + ->where('name', 'stelin') + ->orderBy('id', 'DESC') + ->limit(1) + ->execute() + ->getResult(User::class); $this->assertCount(2, $result); $this->assertCount(2, $result2);