summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2017-01-02 15:45:10 +0100
committerGitHub <noreply@github.com>2017-01-02 15:45:10 +0100
commitf7e232d1bcc2a85a5291aae029eae37452705cd2 (patch)
tree610a25fa42197b623d6bb14adab820522c0efec0 /tests
parentf3c5add790a76bedf1aa1328423c7da6701da9cb (diff)
parent88baea96a9fc46513c611212dbe9535b17b05d87 (diff)
downloadsql-parser-f7e232d1bcc2a85a5291aae029eae37452705cd2.zip
sql-parser-f7e232d1bcc2a85a5291aae029eae37452705cd2.tar.gz
sql-parser-f7e232d1bcc2a85a5291aae029eae37452705cd2.tar.bz2
Merge pull request #111 from bigfoot90/formats-merging
Handling merging formats arrays
Diffstat (limited to 'tests')
-rw-r--r--tests/Utils/FormatterTest.php214
1 files changed, 214 insertions, 0 deletions
diff --git a/tests/Utils/FormatterTest.php b/tests/Utils/FormatterTest.php
index e7c7212..1cc3b06 100644
--- a/tests/Utils/FormatterTest.php
+++ b/tests/Utils/FormatterTest.php
@@ -9,6 +9,220 @@ use SqlParser\Tests\TestCase;
class FormatTest extends TestCase
{
/**
+ * @dataProvider mergeFormats
+ */
+ public function testMergeFormats($default, $overriding, $expected)
+ {
+ $formatter = $this->getMockBuilder('SqlParser\Utils\Formatter')
+ ->disableOriginalConstructor()
+ ->setMethods(array('getDefaultOptions', 'getDefaultFormats'))
+ ->getMock();
+
+ $formatter->expects($this->once())
+ ->method('getDefaultOptions')
+ ->willReturn(array(
+ 'type' => 'text',
+ 'line_ending' => null,
+ 'clause_newline' => null,
+ 'parts_newline' => null,
+ ));
+
+ $formatter->expects($this->once())
+ ->method('getDefaultFormats')
+ ->willReturn($default);
+
+ $expectedOptions = array(
+ 'type' => 'test-type',
+ 'line_ending' => '<br>',
+ 'clause_newline' => null,
+ 'parts_newline' => 0,
+ 'formats' => $expected
+ );
+
+ $overridingOptions = array(
+ 'type' => 'test-type',
+ 'line_ending' => '<br>',
+ 'formats' => $overriding
+ );
+
+ $reflectionMethod = new \ReflectionMethod($formatter, 'getMergedOptions');
+ $reflectionMethod->setAccessible(true);
+ $this->assertEquals($expectedOptions, $reflectionMethod->invoke($formatter, $overridingOptions));
+ }
+
+ public function mergeFormats()
+ {
+ // array(default, overriding, expected)[]
+ return array(
+ 'empty formats' => array(
+ array( // default
+ array(
+ 'type' => 0,
+ 'flags' => 0,
+ ),
+ ),
+ array( // overriding
+ array(
+ ),
+ ),
+ array( // expected
+ array(
+ 'type' => 0,
+ 'flags' => 0,
+ ),
+ ),
+ ),
+ 'no flags' => array(
+ array( // default
+ array(
+ 'type' => 0,
+ 'flags' => 0,
+ 'html' => 'html',
+ 'cli' => 'cli',
+ ),
+ array(
+ 'type' => 0,
+ 'flags' => 1,
+ 'html' => 'html',
+ 'cli' => 'cli',
+ ),
+ ),
+ array( // overriding
+ array(
+ 'type' => 0,
+ 'html' => 'new html',
+ 'cli' => 'new cli',
+ )
+ ),
+ array( // expected
+ array(
+ 'type' => 0,
+ 'flags' => 0,
+ 'html' => 'new html',
+ 'cli' => 'new cli',
+ 'function' => '',
+ ),
+ array(
+ 'type' => 0,
+ 'flags' => 1,
+ 'html' => 'html',
+ 'cli' => 'cli',
+ ),
+ ),
+ ),
+ 'with flags' => array(
+ array( // default
+ array(
+ 'type' => -1,
+ 'flags' => 0,
+ 'html' => 'html',
+ 'cli' => 'cli',
+ ),
+ array(
+ 'type' => 0,
+ 'flags' => 0,
+ 'html' => 'html',
+ 'cli' => 'cli',
+ ),
+ array(
+ 'type' => 0,
+ 'flags' => 1,
+ 'html' => 'html',
+ 'cli' => 'cli',
+ ),
+ ),
+ array( // overriding
+ array(
+ 'type' => 0,
+ 'flags' => 0,
+ 'html' => 'new html',
+ 'cli' => 'new cli',
+ ),
+ ),
+ array( // expected
+ array(
+ 'type' => -1,
+ 'flags' => 0,
+ 'html' => 'html',
+ 'cli' => 'cli',
+ ),
+ array(
+ 'type' => 0,
+ 'flags' => 0,
+ 'html' => 'new html',
+ 'cli' => 'new cli',
+ 'function' => '',
+ ),
+ array(
+ 'type' => 0,
+ 'flags' => 1,
+ 'html' => 'html',
+ 'cli' => 'cli',
+ ),
+ ),
+ ),
+ 'with extra formats' => array(
+ array( // default
+ array(
+ 'type' => 0,
+ 'flags' => 0,
+ 'html' => 'html',
+ 'cli' => 'cli',
+ ),
+ ),
+ array( // overriding
+ array(
+ 'type' => 0,
+ 'flags' => 1,
+ 'html' => 'new html',
+ 'cli' => 'new cli',
+ ),
+ array(
+ 'type' => 1,
+ 'html' => 'new html',
+ 'cli' => 'new cli',
+ ),
+ array(
+ 'type' => 1,
+ 'flags' => 1,
+ 'html' => 'new html',
+ 'cli' => 'new cli',
+ ),
+ ),
+ array( // expected
+ array(
+ 'type' => 0,
+ 'flags' => 0,
+ 'html' => 'html',
+ 'cli' => 'cli',
+ ),
+ array(
+ 'type' => 0,
+ 'flags' => 1,
+ 'html' => 'new html',
+ 'cli' => 'new cli',
+ 'function' => '',
+ ),
+ array(
+ 'type' => 1,
+ 'flags' => 0,
+ 'html' => 'new html',
+ 'cli' => 'new cli',
+ 'function' => '',
+ ),
+ array(
+ 'type' => 1,
+ 'flags' => 1,
+ 'html' => 'new html',
+ 'cli' => 'new cli',
+ 'function' => '',
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
* @dataProvider formatQueries
*/
public function testFormat($query, $expected, $options)