-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
380 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
class FunctionTest extends BaseTest | ||
{ | ||
function loadSql() | ||
{} | ||
|
||
protected function getSingleFunctionSql() | ||
{ | ||
return <<<EOD | ||
DROP FUNCTION IF EXISTS `SPLIT_STR`; | ||
DELIMITER ;; | ||
CREATE DEFINER=`test`@`localhost` FUNCTION `SPLIT_STR`( | ||
x VARCHAR(500), | ||
delim VARCHAR(12), | ||
pos INT | ||
) RETURNS varchar(500) CHARSET utf8 | ||
BEGIN | ||
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), | ||
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), | ||
delim, ''); | ||
END ;; | ||
DELIMITER ; | ||
EOD; | ||
} | ||
|
||
protected function getDiffSingleFunctionSql() | ||
{ | ||
return <<<EOD | ||
DROP FUNCTION IF EXISTS `SPLIT_STR`; | ||
DELIMITER ;; | ||
CREATE DEFINER=`test`@`localhost` FUNCTION `SPLIT_STR`( | ||
x VARCHAR(500), | ||
delim VARCHAR(15), | ||
pos INT | ||
) RETURNS varchar(520) CHARSET utf8 | ||
BEGIN | ||
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), | ||
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), | ||
delim, ''); | ||
END ;; | ||
DELIMITER ; | ||
EOD; | ||
} | ||
|
||
function testHandle_newFunction_shouldGenerateAlterScript() | ||
{ | ||
$this->sourceSql = $this->getSingleFunctionSql(); | ||
|
||
$this->client->shouldReceive('dbHasFunction')->andReturnFalse(); | ||
|
||
$parser = new \Jezzis\MysqlSyncer\Parser\Parser($this->client, true); | ||
$parser->parse($this->sourceSql); | ||
$actualSql = $parser->getExecSqlList(); | ||
|
||
$sql = <<<EOD | ||
CREATE DEFINER=`test`@`localhost` FUNCTION `SPLIT_STR`( | ||
x VARCHAR(500), | ||
delim VARCHAR(12), | ||
pos INT | ||
) RETURNS varchar(500) CHARSET utf8 | ||
BEGIN | ||
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), | ||
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), | ||
delim, ''); | ||
END | ||
EOD; | ||
|
||
$this->assertEquals([$sql], $actualSql); | ||
} | ||
|
||
function testHandle_diffFunction_shouldGenerateAlterScript() | ||
{ | ||
$this->sourceSql = $this->getSingleFunctionSql(); | ||
$procedureDef = <<<EOD | ||
CREATE DEFINER=`test`@`localhost` FUNCTION `SPLIT_STR`( | ||
x VARCHAR(500), | ||
delim VARCHAR(15), | ||
pos INT | ||
) RETURNS varchar(520) CHARSET utf8 | ||
BEGIN | ||
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), | ||
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), | ||
delim, ''); | ||
END | ||
EOD; | ||
|
||
$this->client->shouldReceive('dbHasFunction')->andReturnTrue(); | ||
$this->client->shouldReceive('getDefFromDB')->andReturn($procedureDef); | ||
|
||
$parser = new \Jezzis\MysqlSyncer\Parser\Parser($this->client, true); | ||
$parser->parse($this->sourceSql); | ||
$actualSql = $parser->getExecSqlList(); | ||
|
||
$sqlList = []; | ||
$sqlList[] = "DROP FUNCTION `SPLIT_STR`;"; | ||
$sqlList[] = "CREATE DEFINER=`test`@`localhost` FUNCTION `SPLIT_STR`( | ||
x VARCHAR(500), | ||
delim VARCHAR(12), | ||
pos INT | ||
) RETURNS varchar(500) CHARSET utf8 | ||
BEGIN | ||
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), | ||
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), | ||
delim, ''); | ||
END"; | ||
|
||
$this->assertEquals($sqlList, $actualSql); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
class Procedure extends BaseTest | ||
{ | ||
function loadSql() | ||
{} | ||
|
||
protected function getSingleProcedureSql() | ||
{ | ||
return <<<EOD | ||
DROP PROCEDURE IF EXISTS `SPLIT_STR`; | ||
DELIMITER ;; | ||
CREATE DEFINER=`test`@`localhost` PROCEDURE `SPLIT_STR`( | ||
x VARCHAR(500), | ||
delim VARCHAR(12), | ||
pos INT | ||
) RETURNS varchar(500) CHARSET utf8 | ||
BEGIN | ||
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), | ||
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), | ||
delim, ''); | ||
END ;; | ||
DELIMITER ; | ||
EOD; | ||
} | ||
|
||
protected function getDiffSingleProcedureSql() | ||
{ | ||
return <<<EOD | ||
DROP PROCEDURE IF EXISTS `SPLIT_STR`; | ||
DELIMITER ;; | ||
CREATE DEFINER=`test`@`localhost` PROCEDURE `SPLIT_STR`( | ||
x VARCHAR(500), | ||
delim VARCHAR(15), | ||
pos INT | ||
) RETURNS varchar(520) CHARSET utf8 | ||
BEGIN | ||
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), | ||
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), | ||
delim, ''); | ||
END ;; | ||
DELIMITER ; | ||
EOD; | ||
} | ||
|
||
function testHandle_newProcedure_shouldGenerateAlterScript() | ||
{ | ||
$this->sourceSql = $this->getSingleProcedureSql(); | ||
|
||
$this->client->shouldReceive('dbHasProcedure')->andReturnFalse(); | ||
|
||
$parser = new \Jezzis\MysqlSyncer\Parser\Parser($this->client, true); | ||
$parser->parse($this->sourceSql); | ||
$actualSql = $parser->getExecSqlList(); | ||
|
||
$sql = <<<EOD | ||
CREATE DEFINER=`test`@`localhost` PROCEDURE `SPLIT_STR`( | ||
x VARCHAR(500), | ||
delim VARCHAR(12), | ||
pos INT | ||
) RETURNS varchar(500) CHARSET utf8 | ||
BEGIN | ||
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), | ||
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), | ||
delim, ''); | ||
END | ||
EOD; | ||
|
||
$this->assertEquals([$sql], $actualSql); | ||
} | ||
|
||
function testHandle_diffProcedure_shouldGenerateAlterScript() | ||
{ | ||
$this->sourceSql = $this->getSingleProcedureSql(); | ||
$procedureDef = <<<EOD | ||
CREATE DEFINER=`test`@`localhost` PROCEDURE `SPLIT_STR`( | ||
x VARCHAR(500), | ||
delim VARCHAR(15), | ||
pos INT | ||
) RETURNS varchar(520) CHARSET utf8 | ||
BEGIN | ||
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), | ||
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), | ||
delim, ''); | ||
END | ||
EOD; | ||
|
||
$this->client->shouldReceive('dbHasProcedure')->andReturnTrue(); | ||
$this->client->shouldReceive('getDefFromDB')->andReturn($procedureDef); | ||
|
||
$parser = new \Jezzis\MysqlSyncer\Parser\Parser($this->client, true); | ||
$parser->parse($this->sourceSql); | ||
$actualSql = $parser->getExecSqlList(); | ||
|
||
$sqlList = []; | ||
$sqlList[] = "DROP PROCEDURE `SPLIT_STR`;"; | ||
$sqlList[] = "CREATE DEFINER=`test`@`localhost` PROCEDURE `SPLIT_STR`( | ||
x VARCHAR(500), | ||
delim VARCHAR(12), | ||
pos INT | ||
) RETURNS varchar(500) CHARSET utf8 | ||
BEGIN | ||
RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos), | ||
LENGTH(SUBSTRING_INDEX(x, delim, pos -1)) + 1), | ||
delim, ''); | ||
END"; | ||
|
||
$this->assertEquals($sqlList, $actualSql); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
<?php | ||
|
||
use Mockery as m; | ||
|
||
class ColumnTest extends BaseTest | ||
{ | ||
public function loadSql() | ||
|
Oops, something went wrong.