5
5
use PHPUnit \Framework \TestCase ;
6
6
use suql \db \Container ;
7
7
use suql \syntax \Query ;
8
+ use test \suql \models \buffers \Buffer ;
9
+ use test \suql \models \Query10 ;
8
10
use test \suql \models \Query18 ;
9
11
10
12
final class SqliteTest extends TestCase
@@ -15,6 +17,8 @@ public function setUp(): void
15
17
Container::create (require ('config/db-null.php ' ));
16
18
Query::create ('create database db_test ' )->setConnection ('connection ' )->exec ();
17
19
Container::add (require ('config/db.php ' ));
20
+ Query::create ('create table table_10(f1 int, f2 int) ' )->setConnection ('db_test ' )->exec ();
21
+ Query::create ('insert into table_10 (f1, f2) values (1, 1), (2, 2) ' )->setConnection ('db_test ' )->exec ();
18
22
}
19
23
20
24
public function tearDown (): void
@@ -25,22 +29,35 @@ public function tearDown(): void
25
29
26
30
public function testRealSqliteDb (): void
27
31
{
28
- $ tmp = Query18::all ()
32
+ $ expected = [
33
+ ['af1 ' => '1 ' , 'af2 ' => '1 ' ],
34
+ ['af1 ' => '2 ' , 'af2 ' => '2 ' ],
35
+ ['af1 ' => '3 ' , 'af2 ' => '3 ' ],
36
+ ];
37
+ $ actual = Query18::all ()
29
38
->select ([
30
39
'f1 ' => 'af1 ' ,
31
40
'f2 ' => 'af2 ' ,
32
41
])
33
42
->fetchAll ();
34
- $ this ->assertEquals ([
35
- ['af1 ' => '1 ' , 'af2 ' => '1 ' ],
36
- ['af1 ' => '2 ' , 'af2 ' => '2 ' ],
37
- ['af1 ' => '3 ' , 'af2 ' => '3 ' ],
38
- ], $ tmp );
43
+
44
+ $ this ->assertEquals ($ expected , $ actual );
39
45
}
40
46
41
47
public function testMixDifferentDatabases (): void
42
48
{
43
- // TODO: Написать этот тест - использование вместе Sqlite и MySql
44
- $ this ->assertTrue (true );
49
+ $ expected = [
50
+ ['f1 ' => '1 ' ],
51
+ ['f1 ' => '2 ' ],
52
+ ];
53
+
54
+ Buffer::load (
55
+ Query18::all ()
56
+ ->select (['f1 ' , 'f2 ' ])
57
+ ->fetchAll ()
58
+ );
59
+ $ actual = Buffer::all ()->join (Query10::class)->select (['f1 ' ])->fetchAll ();
60
+
61
+ $ this ->assertSame ($ expected , $ actual );
45
62
}
46
63
}
0 commit comments