diff --git a/.travis.yml b/.travis.yml index a5c6dbd..4e85cf9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,5 @@ language: php php: - 5.6 - - 5.5 - - 5.4 - - 5.3 - - hhvm script: phpunit --coverage-text diff --git a/bootstrap.php b/bootstrap.php new file mode 100644 index 0000000..5f42aeb --- /dev/null +++ b/bootstrap.php @@ -0,0 +1,4 @@ + - + ./tests diff --git a/tests/SqlFormatterTest.php b/tests/SqlFormatterTest.php index 52e4068..8c2654c 100644 --- a/tests/SqlFormatterTest.php +++ b/tests/SqlFormatterTest.php @@ -6,7 +6,7 @@ class SqlFormatterTest extends PHPUnit_Framework_TestCase { protected $sqlData; - + /** * @dataProvider formatHighlightData */ @@ -54,43 +54,43 @@ function testCliHighlight($sql, $html) { function testCompress($sql, $html) { $this->assertEquals(trim($html), trim(SqlFormatter::compress($sql))); } - + function testUsePre() { SqlFormatter::$use_pre = false; $actual = SqlFormatter::highlight("test"); $expected = 'test'; $this->assertEquals($actual,$expected); - + SqlFormatter::$use_pre = true; $actual = SqlFormatter::highlight("test"); $expected = '
test
'; $this->assertEquals($actual,$expected); } - + function testSplitQuery() { $expected = array( "SELECT 'test' FROM MyTable;", "SELECT Column2 FROM SomeOther Table WHERE (test = true);" ); - + $actual = SqlFormatter::splitQuery(implode(';',$expected)); - + $this->assertEquals($expected, $actual); } - + function testSplitQueryEmpty() { $sql = "SELECT 1;SELECT 2;\n-- This is a comment\n;SELECT 3"; $expected = array("SELECT 1;","SELECT 2;","SELECT 3"); $actual = SqlFormatter::splitQuery($sql); - + $this->assertEquals($expected, $actual); } - + function testRemoveComments() { $expected = SqlFormatter::format("SELECT\n * FROM\n MyTable",false); $sql = "/* this is a comment */SELECT#This is another comment\n * FROM-- One final comment\n MyTable"; $actual = SqlFormatter::removeComments($sql); - + $this->assertEquals($expected, $actual); } @@ -100,16 +100,23 @@ function testRemoveOpenComments() { $this->assertEquals("", $actual); } - + + function testTrailingClosingComments() { + $sql = "SELECT 1 */"; + $actual = SqlFormatter::removeComments($sql); + + $this->assertEquals("SELECT \n 1 */", $actual); + } + function testCacheStats() { $stats = SqlFormatter::getCacheStats(); $this->assertGreaterThan(1,$stats['hits']); } - + function formatHighlightData() { $formatHighlightData = explode("\n\n",file_get_contents(__DIR__."/format-highlight.html")); $sqlData = $this->sqlData(); - + $return = array(); foreach($formatHighlightData as $i=>$data) { $return[] = array( @@ -117,14 +124,14 @@ function formatHighlightData() { $data ); } - + return $return; } - + function highlightCliData() { $clidata = explode("\n\n",file_get_contents(__DIR__."/clihighlight.html")); $sqlData = $this->sqlData(); - + $return = array(); foreach($clidata as $i=>$data) { $return[] = array( @@ -132,14 +139,14 @@ function highlightCliData() { $data ); } - + return $return; } - + function formatData() { $formatData = explode("\n\n",file_get_contents(__DIR__."/format.html")); $sqlData = $this->sqlData(); - + $return = array(); foreach($formatData as $i=>$data) { $return[] = array( @@ -147,14 +154,14 @@ function formatData() { $data ); } - + return $return; } - + function compressData() { $compressData = explode("\n\n",file_get_contents(__DIR__."/compress.html")); $sqlData = $this->sqlData(); - + $return = array(); foreach($compressData as $i=>$data) { $return[] = array( @@ -162,14 +169,14 @@ function compressData() { $data ); } - + return $return; } - + function highlightData() { $highlightData = explode("\n\n",file_get_contents(__DIR__."/highlight.html")); $sqlData = $this->sqlData(); - + $return = array(); foreach($highlightData as $i=>$data) { $return[] = array( @@ -177,43 +184,43 @@ function highlightData() { $data ); } - + return $return; } - - - + + + function sqlData() { if(!$this->sqlData) { $this->sqlData = explode("\n\n",file_get_contents(__DIR__."/sql.sql")); } - + /** $formatHighlight = array(); $highlight = array(); $format = array(); $compress = array(); $clihighlight = array(); - + foreach($this->sqlData as $sql) { $formatHighlight[] = trim(SqlFormatter::format($sql)); $highlight[] = trim(SqlFormatter::highlight($sql)); $format[] = trim(SqlFormatter::format($sql, false)); $compress[] = trim(SqlFormatter::compress($sql)); - + SqlFormatter::$cli = true; $clihighlight[] = trim(SqlFormatter::format($sql)); SqlFormatter::$cli = false; } - + file_put_contents(__DIR__."/format-highlight.html", implode("\n\n",$formatHighlight)); file_put_contents(__DIR__."/highlight.html", implode("\n\n",$highlight)); file_put_contents(__DIR__."/format.html", implode("\n\n",$format)); file_put_contents(__DIR__."/compress.html", implode("\n\n",$compress)); file_put_contents(__DIR__."/clihighlight.html", implode("\n\n",$clihighlight)); /**/ - + return $this->sqlData; } - + }