Skip to content

Commit 47ba098

Browse files
committed
Added support for array structures
1 parent f331387 commit 47ba098

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/JsonDbStructure.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,17 @@ final class JsonDbStructure
106106
private $generatedSql = [];
107107

108108
/**
109-
* @param $jsonStructureFile PathUtil | string
109+
* @param $jsonStructureFile PathUtil | string | Array
110110
* @param $sqlVendor string
111111
*/
112112
public function __construct($jsonStructureFile, $sqlVendor)
113113
{
114-
$this->jsonStructure = self::getObjectFromJsonFile($jsonStructureFile);
114+
if (is_array($jsonStructureFile)){
115+
$this->jsonStructure = $jsonStructureFile;
116+
}
117+
else {
118+
$this->jsonStructure = self::getObjectFromJsonFile($jsonStructureFile);
119+
}
115120
$this->sqlVendor = $sqlVendor;
116121
}
117122

tests/JsonDbStructureTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,27 @@ public function parseJsonFile($jsonFile)
1818
return $jsonDbStructure->getGeneratedSql(';');
1919
}
2020

21+
public function parseArrayInput($jsonFile)
22+
{
23+
$jsonArray = json_decode(file_get_contents($jsonFile), JSON_FORCE_OBJECT);
24+
25+
$jsonDbStructure = new Samshal\Scripd\JsonDbStructure($jsonArray, 'mysql');
26+
$jsonDbStructure->parseStructure();
27+
return $jsonDbStructure->getGeneratedSql(';');
28+
}
29+
30+
/**
31+
* @dataProvider dataProvider
32+
*/
33+
public function testStructureParserWithJsonFileInput($expected, $jsonFile)
34+
{
35+
$this->assertEquals($expected, self::parseJsonFile($jsonFile));
36+
}
37+
2138
/**
2239
* @dataProvider dataProvider
2340
*/
24-
public function testStructureParser($expected, $jsonFile)
41+
public function testStructureParserWithArrayInput($expected, $jsonFile)
2542
{
2643
$this->assertEquals($expected, self::parseJsonFile($jsonFile));
2744
}

0 commit comments

Comments
 (0)