Skip to content

Commit 7861701

Browse files
committed
Translated exceptions.
Refactored tests.
1 parent f1b0644 commit 7861701

3 files changed

Lines changed: 80 additions & 65 deletions

File tree

src/Component.php

Lines changed: 70 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,64 +10,84 @@
1010
*
1111
* @package SqlParser
1212
*/
13-
namespace SqlParser;
1413

15-
/**
16-
* A component (of a statement) is a part of a statement that is common to
17-
* multiple query types.
18-
*
19-
* @category Components
20-
* @package SqlParser
21-
* @author Dan Ungureanu <udan1107@gmail.com>
22-
* @license http://opensource.org/licenses/GPL-2.0 GNU Public License
23-
*/
24-
abstract class Component
25-
{
14+
namespace {
2615

27-
/**
28-
* Parses the tokens contained in the given list in the context of the given
29-
* parser.
30-
*
31-
* @param Parser $parser The parser that serves as context.
32-
* @param TokensList $list The list of tokens that are being parsed.
33-
* @param array $options Parameters for parsing.
34-
*
35-
* @return mixed
36-
*/
37-
public static function parse(
38-
Parser $parser, TokensList $list, array $options = array()
39-
) {
40-
// This method should be abstract, but it can't be both static and
41-
// abstract.
42-
throw new \Exception('Not implemented yet.');
43-
}
16+
if (!function_exists('__')) {
4417

45-
/**
46-
* Builds the string representation of a component of this type.
47-
*
48-
* In other words, this function represents the inverse function of
49-
* `static::parse`.
50-
*
51-
* @param mixed $component The component to be built.
52-
*
53-
* @return string
54-
*/
55-
public static function build($component)
56-
{
57-
// This method should be abstract, but it can't be both static and
58-
// abstract.
59-
throw new \Exception('Not implemented yet.');
18+
/**
19+
* Translates the given string.
20+
*
21+
* @param string $str String to be translated.
22+
*
23+
* @return string
24+
*/
25+
function __($str)
26+
{
27+
return $str;
28+
}
6029
}
30+
}
31+
32+
namespace SqlParser {
6133

6234
/**
63-
* Builds the string representation of a component of this type.
64-
*
65-
* @see static::build
35+
* A component (of a statement) is a part of a statement that is common to
36+
* multiple query types.
6637
*
67-
* @return string
38+
* @category Components
39+
* @package SqlParser
40+
* @author Dan Ungureanu <udan1107@gmail.com>
41+
* @license http://opensource.org/licenses/GPL-2.0 GNU Public License
6842
*/
69-
public function __toString()
43+
abstract class Component
7044
{
71-
return static::build($this);
45+
46+
/**
47+
* Parses the tokens contained in the given list in the context of the given
48+
* parser.
49+
*
50+
* @param Parser $parser The parser that serves as context.
51+
* @param TokensList $list The list of tokens that are being parsed.
52+
* @param array $options Parameters for parsing.
53+
*
54+
* @return mixed
55+
*/
56+
public static function parse(
57+
Parser $parser, TokensList $list, array $options = array()
58+
) {
59+
// This method should be abstract, but it can't be both static and
60+
// abstract.
61+
throw new \Exception(\__('Not implemented yet.'));
62+
}
63+
64+
/**
65+
* Builds the string representation of a component of this type.
66+
*
67+
* In other words, this function represents the inverse function of
68+
* `static::parse`.
69+
*
70+
* @param mixed $component The component to be built.
71+
*
72+
* @return string
73+
*/
74+
public static function build($component)
75+
{
76+
// This method should be abstract, but it can't be both static and
77+
// abstract.
78+
throw new \Exception(\__('Not implemented yet.'));
79+
}
80+
81+
/**
82+
* Builds the string representation of a component of this type.
83+
*
84+
* @see static::build
85+
*
86+
* @return string
87+
*/
88+
public function __toString()
89+
{
90+
return static::build($this);
91+
}
7292
}
7393
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class ComponentTest extends TestCase
1414
/**
1515
* @expectedException \Exception
1616
* @expectedExceptionMessage Not implemented yet.
17+
* @runInSeparateProcess
18+
* @preserveGlobalState disabled
1719
*/
1820
public function testParse()
1921
{

tests/bootstrap.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
<?php
22

3-
namespace SqlParser\Tests;
3+
/**
4+
* Bootstrap for tests.
5+
*
6+
* @package SqlParser
7+
* @subpackage Tests
8+
*/
49

5-
require_once 'vendor/autoload.php';
10+
namespace SqlParser\Tests;
611

712
use SqlParser\Lexer;
813
use SqlParser\Parser;
914

10-
/**
11-
* Dummy function used to test if errors are translated.
12-
*
13-
* It only translates "TO_TRANSLATE" to "***".
14-
*
15-
* @param string $msg The message to be translated.
16-
*
17-
* @return string
18-
*/
19-
function __($msg)
20-
{
21-
return str_replace('TO_TRANSLATE', '***', $msg);
22-
}
15+
require_once 'vendor/autoload.php';
2316

2417
/**
2518
* Implements useful methods for testing.

0 commit comments

Comments
 (0)