File tree Expand file tree Collapse file tree 5 files changed +86
-9
lines changed
Expand file tree Collapse file tree 5 files changed +86
-9
lines changed Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ public function printValue($var, int $flags = null)
154154 }
155155
156156 $ output = static ::debugValue ($ var , $ flags );
157- if (PHP_SAPI !== ' cli ' ) {
157+ if (! $ this -> isCli () ) {
158158 $ output = "<pre> {$ output }</pre> " ;
159159 }
160160 echo $ output ;
@@ -204,4 +204,14 @@ public function logValue($var, int $flags = null)
204204 {
205205 $ this ->Logger ->addDebug (static ::debugValue ($ var , $ flags ));
206206 }
207+
208+ /**
209+ * Check whether we are in a CLI environment.
210+ *
211+ * @return bool
212+ */
213+ protected function isCli (): bool
214+ {
215+ return substr (PHP_SAPI , 0 , 3 ) === 'cli ' ;
216+ }
207217}
Original file line number Diff line number Diff line change 11<?php
22
3- namespace Fabacino \Debug \Test ;
4-
53/**
64 * Tests for function `dbg`.
5+ *
6+ * @copyright Fabian Wiget <fabacino@gmail.com>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
710 */
11+
12+ namespace Fabacino \Debug \Test ;
13+
814class DbgTest extends \PHPUnit \Framework \TestCase
915{
1016 /**
@@ -45,6 +51,27 @@ public function testPrintArray()
4551 [2] => third
4652)
4753
54+ EOT;
55+ $ this ->assertEquals ($ expected , $ this ->captureOutput ($ var ));
56+ }
57+
58+ /**
59+ * Test printing output in non-CLI environment.
60+ *
61+ * @return void
62+ */
63+ public function testPrintArrayNonCli ()
64+ {
65+ TestDebug::init ();
66+ $ var = ['first ' , 'second ' , 'third ' ];
67+ $ expected = <<<'EOT'
68+ <pre>Array
69+ (
70+ [0] => first
71+ [1] => second
72+ [2] => third
73+ )
74+ </pre>
4875EOT;
4976 $ this ->assertEquals ($ expected , $ this ->captureOutput ($ var ));
5077 }
Original file line number Diff line number Diff line change 11<?php
22
3+ /**
4+ * Tests for function `dbglog`.
5+ *
6+ * @copyright Fabian Wiget <fabacino@gmail.com>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
312namespace Fabacino \Debug \Test ;
413
514use Fabacino \Debug \Debug ;
615use Monolog \Logger ;
716use Monolog \Formatter \LineFormatter ;
817use Monolog \Handler \StreamHandler ;
918
10- /**
11- * Tests for function `dbglog`.
12- */
1319class DbglogTest extends \PHPUnit \Framework \TestCase
1420{
1521 /**
Original file line number Diff line number Diff line change 11<?php
22
3+ /**
4+ * Tests for function `dbgr`.
5+ *
6+ * @copyright Fabian Wiget <fabacino@gmail.com>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
312namespace Fabacino \Debug \Test ;
413
514use Fabacino \Debug \Debug ;
615
7- /**
8- * Tests for function `dbgr`.
9- */
1016class DbgrTest extends \PHPUnit \Framework \TestCase
1117{
1218 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Debug class for testing.
5+ *
6+ * @copyright Fabian Wiget <fabacino@gmail.com>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace Fabacino \Debug \Test ;
13+
14+ class TestDebug extends \Fabacino \Debug \Debug
15+ {
16+ /**
17+ * Check whether we are in a CLI environment.
18+ *
19+ * @return bool
20+ */
21+ protected function isCli (): bool
22+ {
23+ // PHPUnit is always executed through CLI. In order to be able to check
24+ // functionality which is working only in a non-CLI environment, we just
25+ // pretend that PHP is running in a non-CLI environment.
26+ return false ;
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments