lime /test/unit/LimePrinterTest.php

Language PHP Lines 197
MD5 Hash c0a126b5fb7586939c3905f808d6a18a Estimated Cost $1,606 (why?)
Repository git://github.com/bschussek/lime.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php

/*
 * This file is part of the Lime framework.
 *
 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
 * (c) Bernhard Schussek <bernhard.schussek@symfony-project.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

LimeAnnotationSupport::enable();

$t = new LimeTest();

// @Before

  $colorizer = $t->stub('LimeColorizer');
  $printer = new LimePrinter($colorizer);


// @After

  $colorizer = null;
  $printer = null;


// @Test: printText() prints text using the given style

  // fixtures
  $colorizer->colorize('My text', 'RED')->returns('<RED>My text</RED>');
  $colorizer->replay();
  // test
  ob_start();
  $printer->printText('My text', 'RED');
  $result = ob_get_clean();
  // assertions
  $t->is($result, '<RED>My text</RED>', 'The result was colorized and printed');


// @Test: printLine() prints text followed by a newline

  // fixtures
  $colorizer->colorize('My text', 'RED')->returns('<RED>My text</RED>');
  $colorizer->replay();
  // test
  ob_start();
  $printer->printLine('My text', 'RED');
  $result = ob_get_clean();
  // assertions
  $t->is($result, "<RED>My text</RED>\n", 'The result was colorized and printed');


// @Test: printBox() prints text in a box with a width of 80 characters

  // fixtures
  $paddedText = str_pad('My text', 80, ' ');
  $colorizer->colorize($paddedText, 'RED')->returns('<RED>'.$paddedText.'</RED>');
  $colorizer->replay();
  // test
  ob_start();
  $printer->printBox('My text', 'RED');
  $result = ob_get_clean();
  // assertions
  $t->is($result, '<RED>'.$paddedText."</RED>\n", 'The result was colorized and printed');


// @Test: printLargeBox() prints text in a large box with a width of 80 characters or more

  // fixtures
  $paddedText = str_pad('  My text', 80, ' ');
  $paddedSpace = str_repeat(' ', 80);
  $colorizer->colorize($paddedText, 'RED')->returns('<RED>'.$paddedText.'</RED>');
  $colorizer->colorize($paddedSpace, 'RED')->returns('<RED>'.$paddedSpace.'</RED>');
  $colorizer->replay();
  // test
  ob_start();
  $printer->printLargeBox('My text', 'RED');
  $result = ob_get_clean();
  // assertions
  $t->is($result, "\n<RED>".$paddedSpace."</RED>\n<RED>".$paddedText."</RED>\n<RED>".$paddedSpace."</RED>\n\n", 'The result was colorized and printed');


// @Test: The printer does also work without colorizer

  // fixtures
  $printer = new LimePrinter();
  // test
  ob_start();
  $printer->printText('My text');
  $result = ob_get_clean();
  // assertions
  $t->is($result, 'My text', 'The result was printed');


// @Test: Strings in unformatted text are automatically formatted

  // fixtures
  $colorizer->colorize('"Test string"', LimePrinter::STRING)->returns('<BLUE>"Test string"</BLUE>');
  $colorizer->replay();
  // test
  ob_start();
  $printer->printText('My text with a "Test string"');
  $result = ob_get_clean();
  // assertions
  $t->is($result, 'My text with a <BLUE>"Test string"</BLUE>', 'The result was colorized and printed');


// @Test: Integers in unformatted text are automatically formatted

  // fixtures
  $colorizer->colorize('123', LimePrinter::NUMBER)->returns('<BLUE>123</BLUE>');
  $colorizer->replay();
  // test
  ob_start();
  $printer->printText('My text with an integer: 123');
  $result = ob_get_clean();
  // assertions
  $t->is($result, 'My text with an integer: <BLUE>123</BLUE>', 'The result was colorized and printed');


// @Test: Integers within words are not formatted

  // test
  ob_start();
  $printer->printText('My text with an inte123ger');
  $result = ob_get_clean();
  // assertions
  $t->is($result, 'My text with an inte123ger', 'The result was not colorized and printed');


// @Test: Floats in unformatted text are automatically formatted

  // fixtures
  $colorizer->colorize('1.23', LimePrinter::NUMBER)->returns('<BLUE>1.23</BLUE>');
  $colorizer->replay();
  // test
  ob_start();
  $printer->printText('My text with a float: 1.23');
  $result = ob_get_clean();
  // assertions
  $t->is($result, 'My text with a float: <BLUE>1.23</BLUE>', 'The result was colorized and printed');


// @Test: Booleans in unformatted text are automatically formatted

  // fixtures
  $colorizer->colorize('true', LimePrinter::BOOLEAN)->returns('<BLUE>true</BLUE>');
  $colorizer->colorize('false', LimePrinter::BOOLEAN)->returns('<BLUE>false</BLUE>');
  $colorizer->replay();
  // test
  ob_start();
  $printer->printText('My text with true and false');
  $result = ob_get_clean();
  // assertions
  $t->is($result, 'My text with <BLUE>true</BLUE> and <BLUE>false</BLUE>', 'The result was colorized and printed');

/*
// @Test: functions in unformatted text are automatically formatted

  // @Test: Case 1 - Function without prefix

  // fixtures
  $colorizer->colorize('function(1, 2)', LimePrinter::METHOD)->returns('<BLUE>function(1, 2)</BLUE>');
  $colorizer->replay();
  // test
  ob_start();
  $printer->printText('My text with a function(1, 2)');
  $result = ob_get_clean();
  // assertions
  $t->is($result, 'My text with a <BLUE>function(1, 2)</BLUE>', 'The result was colorized and printed');

  // @Test: Case 2 - Function with "->" prefix

  // fixtures
  $colorizer->colorize('->function()', LimePrinter::METHOD)->returns('<BLUE>->function()</BLUE>');
  $colorizer->replay();
  // test
  ob_start();
  $printer->printText('My text with a ->function()');
  $result = ob_get_clean();
  // assertions
  $t->is($result, 'My text with a <BLUE>->function()</BLUE>', 'The result was colorized and printed');

  // @Test: Case 3 - Function with "::" prefix

  // fixtures
  $colorizer->colorize('::function(1, 2)', LimePrinter::METHOD)->returns('<BLUE>::function(1, 2)</BLUE>');
  $colorizer->replay();
  // test
  ob_start();
  $printer->printText('My text with a ::function(1, 2)');
  $result = ob_get_clean();
  // assertions
  $t->is($result, 'My text with a <BLUE>::function(1, 2)</BLUE>', 'The result was colorized and printed');
*/
Back to Top