-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.x' of https://github.com/easy-swoole/fast-db into 2.x
- Loading branch information
Showing
4 changed files
with
145 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,10 +85,20 @@ public function testTestDb() | |
} catch (\Throwable $throwable) { | ||
if (USE_MYSQLI) { | ||
$this->assertInstanceOf(\mysqli_sql_exception::class, $throwable); | ||
$this->assertSame("Access denied for user 'error'@'localhost' (using password: YES)", $throwable->getMessage()); | ||
$err = $throwable->getMessage(); | ||
if (str_contains($err, 'using password: YES')) { | ||
$this->assertSame("Access denied for user 'error'@'localhost' (using password: YES)", $err); | ||
} else { | ||
$this->assertSame("Connection refused", $err); | ||
} | ||
} else { | ||
$this->assertInstanceOf(RuntimeError::class, $throwable); | ||
$this->assertSame("SQLSTATE[28000] [1045] Access denied for user 'error'@'localhost' (using password: YES)", $throwable->getMessage()); | ||
$err = $throwable->getMessage(); | ||
if (str_contains($err, 'using password: YES')) { | ||
$this->assertSame("connection error error case initObject fail after 3 times case connection [[email protected]] connect error: SQLSTATE[28000] [1045] Access denied for user 'error'@'localhost' (using password: YES)", $err); | ||
} else { | ||
$this->assertSame("SQLSTATE[HY000] [2002] Connection refused", $err); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -216,9 +226,19 @@ public function testBegin() | |
} catch (\Throwable $throwable) { | ||
$this->assertInstanceOf(RuntimeError::class, $throwable); | ||
if (USE_MYSQLI) { | ||
$this->assertSame("connection error error case initObject fail after 3 times case Access denied for user 'error'@'localhost' (using password: YES)", $throwable->getMessage()); | ||
$err = $throwable->getMessage(); | ||
if (str_contains($err, '(using password: YES)')) { | ||
$this->assertSame("connection error error case initObject fail after 3 times case Access denied for user 'error'@'localhost' (using password: YES)", $err); | ||
} else { | ||
$this->assertSame("connection error error case initObject fail after 3 times case Connection refused", $err); | ||
} | ||
} else { | ||
$this->assertSame("connection error error case initObject fail after 3 times case connection [[email protected]] connect error: SQLSTATE[28000] [1045] Access denied for user 'error'@'localhost' (using password: YES)", $throwable->getMessage()); | ||
$err = $throwable->getMessage(); | ||
if (str_contains($err, '(using password: YES)')) { | ||
$this->assertSame("connection error error case initObject fail after 3 times case connection [[email protected]] connect error: SQLSTATE[28000] [1045] Access denied for user 'error'@'localhost' (using password: YES)", $err); | ||
} else { | ||
$this->assertSame("connection error error case initObject fail after 3 times case connection [[email protected]] connect error: SQLSTATE[HY000] [2002] Connection refused", $err); | ||
} | ||
} | ||
$errorFastDb->rollback(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* This file is part of EasySwoole. | ||
* | ||
* @link https://www.easyswoole.com | ||
* @document https://www.easyswoole.com | ||
* @contact https://www.easyswoole.com/Preface/contact.html | ||
* @license https://github.com/easy-swoole/easyswoole/blob/3.x/LICENSE | ||
*/ | ||
|
||
namespace EasySwoole\FastDb\Tests; | ||
|
||
use EasySwoole\Command\CommandManager; | ||
use EasySwoole\FastDb\Commands\GenModelAction; | ||
use EasySwoole\FastDb\Config; | ||
use EasySwoole\FastDb\FastDb; | ||
use EasySwoole\FastDb\Mysql\QueryResult; | ||
use EasySwoole\Mysqli\QueryBuilder; | ||
use EasySwoole\Spl\SplBean; | ||
|
||
final class GenModelActionTest extends BaseTestCase | ||
{ | ||
protected $tableName = 'easyswoole_user'; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$configObj = new Config(MYSQL_CONFIG); | ||
FastDb::getInstance()->addDb($configObj); | ||
FastDb::getInstance()->setOnQuery(function (QueryResult $queryResult) { | ||
// if ($queryResult->getQueryBuilder()) { | ||
// echo $queryResult->getQueryBuilder()->getLastQuery() . "\n"; | ||
// } else { | ||
// echo $queryResult->getRawSql() . "\n"; | ||
// } | ||
}); | ||
|
||
$this->createTestTable(); | ||
} | ||
|
||
private function createTestTable() | ||
{ | ||
$sql = <<<Sql | ||
CREATE TABLE IF NOT EXISTS `{$this->tableName}` | ||
( | ||
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'increment id', | ||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'name', | ||
`status` tinyint unsigned DEFAULT '0' COMMENT 'status', | ||
`score` int unsigned DEFAULT '0' COMMENT 'score', | ||
`sex` tinyint unsigned DEFAULT '0' COMMENT 'sex', | ||
`address` json DEFAULT NULL COMMENT 'address', | ||
`email` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'email', | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; | ||
Sql; | ||
$builder = new QueryBuilder(); | ||
$builder->raw($sql); | ||
FastDb::getInstance()->query($builder)->getResult(); | ||
} | ||
|
||
public function testGenModel() | ||
{ | ||
$file = __DIR__ . '/Model/EasyswooleUser.php'; | ||
@unlink($file); | ||
|
||
$commandManager = CommandManager::getInstance(); | ||
$opts = [ | ||
'table' => 'easyswoole_user', | ||
'path' => 'tests/Model', | ||
'with-comments' => '', | ||
]; | ||
$commandManager->setOpts($opts); | ||
(new GenModelAction())->run(); | ||
|
||
$this->assertFileExists($file); | ||
@unlink($file); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters