Skip to content

Commit 18e9f06

Browse files
committed
add more tests for mysql, postgres
1 parent 685d674 commit 18e9f06

5 files changed

Lines changed: 530 additions & 108 deletions

File tree

tests/cases/MySqlMultiQueryParserTest.phpt

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,27 @@ require_once __DIR__ . '/../bootstrap.php';
1717
class MySqlMultiQueryParserTest extends TestCase
1818
{
1919
/**
20-
* @dataProvider provideLoadFileData
20+
* @dataProvider provideDelimitersData
2121
*/
22-
public function testLoadFile($content, array $expectedQueries)
22+
public function testDelimiter($content, array $expectedQueries)
2323
{
2424
$parser = new MySqlMultiQueryParser();
25-
$actualQueries = iterator_to_array($parser->parseFile(FileMock::create($content)));
26-
Assert::same($expectedQueries, $actualQueries);
25+
$queries = iterator_to_array($parser->parseFile(FileMock::create($content)));
26+
Assert::same($expectedQueries, $queries);
2727
}
2828

2929

30-
protected function provideLoadFileData()
30+
public function testFile()
31+
{
32+
$parser = new MySqlMultiQueryParser();
33+
$queries = iterator_to_array($parser->parseFile(__DIR__ . '/data/mysql.sql'));
34+
Assert::count(58, $queries);
35+
}
36+
37+
38+
protected function provideDelimitersData()
3139
{
3240
return [
33-
[
34-
'SELECT 1',
35-
[
36-
'SELECT 1',
37-
],
38-
],
39-
[
40-
'SELECT 1; ',
41-
[
42-
'SELECT 1',
43-
],
44-
],
45-
[
46-
'SELECT 1; SELECT 2; SELECT 3; ',
47-
[
48-
'SELECT 1',
49-
'SELECT 2',
50-
'SELECT 3',
51-
],
52-
],
5341
[
5442
implode("\n", [
5543
'SELECT 1;',

tests/cases/PgSqlMultiQueryParserTest.phpt

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types = 1);
2+
3+
/**
4+
* @testCase
5+
*/
6+
7+
namespace Nextras\MultiQueryParser;
8+
9+
use Tester\Assert;
10+
use Tester\TestCase;
11+
12+
13+
require_once __DIR__ . '/../bootstrap.php';
14+
15+
16+
class PostgreSqlMultiQueryParserTest extends TestCase
17+
{
18+
public function testFile()
19+
{
20+
$parser = new PostgreSqlMultiQueryParser();
21+
$queries = iterator_to_array($parser->parseFile(__DIR__ . '/data/postgres.sql'));
22+
Assert::count(66, $queries);
23+
Assert::same(<<<SQL
24+
CREATE FUNCTION "book_collections_before"() RETURNS TRIGGER AS
25+
\$BODY$
26+
BEGIN
27+
NEW."updated_at" = NOW();
28+
return NEW;
29+
END;
30+
\$BODY$
31+
LANGUAGE 'plpgsql' VOLATILE
32+
SQL, $queries[16]);
33+
}
34+
}
35+
36+
37+
(new PostgreSqlMultiQueryParserTest())->run();

0 commit comments

Comments
 (0)