Browse Source

Remove redundant tests around debug()

Apply suggestions from code review

Co-Authored-By: ADmad <ADmad@users.noreply.github.com>
Co-Authored-By: othercorey <corey.taylor.fl@gmail.com>
Mark Story 6 years ago
parent
commit
9e227f5ba1

+ 2 - 2
src/Error/Debug/ConsoleFormatter.php

@@ -75,9 +75,9 @@ class ConsoleFormatter implements FormatterInterface
     }
 
     /**
-     * {@inheritDoc}
+     * @inheritDoc
      */
-    public function formatWrapper(string $contents, array $location)
+    public function formatWrapper(string $contents, array $location): string
     {
         $lineInfo = '';
         if (isset($location['file'], $location['file'])) {

+ 1 - 1
src/Error/Debug/FormatterInterface.php

@@ -38,5 +38,5 @@ interface FormatterInterface
      * @param array $location The file and line the contents came from.
      * @return string
      */
-    public function formatWrapper(string $contents, array $location);
+    public function formatWrapper(string $contents, array $location): string;
 }

+ 2 - 2
src/Error/Debug/HtmlFormatter.php

@@ -60,9 +60,9 @@ class HtmlFormatter implements FormatterInterface
     }
 
     /**
-     * {@inheritDoc}
+     * @inheritDoc
      */
-    public function formatWrapper(string $contents, array $location)
+    public function formatWrapper(string $contents, array $location): string
     {
         $lineInfo = '';
         if (isset($location['file'], $location['file'])) {

+ 2 - 2
src/Error/Debug/TextFormatter.php

@@ -29,9 +29,9 @@ use RuntimeException;
 class TextFormatter implements FormatterInterface
 {
     /**
-     * {@inheritDoc}
+     * @inheritDoc
      */
-    public function formatWrapper(string $contents, array $location)
+    public function formatWrapper(string $contents, array $location): string
     {
         $template = <<<TEXT
 %s

+ 3 - 1
src/Error/Debugger.php

@@ -914,7 +914,9 @@ class Debugger
      * @param array $location If contains keys "file" and "line" their values will
      *    be used to show location info.
      * @param bool|null $showHtml If set to true, the method prints the debug
-     *    data in a browser-friendly way.
+     *    data encoded as HTML. If false, plain text formatting will be used.
+     *    If null, the format will be chosen based on the configured exportFormatter, or
+     *    environment conditions.
      * @return void
      */
     public static function printVar($var, array $location = [], ?bool $showHtml = null): void

+ 8 - 130
tests/TestCase/BasicsTest.php

@@ -19,6 +19,7 @@ declare(strict_types=1);
 namespace Cake\Test\TestCase;
 
 use Cake\Collection\Collection;
+use Cake\Error\Debugger;
 use Cake\Event\EventManager;
 use Cake\Http\Response;
 use Cake\TestSuite\TestCase;
@@ -230,7 +231,7 @@ class BasicsTest extends TestCase
 ###########################
 
 EXPECTED;
-        $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 9);
+        $expected = sprintf($expectedText, Debugger::trimPath(__FILE__), __LINE__ - 9);
 
         $this->assertSame($expected, $result);
 
@@ -238,146 +239,23 @@ EXPECTED;
         $value = '<div>this-is-a-test</div>';
         $this->assertSame($value, debug($value, true));
         $result = ob_get_clean();
-        $expectedHtml = <<<EXPECTED
-<div class="cake-debug-output" style="direction:ltr">
-<span><strong>%s</strong> (line <strong>%d</strong>)</span>
-<pre class="cake-debug">
-&#039;&lt;div&gt;this-is-a-test&lt;/div&gt;&#039;
-</pre>
-</div>
-EXPECTED;
-        $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
-        $this->assertSame($expected, $result);
+        $this->assertStringContainsString('<div class="cake-debug-output', $result);
+        $this->assertStringContainsString('this-is-a-test', $result);
 
         ob_start();
         debug('<div>this-is-a-test</div>', true, true);
         $result = ob_get_clean();
         $expected = <<<EXPECTED
-<div class="cake-debug-output" style="direction:ltr">
+<div class="cake-debug-output cake-debug" style="direction:ltr">
 <span><strong>%s</strong> (line <strong>%d</strong>)</span>
-<pre class="cake-debug">
-&#039;&lt;div&gt;this-is-a-test&lt;/div&gt;&#039;
-</pre>
-</div>
 EXPECTED;
-        $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
-        $this->assertSame($expected, $result);
+        $expected = sprintf($expected, Debugger::trimPath(__FILE__), __LINE__ - 6);
+        $this->assertStringContainsString($expected, $result);
 
         ob_start();
         debug('<div>this-is-a-test</div>', true, false);
         $result = ob_get_clean();
-        $expected = <<<EXPECTED
-<div class="cake-debug-output" style="direction:ltr">
-
-<pre class="cake-debug">
-&#039;&lt;div&gt;this-is-a-test&lt;/div&gt;&#039;
-</pre>
-</div>
-EXPECTED;
-        $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
-        $this->assertSame($expected, $result);
-
-        ob_start();
-        debug('<div>this-is-a-test</div>', null);
-        $result = ob_get_clean();
-        $expectedHtml = <<<EXPECTED
-<div class="cake-debug-output" style="direction:ltr">
-<span><strong>%s</strong> (line <strong>%d</strong>)</span>
-<pre class="cake-debug">
-&#039;&lt;div&gt;this-is-a-test&lt;/div&gt;&#039;
-</pre>
-</div>
-EXPECTED;
-        $expectedText = <<<EXPECTED
-%s (line %d)
-########## DEBUG ##########
-'<div>this-is-a-test</div>'
-###########################
-
-EXPECTED;
-        if ((PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg')) {
-            $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 18);
-        } else {
-            $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
-        }
-        $this->assertSame($expected, $result);
-
-        ob_start();
-        debug('<div>this-is-a-test</div>', null, false);
-        $result = ob_get_clean();
-        $expectedHtml = <<<EXPECTED
-<div class="cake-debug-output" style="direction:ltr">
-
-<pre class="cake-debug">
-&#039;&lt;div&gt;this-is-a-test&lt;/div&gt;&#039;
-</pre>
-</div>
-EXPECTED;
-        $expectedText = <<<EXPECTED
-
-########## DEBUG ##########
-'<div>this-is-a-test</div>'
-###########################
-
-EXPECTED;
-        if ((PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg')) {
-            $expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 18);
-        } else {
-            $expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
-        }
-        $this->assertSame($expected, $result);
-
-        ob_start();
-        debug('<div>this-is-a-test</div>', false);
-        $result = ob_get_clean();
-        $expected = <<<EXPECTED
-%s (line %d)
-########## DEBUG ##########
-'<div>this-is-a-test</div>'
-###########################
-
-EXPECTED;
-        $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 9);
-        $this->assertSame($expected, $result);
-
-        ob_start();
-        debug('<div>this-is-a-test</div>', false, true);
-        $result = ob_get_clean();
-        $expected = <<<EXPECTED
-%s (line %d)
-########## DEBUG ##########
-'<div>this-is-a-test</div>'
-###########################
-
-EXPECTED;
-        $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 9);
-        $this->assertSame($expected, $result);
-
-        ob_start();
-        debug('<div>this-is-a-test</div>', false, false);
-        $result = ob_get_clean();
-        $expected = <<<EXPECTED
-
-########## DEBUG ##########
-'<div>this-is-a-test</div>'
-###########################
-
-EXPECTED;
-        $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 9);
-        $this->assertSame($expected, $result);
-
-        ob_start();
-        $this->assertFalse(debug(false, false, false));
-        $result = ob_get_clean();
-        $expected = <<<EXPECTED
-
-########## DEBUG ##########
-false
-###########################
-
-EXPECTED;
-        $expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 9);
-        $this->assertSame($expected, $result);
+        $this->assertStringNotContainsString('(line', $result);
     }
 
     /**