Skip to content

Commit

Permalink
Added support for array structures
Browse files Browse the repository at this point in the history
  • Loading branch information
Samshal committed May 4, 2016
1 parent f331387 commit 47ba098
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/JsonDbStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@ final class JsonDbStructure
private $generatedSql = [];

/**
* @param $jsonStructureFile PathUtil | string
* @param $jsonStructureFile PathUtil | string | Array
* @param $sqlVendor string
*/
public function __construct($jsonStructureFile, $sqlVendor)
{
$this->jsonStructure = self::getObjectFromJsonFile($jsonStructureFile);
if (is_array($jsonStructureFile)){
$this->jsonStructure = $jsonStructureFile;
}
else {
$this->jsonStructure = self::getObjectFromJsonFile($jsonStructureFile);
}
$this->sqlVendor = $sqlVendor;
}

Expand Down
19 changes: 18 additions & 1 deletion tests/JsonDbStructureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,27 @@ public function parseJsonFile($jsonFile)
return $jsonDbStructure->getGeneratedSql(';');
}

public function parseArrayInput($jsonFile)
{
$jsonArray = json_decode(file_get_contents($jsonFile), JSON_FORCE_OBJECT);

$jsonDbStructure = new Samshal\Scripd\JsonDbStructure($jsonArray, 'mysql');
$jsonDbStructure->parseStructure();
return $jsonDbStructure->getGeneratedSql(';');
}

/**
* @dataProvider dataProvider
*/
public function testStructureParserWithJsonFileInput($expected, $jsonFile)
{
$this->assertEquals($expected, self::parseJsonFile($jsonFile));
}

/**
* @dataProvider dataProvider
*/
public function testStructureParser($expected, $jsonFile)
public function testStructureParserWithArrayInput($expected, $jsonFile)
{
$this->assertEquals($expected, self::parseJsonFile($jsonFile));
}
Expand Down

0 comments on commit 47ba098

Please sign in to comment.