2 namespace JakubOnderka\PhpConsoleHighlighter;
4 class HighlighterTest extends \PHPUnit_Framework_TestCase
6 /** @var Highlighter */
9 protected function getConsoleColorMock()
11 $mock = method_exists($this, 'createMock')
12 ? $this->createMock('\JakubOnderka\PhpConsoleColor\ConsoleColor')
13 : $this->getMock('\JakubOnderka\PhpConsoleColor\ConsoleColor');
15 $mock->expects($this->any())
17 ->will($this->returnCallback(function ($style, $text) {
18 return "<$style>$text</$style>";
21 $mock->expects($this->any())
23 ->will($this->returnValue(true));
28 protected function setUp()
30 $this->uut = new Highlighter($this->getConsoleColorMock());
33 protected function compare($original, $expected)
35 $output = $this->uut->getWholeFile($original);
36 $this->assertEquals($expected, $output);
39 public function testVariable()
48 <token_default><?php</token_default>
49 <token_keyword>echo </token_keyword><token_default>\$a</token_default><token_keyword>;</token_keyword>
54 public function testInteger()
63 <token_default><?php</token_default>
64 <token_keyword>echo </token_keyword><token_default>43</token_default><token_keyword>;</token_keyword>
69 public function testFloat()
78 <token_default><?php</token_default>
79 <token_keyword>echo </token_keyword><token_default>43.3</token_default><token_keyword>;</token_keyword>
84 public function testHex()
93 <token_default><?php</token_default>
94 <token_keyword>echo </token_keyword><token_default>0x43</token_default><token_keyword>;</token_keyword>
99 public function testBasicFunction()
104 function plus(\$a, \$b) {
110 <token_default><?php</token_default>
111 <token_keyword>function </token_keyword><token_default>plus</token_default><token_keyword>(</token_keyword><token_default>\$a</token_default><token_keyword>, </token_keyword><token_default>\$b</token_default><token_keyword>) {</token_keyword>
112 <token_keyword> return </token_keyword><token_default>\$a </token_default><token_keyword>+ </token_keyword><token_default>\$b</token_default><token_keyword>;</token_keyword>
113 <token_keyword>}</token_keyword>
118 public function testStringNormal()
127 <token_default><?php</token_default>
128 <token_keyword>echo </token_keyword><token_string>'Ahoj světe'</token_string><token_keyword>;</token_keyword>
133 public function testStringDouble()
142 <token_default><?php</token_default>
143 <token_keyword>echo </token_keyword><token_string>"Ahoj světe"</token_string><token_keyword>;</token_keyword>
148 public function testInstanceof()
153 \$a instanceof stdClass;
157 <token_default><?php</token_default>
158 <token_default>\$a </token_default><token_keyword>instanceof </token_keyword><token_default>stdClass</token_default><token_keyword>;</token_keyword>
166 public function testConstant()
179 foreach ($constants as $constant) {
187 <token_default><?php</token_default>
188 <token_default>$constant</token_default><token_keyword>;</token_keyword>
197 public function testComment()
206 <token_default><?php</token_default>
207 <token_comment>/* Ahoj */</token_comment>
212 public function testDocComment()
221 <token_default><?php</token_default>
222 <token_comment>/** Ahoj */</token_comment>
227 public function testInlineComment()
236 <token_default><?php</token_default>
237 <token_comment>// Ahoj</token_comment>
242 public function testHashComment()
251 <token_default><?php</token_default>
252 <token_comment># Ahoj</token_comment>
257 public function testEmpty()
266 public function testWhitespace()
271 '<token_html> </token_html>'