diff options
-rw-r--r-- | src/Component.php | 120 | ||||
-rw-r--r-- | tests/Components/ComponentTest.php (renamed from tests/Components/FragmentTest.php) | 2 | ||||
-rw-r--r-- | tests/bootstrap.php | 23 |
3 files changed, 80 insertions, 65 deletions
diff --git a/src/Component.php b/src/Component.php index 3aa5506..7291ca5 100644 --- a/src/Component.php +++ b/src/Component.php @@ -10,64 +10,84 @@ * * @package SqlParser */ -namespace SqlParser; -/** - * A component (of a statement) is a part of a statement that is common to - * multiple query types. - * - * @category Components - * @package SqlParser - * @author Dan Ungureanu <udan1107@gmail.com> - * @license http://opensource.org/licenses/GPL-2.0 GNU Public License - */ -abstract class Component -{ +namespace { - /** - * Parses the tokens contained in the given list in the context of the given - * parser. - * - * @param Parser $parser The parser that serves as context. - * @param TokensList $list The list of tokens that are being parsed. - * @param array $options Parameters for parsing. - * - * @return mixed - */ - public static function parse( - Parser $parser, TokensList $list, array $options = array() - ) { - // This method should be abstract, but it can't be both static and - // abstract. - throw new \Exception('Not implemented yet.'); - } + if (!function_exists('__')) { - /** - * Builds the string representation of a component of this type. - * - * In other words, this function represents the inverse function of - * `static::parse`. - * - * @param mixed $component The component to be built. - * - * @return string - */ - public static function build($component) - { - // This method should be abstract, but it can't be both static and - // abstract. - throw new \Exception('Not implemented yet.'); + /** + * Translates the given string. + * + * @param string $str String to be translated. + * + * @return string + */ + function __($str) + { + return $str; + } } +} + +namespace SqlParser { /** - * Builds the string representation of a component of this type. - * - * @see static::build + * A component (of a statement) is a part of a statement that is common to + * multiple query types. * - * @return string + * @category Components + * @package SqlParser + * @author Dan Ungureanu <udan1107@gmail.com> + * @license http://opensource.org/licenses/GPL-2.0 GNU Public License */ - public function __toString() + abstract class Component { - return static::build($this); + + /** + * Parses the tokens contained in the given list in the context of the given + * parser. + * + * @param Parser $parser The parser that serves as context. + * @param TokensList $list The list of tokens that are being parsed. + * @param array $options Parameters for parsing. + * + * @return mixed + */ + public static function parse( + Parser $parser, TokensList $list, array $options = array() + ) { + // This method should be abstract, but it can't be both static and + // abstract. + throw new \Exception(\__('Not implemented yet.')); + } + + /** + * Builds the string representation of a component of this type. + * + * In other words, this function represents the inverse function of + * `static::parse`. + * + * @param mixed $component The component to be built. + * + * @return string + */ + public static function build($component) + { + // This method should be abstract, but it can't be both static and + // abstract. + throw new \Exception(\__('Not implemented yet.')); + } + + /** + * Builds the string representation of a component of this type. + * + * @see static::build + * + * @return string + */ + public function __toString() + { + return static::build($this); + } } } diff --git a/tests/Components/FragmentTest.php b/tests/Components/ComponentTest.php index f8b27fa..b2388a3 100644 --- a/tests/Components/FragmentTest.php +++ b/tests/Components/ComponentTest.php @@ -14,6 +14,8 @@ class ComponentTest extends TestCase /** * @expectedException \Exception * @expectedExceptionMessage Not implemented yet. + * @runInSeparateProcess + * @preserveGlobalState disabled */ public function testParse() { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 98ffcc6..ebf1ee7 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,25 +1,18 @@ <?php -namespace SqlParser\Tests; +/** + * Bootstrap for tests. + * + * @package SqlParser + * @subpackage Tests + */ -require_once 'vendor/autoload.php'; +namespace SqlParser\Tests; use SqlParser\Lexer; use SqlParser\Parser; -/** - * Dummy function used to test if errors are translated. - * - * It only translates "TO_TRANSLATE" to "***". - * - * @param string $msg The message to be translated. - * - * @return string - */ -function __($msg) -{ - return str_replace('TO_TRANSLATE', '***', $msg); -} +require_once 'vendor/autoload.php'; /** * Implements useful methods for testing. |