summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Lexer/LexerTest.php18
-rw-r--r--tests/Parser/ParserTest.php22
-rw-r--r--tests/bootstrap.php13
3 files changed, 51 insertions, 2 deletions
diff --git a/tests/Lexer/LexerTest.php b/tests/Lexer/LexerTest.php
index 1a7c5f5..8a7798c 100644
--- a/tests/Lexer/LexerTest.php
+++ b/tests/Lexer/LexerTest.php
@@ -31,6 +31,24 @@ class LexerTest extends TestCase
}
/**
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function testErrorTranslate()
+ {
+ define('TRANSLATE', '\\SqlParser\\Tests\\translate');
+
+ $lexer = new Lexer('');
+
+ $lexer->error('TO_TRANSLATE', null);
+
+ $this->assertEquals(
+ $lexer->errors,
+ array(new LexerException('***', null, 0))
+ );
+ }
+
+ /**
* @expectedException SqlParser\Exceptions\LexerException
* @expectedExceptionMessage strict error
* @expectedExceptionCode 4
diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php
index 82052a2..1cd5e2d 100644
--- a/tests/Parser/ParserTest.php
+++ b/tests/Parser/ParserTest.php
@@ -49,13 +49,31 @@ class ParserTest extends TestCase
$this->assertEquals(
$parser->errors,
array(
- new ParserException('error #1', new Token('foo'), 1),
- new ParserException('error #2', new Token('bar'), 2),
+ new ParserException('error #1', new Token('foo'), 1),
+ new ParserException('error #2', new Token('bar'), 2),
)
);
}
/**
+ * @runInSeparateProcess
+ * @preserveGlobalState disabled
+ */
+ public function testErrorTranslate()
+ {
+ define('TRANSLATE', '\\SqlParser\\Tests\\translate');
+
+ $parser = new Parser(new TokensList());
+
+ $parser->error('TO_TRANSLATE', null);
+
+ $this->assertEquals(
+ $parser->errors,
+ array(new ParserException('***', null, 0))
+ );
+ }
+
+ /**
* @expectedException SqlParser\Exceptions\ParserException
* @expectedExceptionMessage strict error
* @expectedExceptionCode 3
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 6cc3c63..d23d71f 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -9,6 +9,19 @@ use SqlParser\Parser;
use SqlParser\Token;
/**
+ * Dummy function used to test if errors are translated.
+ *
+ * It translates only "TO_TRANSLATE" to "***".
+ *
+ * @param string $msg
+ *
+ * @return string
+ */
+function translate($msg) {
+ return str_replace('TO_TRANSLATE', '***' , $msg);
+}
+
+/**
* Implements useful methods for testing.
*
* Each test consists of a string that represents the serialized Lexer or Parser