1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Parser_Text_ParserTest extends SwaggerGen_TestCase |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @covers \SwaggerGen\Parser\Text\Parser::__construct |
8
|
|
|
*/ |
9
|
|
|
public function testConstructor_Empty() |
10
|
|
|
{ |
11
|
|
|
$object = new \SwaggerGen\Parser\Text\Parser(); |
12
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @covers \SwaggerGen\Parser\Text\Parser::__construct |
17
|
|
|
*/ |
18
|
|
|
public function testConstructor_Dirs() |
19
|
|
|
{ |
20
|
|
|
$this->markTestIncomplete('Not yet implemented.'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @covers \SwaggerGen\Parser\Text\Parser::addDirs |
25
|
|
|
*/ |
26
|
|
|
public function testAddDirs() |
27
|
|
|
{ |
28
|
|
|
$this->markTestIncomplete('Not yet implemented.'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @covers \SwaggerGen\Parser\Text\Parser::parseText |
33
|
|
|
*/ |
34
|
|
|
public function testParseText() |
35
|
|
|
{ |
36
|
|
|
$object = new \SwaggerGen\Parser\Text\Parser(); |
37
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
38
|
|
|
|
39
|
|
|
$statements = $object->parseText('title Some words'); |
40
|
|
|
|
41
|
|
|
$this->assertCount(1, $statements); |
42
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
43
|
|
|
$this->assertSame('title', $statements[0]->getCommand()); |
44
|
|
|
$this->assertSame('Some words', $statements[0]->getData()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @covers \SwaggerGen\Parser\Text\Parser::parseText |
49
|
|
|
*/ |
50
|
|
|
public function testParseText_Whitespace() |
51
|
|
|
{ |
52
|
|
|
$object = new \SwaggerGen\Parser\Text\Parser(); |
53
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
54
|
|
|
|
55
|
|
|
$statements = $object->parseText(" \t title \t\t Some words \t "); |
56
|
|
|
|
57
|
|
|
$this->assertCount(1, $statements); |
58
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
59
|
|
|
$this->assertSame('title', $statements[0]->getCommand()); |
60
|
|
|
$this->assertSame('Some words', $statements[0]->getData()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @covers \SwaggerGen\Parser\Text\Parser::parseText |
65
|
|
|
*/ |
66
|
|
|
public function testParseText_Multiple_LF() |
67
|
|
|
{ |
68
|
|
|
$object = new \SwaggerGen\Parser\Text\Parser(); |
69
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
70
|
|
|
|
71
|
|
|
$statements = $object->parseText("title Some words\nSome Random words"); |
72
|
|
|
|
73
|
|
|
$this->assertCount(2, $statements); |
74
|
|
|
|
75
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
76
|
|
|
$this->assertSame('title', $statements[0]->getCommand()); |
77
|
|
|
$this->assertSame('Some words', $statements[0]->getData()); |
78
|
|
|
|
79
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
80
|
|
|
$this->assertSame('Some', $statements[1]->getCommand()); |
81
|
|
|
$this->assertSame('Random words', $statements[1]->getData()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @covers \SwaggerGen\Parser\Text\Parser::parseText |
86
|
|
|
*/ |
87
|
|
|
public function testParseText_Multiple_CR() |
88
|
|
|
{ |
89
|
|
|
$object = new \SwaggerGen\Parser\Text\Parser(); |
90
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
91
|
|
|
|
92
|
|
|
$statements = $object->parseText("title Some words\rSome Random words"); |
93
|
|
|
|
94
|
|
|
$this->assertCount(2, $statements); |
95
|
|
|
|
96
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
97
|
|
|
$this->assertSame('title', $statements[0]->getCommand()); |
98
|
|
|
$this->assertSame('Some words', $statements[0]->getData()); |
99
|
|
|
|
100
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
101
|
|
|
$this->assertSame('Some', $statements[1]->getCommand()); |
102
|
|
|
$this->assertSame('Random words', $statements[1]->getData()); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @covers \SwaggerGen\Parser\Text\Parser::parseText |
107
|
|
|
*/ |
108
|
|
|
public function testParseText_Multiple_CRLF() |
109
|
|
|
{ |
110
|
|
|
$object = new \SwaggerGen\Parser\Text\Parser(); |
111
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
112
|
|
|
|
113
|
|
|
$statements = $object->parseText("title Some words\r\nSome Random words"); |
114
|
|
|
|
115
|
|
|
$this->assertCount(2, $statements); |
116
|
|
|
|
117
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
118
|
|
|
$this->assertSame('title', $statements[0]->getCommand()); |
119
|
|
|
$this->assertSame('Some words', $statements[0]->getData()); |
120
|
|
|
|
121
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
122
|
|
|
$this->assertSame('Some', $statements[1]->getCommand()); |
123
|
|
|
$this->assertSame('Random words', $statements[1]->getData()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @covers \SwaggerGen\Parser\Text\Parser::parseText |
128
|
|
|
*/ |
129
|
|
|
public function testParseText_Multiple_BlankLines() |
130
|
|
|
{ |
131
|
|
|
$object = new \SwaggerGen\Parser\Text\Parser(); |
132
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
133
|
|
|
|
134
|
|
|
$statements = $object->parseText("title Some words\r\n\n\n\rSome Random words"); |
135
|
|
|
|
136
|
|
|
$this->assertCount(2, $statements); |
137
|
|
|
|
138
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
139
|
|
|
$this->assertSame('title', $statements[0]->getCommand()); |
140
|
|
|
$this->assertSame('Some words', $statements[0]->getData()); |
141
|
|
|
|
142
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
143
|
|
|
$this->assertSame('Some', $statements[1]->getCommand()); |
144
|
|
|
$this->assertSame('Random words', $statements[1]->getData()); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @covers \SwaggerGen\Parser\Text\Parser::parseText |
149
|
|
|
*/ |
150
|
|
|
public function testParseText_Dirs() |
151
|
|
|
{ |
152
|
|
|
$object = new \SwaggerGen\Parser\Text\Parser(); |
153
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
154
|
|
|
|
155
|
|
|
$statements = $object->parseText("title Some words\r\n\n\n\rSome Random words", array( |
156
|
|
|
__DIR__ . '/ParserTest/not used by text parser', |
157
|
|
|
)); |
158
|
|
|
|
159
|
|
|
$this->assertCount(2, $statements); |
160
|
|
|
|
161
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
162
|
|
|
$this->assertSame('title', $statements[0]->getCommand()); |
163
|
|
|
$this->assertSame('Some words', $statements[0]->getData()); |
164
|
|
|
|
165
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
166
|
|
|
$this->assertSame('Some', $statements[1]->getCommand()); |
167
|
|
|
$this->assertSame('Random words', $statements[1]->getData()); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @covers \SwaggerGen\Parser\Text\Parser::parse |
172
|
|
|
*/ |
173
|
|
|
public function testParse() |
174
|
|
|
{ |
175
|
|
|
$object = new \SwaggerGen\Parser\Text\Parser(); |
176
|
|
|
$this->assertInstanceOf('\SwaggerGen\Parser\Text\Parser', $object); |
177
|
|
|
|
178
|
|
|
$statements = $object->parse(__DIR__ . '/ParserTest/testParse.txt', array( |
179
|
|
|
__DIR__ . '/ParserTest/not used by text parser', |
180
|
|
|
)); |
181
|
|
|
|
182
|
|
|
$this->assertCount(2, $statements); |
183
|
|
|
|
184
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[0]); |
185
|
|
|
$this->assertSame('title', $statements[0]->getCommand()); |
186
|
|
|
$this->assertSame('Some words', $statements[0]->getData()); |
187
|
|
|
|
188
|
|
|
$this->assertInstanceOf('\SwaggerGen\Statement', $statements[1]); |
189
|
|
|
$this->assertSame('Some', $statements[1]->getCommand()); |
190
|
|
|
$this->assertSame('Random words', $statements[1]->getData()); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
} |
194
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.