Skip to content

Commit

Permalink
修复测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
doyouhaobaby committed Sep 14, 2024
1 parent 7007bae commit d002be1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 67 deletions.
69 changes: 13 additions & 56 deletions tests/Database/Ddd/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public function testFindAll(): void
}

$repository = new Repository(new Post());
$select = $repository->condition();
$result = $repository->findAllByCondition();
$select = $repository->getEntitySelect();
$result = $repository->findAll();

$sql = <<<'eot'
SQL: [70] SELECT `post`.* FROM `post` WHERE `post`.`delete_at` = :post_delete_at | Params: 1 | Key: Name: [15] :post_delete_at | paramno=0 | name=[15] ":post_delete_at" | is_param=1 | param_type=1 (SELECT `post`.* FROM `post` WHERE `post`.`delete_at` = 0)
Expand Down Expand Up @@ -192,7 +192,7 @@ public function testFindAll2(): void
}

$repository = new Repository(new Post());
$result = $repository->findAllByCondition(static function (Select $select): void {
$result = $repository->findAll(condition: static function (Select $select): void {
$select->where('id', '<', 8);
});

Expand Down Expand Up @@ -228,8 +228,8 @@ public function testFindCount(): void
}

$repository = new Repository(new Post());
$select = $repository->condition();
$result = $repository->findCountByCondition();
$select = $repository->getEntitySelect();
$result = $repository->findCount();

$sql = <<<'eot'
SQL: [91] SELECT COUNT(*) AS row_count FROM `post` WHERE `post`.`delete_at` = :post_delete_at LIMIT 1 | Params: 1 | Key: Name: [15] :post_delete_at | paramno=0 | name=[15] ":post_delete_at" | is_param=1 | param_type=1 (SELECT COUNT(*) AS row_count FROM `post` WHERE `post`.`delete_at` = 0 LIMIT 1)
Expand Down Expand Up @@ -263,7 +263,7 @@ public function testFindCount2(): void
}

$repository = new Repository(new Post());
$result = $repository->findCountByCondition(static function (Select $select): void {
$result = $repository->findCount(condition: static function (Select $select): void {
$select->where('id', '<', 8);
});

Expand Down Expand Up @@ -768,49 +768,6 @@ public function testForceDeleteTwice(): void
self::assertNull($newPost->summary);
}

#[Api([
'zh-CN:title' => 'condition 条件查询器支持闭包',
])]
public function testConditionIsClosure(): void
{
$connect = $this->createDatabaseConnect();

for ($i = 0; $i < 10; ++$i) {
$connect
->table('post')
->insert([
'title' => 'hello world',
'user_id' => 1,
'summary' => 'post summary',
'delete_at' => 0,
])
;
}

$request = ['foo' => 'no-bar', 'hello' => 'no-world'];

$repository = new Repository(new Post());

$condition = static function (Select $select, Entity $entity): void {
$select->where('id', '<', 8);
};

$select = $repository->condition($condition);
$result = $select->findAll();

$this->assertInstanceof(Select::class, $select);
$this->assertInstanceof(Collection::class, $result);
self::assertCount(7, $result);
}

public function testConditionTypeIsInvalid(): void
{
$this->expectException(\TypeError::class);

$repository = new Repository(new Post());
$repository->condition(5);
}

#[Api([
'zh-CN:title' => 'findPage 分页查询',
])]
Expand Down Expand Up @@ -868,7 +825,7 @@ public function testFindPageWithCondition(): void
$select->where('id', '<', 8);
};

$page = $repository->findPage(1, 10, $condition);
$page = $repository->findPage(1, 10, condition: $condition);
$result = $page->getData();

$this->assertInstanceof(BasePage::class, $page);
Expand Down Expand Up @@ -934,7 +891,7 @@ public function testFindPageMacroWithCondition(): void
$select->where('id', '<', 8);
};

$page = $repository->findPageMacro(1, 10, $condition);
$page = $repository->findPageMacro(1, 10, condition: $condition);
$result = $page->getData();

$this->assertInstanceof(BasePage::class, $page);
Expand Down Expand Up @@ -1000,7 +957,7 @@ public function testFindPagePrevNextWithCondition(): void
$select->where('id', '<', 8);
};

$page = $repository->findPagePrevNext(1, 10, $condition);
$page = $repository->findPagePrevNext(1, 10, condition: $condition);
$result = $page->getData();

$this->assertInstanceof(BasePage::class, $page);
Expand Down Expand Up @@ -1030,7 +987,7 @@ public function testFindList(): void

$repository = new Repository(new Post());

$result = $repository->findList(null, 'summary', 'title');
$result = $repository->findList('summary', 'title');

self::assertIsArray($result);

Expand Down Expand Up @@ -1075,7 +1032,7 @@ public function testFindListFieldValueIsArray(): void

$repository = new Repository(new Post());

$result = $repository->findList(null, ['summary', 'title']);
$result = $repository->findList(['summary', 'title']);

self::assertIsArray($result);

Expand Down Expand Up @@ -1123,9 +1080,9 @@ public function testFindListWithCondition(): void

$repository = new Repository(new Post());

$result = $repository->findList(static function (Select $select): void {
$result = $repository->findList(['summary', 'title'], condition: static function (Select $select): void {
$select->where('id', '>', 5);
}, ['summary', 'title']);
});

self::assertIsArray($result);

Expand Down
2 changes: 1 addition & 1 deletion tests/Database/Ddd/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ public function testPreLoadPage(): void

$select = new Select($post = Post::select()->findEntity(1));
$select->eager(['user']);
$page = $select->page(1, count: 2);
$page = $select->findPageList(1, count: 2);
$sql = <<<'eot'
SQL: [63] SELECT `user`.* FROM `user` WHERE `user`.`id` IN (:user_id_in0) | Params: 1 | Key: Name: [12] :user_id_in0 | paramno=0 | name=[12] ":user_id_in0" | is_param=1 | param_type=1 (SELECT `user`.* FROM `user` WHERE `user`.`id` IN (1))
eot;
Expand Down
20 changes: 10 additions & 10 deletions tests/Database/Read/AggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testCount2(): void
}

#[Api([
'zh-CN:title' => 'findCount 查询数量指定字段和别名',
'zh-CN:title' => 'findCount 查询数量指定字段',
])]
public function testCount3(): void
{
Expand All @@ -81,7 +81,7 @@ public function testCount3(): void
$sql,
$this->varJsonSql(
$connect->table('test_query')
->findCount('*', 'row_count2'),
->findCount('*'),
$connect,
2
)
Expand Down Expand Up @@ -139,7 +139,7 @@ public function testAvg2(): void
}

#[Api([
'zh-CN:title' => 'findAvg 查询平均值指定字段和别名',
'zh-CN:title' => 'findAvg 查询平均值指定字段',
])]
public function testAvg3(): void
{
Expand All @@ -156,7 +156,7 @@ public function testAvg3(): void
$sql,
$this->varJsonSql(
$connect->table('test_query')
->findAvg('num', 'avg_value2'),
->findAvg('num'),
$connect,
2
)
Expand Down Expand Up @@ -214,7 +214,7 @@ public function testMax2(): void
}

#[Api([
'zh-CN:title' => 'findMax 查询最大值指定字段和别名',
'zh-CN:title' => 'findMax 查询最大值指定字段',
])]
public function testMax3(): void
{
Expand All @@ -231,7 +231,7 @@ public function testMax3(): void
$sql,
$this->varJsonSql(
$connect->table('test_query')
->findMax('num', 'max_value2'),
->findMax('num'),
$connect,
2
)
Expand Down Expand Up @@ -289,7 +289,7 @@ public function testMin2(): void
}

#[Api([
'zh-CN:title' => 'findMin 查询最小值指定字段和别名',
'zh-CN:title' => 'findMin 查询最小值指定字段',
])]
public function testMin3(): void
{
Expand All @@ -306,7 +306,7 @@ public function testMin3(): void
$sql,
$this->varJsonSql(
$connect->table('test_query')
->findMin('num', 'min_value2'),
->findMin('num'),
$connect,
2
)
Expand Down Expand Up @@ -364,7 +364,7 @@ public function testSum2(): void
}

#[Api([
'zh-CN:title' => 'findSum 查询合计指定字段和别名',
'zh-CN:title' => 'findSum 查询合计指定字段',
])]
public function testSum3(): void
{
Expand All @@ -381,7 +381,7 @@ public function testSum3(): void
$sql,
$this->varJsonSql(
$connect->table('test_query')
->findSum('num', 'sum_value2'),
->findSum('num'),
$connect,
2
)
Expand Down

0 comments on commit d002be1

Please sign in to comment.