Skip to content

Commit

Permalink
修复测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
doyouhaobaby committed Feb 17, 2023
1 parent 4dfc18f commit 464f1cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
10 changes: 5 additions & 5 deletions app/Infra/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public function sum(string $field = '*'): string|int|float
/**
* 获取一条记录的某个字段值.
*/
public function getField(string $field, null|string|bool|int $separator = null): string|array|int|float
public function getField(string $field, null|string|bool|int $separator = null): string|array|int|float|null
{
$options['field'] = $field;
$options = $this->_parseOptions($options);
Expand Down Expand Up @@ -418,17 +418,17 @@ public function getDbFields(): array|false
return false;
}

public function min(string $field = '*'): string|int|float
public function min(string $field = '*'): string|int|float|null
{
return $this->callStatisticalQuery('min', $field);
}

public function max(string $field = '*'): string|int|float
public function max(string $field = '*'): string|int|float|null
{
return $this->callStatisticalQuery('max', $field);
}

public function avg(string $field = '*'): string|int|float
public function avg(string $field = '*'): string|int|float|null
{
return $this->callStatisticalQuery('avg', $field);
}
Expand Down Expand Up @@ -1415,7 +1415,7 @@ protected function _checkTableInfo(): void
}
}

protected function callStatisticalQuery(string $method, string $field): string|int|float
protected function callStatisticalQuery(string $method, string $field): string|int|float|null
{
try {
$this->shouldCountSelect = true;
Expand Down
25 changes: 13 additions & 12 deletions app/Infra/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ public function testQuerySub29(): void
$result = trim($baseBrandModel->getLastSql());
$sql = 'SELECT MAX(brand_id) AS max FROM `base_brand` LIMIT 1';
static::assertSame($result, $sql);
static::assertIsInt($count);
static::assertTrue(null === $count || \is_int($count));
}

public function testQuerySub30(): void
Expand All @@ -657,7 +657,7 @@ public function testQuerySub30(): void
$result = trim($baseBrandModel->getLastSql());
$sql = 'SELECT MIN(brand_id) AS min FROM `base_brand` WHERE ( brand_id>0 ) LIMIT 1';
static::assertSame($result, $sql);
static::assertIsInt($count);
static::assertTrue(null === $count || \is_int($count));
}

public function testQuerySub31(): void
Expand Down Expand Up @@ -1282,11 +1282,12 @@ public function testQuerySub74(): void
$baseBrandModel = BaseBrandModel::make();
$baseBrandModel
->field('SUM(brand_id),`brand_name`,`brand_logo` as logo')
->group('brand_id')
->select()
;
$result = $baseBrandModel->getLastSql();
$result = trim($baseBrandModel->getLastSql());
$sql = 'SELECT SUM(brand_id),`brand_name`,`brand_logo` as logo FROM `base_brand`';
$sql = 'SELECT SUM(brand_id),`brand_name`,`brand_logo` as logo FROM `base_brand` GROUP BY brand_id';
static::assertSame($result, $sql);
}

Expand Down Expand Up @@ -1626,13 +1627,13 @@ public function testQuerySub97(): void
$baseBrandModel = BaseBrandModel::make();
$baseBrandModel
->where('status>1')
->field('brand_name,max(brand_id)')
->group('brand_logo')
->field('brand_logo,brand_name,max(brand_id)')
->group('brand_logo,brand_name')
->select()
;
$result = $baseBrandModel->getLastSql();
$result = trim($baseBrandModel->getLastSql());
$sql = 'SELECT `brand_name`,max(brand_id) FROM `base_brand` WHERE ( status>1 ) GROUP BY brand_logo';
$sql = 'SELECT `brand_logo`,`brand_name`,max(brand_id) FROM `base_brand` WHERE ( status>1 ) GROUP BY brand_logo,brand_name';
static::assertSame($result, $sql);
}

Expand All @@ -1641,13 +1642,13 @@ public function testQuerySub98(): void
$baseBrandModel = BaseBrandModel::make();
$baseBrandModel
->where('status>1')
->field('`brand_name`,max(brand_id)')
->group('`brand_logo`,status')
->field('brand_logo,status,max(brand_id)')
->group('brand_logo,status')
->select()
;
$result = $baseBrandModel->getLastSql();
$result = trim($baseBrandModel->getLastSql());
$sql = 'SELECT `brand_name`,max(brand_id) FROM `base_brand` WHERE ( status>1 ) GROUP BY `brand_logo`,status';
$sql = 'SELECT `brand_logo`,`status`,max(brand_id) FROM `base_brand` WHERE ( status>1 ) GROUP BY brand_logo,status';
static::assertSame($result, $sql);
}

Expand All @@ -1656,14 +1657,14 @@ public function testQuerySub99(): void
$baseBrandModel = BaseBrandModel::make();
$baseBrandModel
->where('status>1')
->field('`brand_name`,max(brand_id)')
->group('`brand_logo`,status')
->field('brand_logo,status,max(brand_id)')
->group('brand_logo,status')
->having('count(status)>3')
->select()
;
$result = $baseBrandModel->getLastSql();
$result = trim($baseBrandModel->getLastSql());
$sql = 'SELECT `brand_name`,max(brand_id) FROM `base_brand` WHERE ( status>1 ) GROUP BY `brand_logo`,status HAVING count(status)>3';
$sql = 'SELECT `brand_logo`,`status`,max(brand_id) FROM `base_brand` WHERE ( status>1 ) GROUP BY brand_logo,status HAVING count(status)>3';
static::assertSame($result, $sql);
}

Expand Down
6 changes: 3 additions & 3 deletions assets/database/migrations/20230217145516_base_brand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ private function struct(): void
$sql = <<<'EOT'
CREATE TABLE `base_brand` (
`brand_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`company_id` bigint(20) unsigned NOT NULL COMMENT '公司ID',
`company_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '公司ID',
`status` enum('T','F') NOT NULL DEFAULT 'T' COMMENT '状态',
`order_num` bigint(20) unsigned NOT NULL DEFAULT '500' COMMENT '排序',
`brand_num` varchar(30) NOT NULL DEFAULT '' COMMENT '编号',
`brand_name` varchar(30) NOT NULL DEFAULT '' COMMENT '名称',
`brand_logo` varchar(130) NOT NULL DEFAULT '' COMMENT 'LOGO',
`brand_about` text NOT NULL COMMENT '介绍',
`brand_about` text COMMENT '介绍',
`update_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`create_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`brand_letter` varchar(30) NOT NULL DEFAULT '' COMMENT '品牌首字母',
`seo_keywords` varchar(30) NOT NULL COMMENT 'SEO关键字',
`seo_keywords` varchar(30) NOT NULL DEFAULT '' COMMENT 'SEO关键字',
PRIMARY KEY (`brand_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
EOT;
Expand Down

0 comments on commit 464f1cc

Please sign in to comment.