File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments