Skip to content

Commit ead2248

Browse files
author
arutyunyan
committed
add macros tests
1 parent ce59a10 commit ead2248

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

tests/suql/MacrosTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use PHPUnit\Framework\TestCase;
6+
use sagittaracc\StringHelper;
7+
use test\suql\models\Query30;
8+
9+
final class MacrosTest extends TestCase
10+
{
11+
/**
12+
* Example:
13+
*
14+
* select
15+
* table.f1,
16+
* table.f2
17+
* from table
18+
*
19+
*/
20+
public function testSelectFieldList(): void
21+
{
22+
$expected = StringHelper::trimSql(require('queries/mysql/q42.php'));
23+
$actual = Query30::all()->macros1('param1')->getRawSql();
24+
$this->assertEquals($expected, $actual);
25+
}
26+
}

tests/suql/macros/macros1.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
return [
4+
'param1' => function ($query) {
5+
$query->select(['f1', 'f2']);
6+
},
7+
];

tests/suql/models/Query30.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace test\suql\models;
4+
5+
use suql\builder\MySQLBuilder;
6+
use suql\syntax\entity\SuQLTable;
7+
use test\suql\schema\AppScheme;
8+
9+
# [Table(name="table_30")]
10+
class Query30 extends SuQLTable
11+
{
12+
protected static $schemeClass = AppScheme::class;
13+
protected static $builderClass = MySQLBuilder::class;
14+
15+
protected $useMacros = true;
16+
protected $macrosPath = 'tests/suql/macros';
17+
}

tests/suql/queries/mysql/q42.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
return <<<SQL
3+
select
4+
`table_30`.`f1`,
5+
`table_30`.`f2`
6+
from `table_30`
7+
SQL;

0 commit comments

Comments
 (0)