Browse Source

Merge branch 'master' into 3.next

Combine error messages added in 3.2, with exception type already added
in 3.next.
Mark Story 9 years ago
parent
commit
83747f8df0

+ 4 - 4
src/ORM/Marshaller.php

@@ -58,7 +58,7 @@ class Marshaller
      * Build the map of property => association names.
      *
      * @param array $options List of options containing the 'associated' key.
-     * @throws \InvalidArgumentException
+     * @throws \InvalidArgumentException When associations do not exist.
      * @return array
      */
     protected function _buildPropertyMap($options)
@@ -84,9 +84,9 @@ class Marshaller
             // it is a missing association that we should error on.
             if (substr($key, 0, 1) !== "_") {
                 throw new \InvalidArgumentException(sprintf(
-                    "'%s' is not associated with '%s'",
-                    $this->_table->alias(),
-                    $key
+                    'Cannot marshal data for "%s" association. It is not associated with "%s".',
+                    $key,
+                    $this->_table->alias()
                 ));
             }
         }

+ 3 - 3
src/Shell/Helper/TableHelper.php

@@ -32,7 +32,7 @@ class TableHelper extends Helper
         'rowSeparator' => false,
         'headerStyle' => 'info',
     ];
-    
+
     /**
      * Calculate the column widths
      *
@@ -44,7 +44,7 @@ class TableHelper extends Helper
         $widths = [];
         foreach ($rows as $line) {
             foreach ($line as $k => $v) {
-                $columnLength = mb_strlen($line[$k]);
+                $columnLength = mb_strwidth($line[$k]);
                 if ($columnLength > (isset($widths[$k]) ? $widths[$k] : 0)) {
                     $widths[$k] = $columnLength;
                 }
@@ -86,7 +86,7 @@ class TableHelper extends Helper
 
         $out = '';
         foreach ($row as $i => $column) {
-            $pad = $widths[$i] - mb_strlen($column);
+            $pad = $widths[$i] - mb_strwidth($column);
             if (!empty($options['style'])) {
                 $column = $this->_addStyle($column, $options['style']);
             }

+ 3 - 3
src/View/Helper/HtmlHelper.php

@@ -326,7 +326,7 @@ class HtmlHelper extends Helper
      *   over value of `escape`)
      * - `confirm` JavaScript confirmation message.
      *
-     * @param string $title The content to be wrapped by <a> tags.
+     * @param string $title The content to be wrapped by `<a>` tags.
      * @param string|array|null $url Cake-relative URL or array of URL parameters, or
      *   external URL (starts with http://)
      * @param array $options Array of options and HTML attributes.
@@ -420,7 +420,7 @@ class HtmlHelper extends Helper
      *   CSS stylesheets. If `$path` is prefixed with '/', the path will be relative to the webroot
      *   of your application. Otherwise, the path will be relative to your CSS path, usually webroot/css.
      * @param array $options Array of options and HTML arguments.
-     * @return string|null CSS <link /> or <style /> tag, depending on the type of link.
+     * @return string|null CSS `<link />` or `<style />` tag, depending on the type of link.
      * @link http://book.cakephp.org/3.0/en/views/helpers/html.html#linking-to-css-files
      */
     public function css($path, array $options = [])
@@ -561,7 +561,7 @@ class HtmlHelper extends Helper
      *
      * ### Options
      *
-     * - `safe` (boolean) Whether or not the $script should be wrapped in <![CDATA[ ]]>
+     * - `safe` (boolean) Whether or not the $script should be wrapped in `<![CDATA[ ]]>`
      * - `block` Set to true to append output to view block "script" or provide
      *   custom block name.
      *

+ 50 - 0
tests/TestCase/ORM/MarshallerTest.php

@@ -324,6 +324,29 @@ class MarshallerTest extends TestCase
     }
 
     /**
+     * Test one() with an invalid association
+     *
+     * @expectedException InvalidArgumentException
+     * @expectedExceptionMessage Cannot marshal data for "Derp" association. It is not associated with "Articles".
+     * @return void
+     */
+    public function testOneInvalidAssociation()
+    {
+        $data = [
+            'title' => 'My title',
+            'body' => 'My content',
+            'derp' => [
+                'id' => 1,
+                'username' => 'mark',
+            ]
+        ];
+        $marshall = new Marshaller($this->articles);
+        $marshall->one($data, [
+            'associated' => ['Derp']
+        ]);
+    }
+
+    /**
      * Test one() supports accessibleFields option for associations
      *
      * @return void
@@ -1335,6 +1358,33 @@ class MarshallerTest extends TestCase
     }
 
     /**
+     * Test merge() with an invalid association
+     *
+     * @expectedException InvalidArgumentException
+     * @expectedExceptionMessage Cannot marshal data for "Derp" association. It is not associated with "Articles".
+     * @return void
+     */
+    public function testMergeInvalidAssociation()
+    {
+        $data = [
+            'title' => 'My title',
+            'body' => 'My content',
+            'derp' => [
+                'id' => 1,
+                'username' => 'mark',
+            ]
+        ];
+        $article = new Entity([
+           'title' => 'title for post',
+           'body' => 'body',
+        ]);
+        $marshall = new Marshaller($this->articles);
+        $marshall->merge($article, $data, [
+            'associated' => ['Derp']
+        ]);
+    }
+
+    /**
      * Test merge when fieldList contains an association.
      *
      * @return void

+ 2 - 0
tests/TestCase/ORM/QueryRegressionTest.php

@@ -509,6 +509,8 @@ class QueryRegressionTest extends TestCase
         ]);
 
         $result = $table->find()->contain(['Articles.Tags'])->toArray();
+        $this->skipIf(count($result) == 0, 'No results, this test sometimes acts up on PHP 5.6');
+
         $this->assertEquals(
             ['tag1', 'tag3'],
             collection($result[2]->articles[0]->tags)->extract('name')->toArray()

+ 24 - 0
tests/TestCase/Shell/Helper/TableHelperTest.php

@@ -88,6 +88,30 @@ class TableHelperTest extends TestCase
     }
 
     /**
+     * Test output with multi-byte characters
+     *
+     * @return void
+     */
+    public function testOutputFullwidth()
+    {
+        $data = [
+            ['Header 1', 'Head', 'Long Header'],
+            ['short', '竜頭蛇尾', 'short'],
+            ['Longer thing', 'longerish', 'Longest Value'],
+        ];
+        $this->helper->output($data);
+        $expected = [
+            '+--------------+-----------+---------------+',
+            '| <info>Header 1</info>     | <info>Head</info>      | <info>Long Header</info>   |',
+            '+--------------+-----------+---------------+',
+            '| short        | 竜頭蛇尾  | short         |',
+            '| Longer thing | longerish | Longest Value |',
+            '+--------------+-----------+---------------+',
+        ];
+        $this->assertEquals($expected, $this->stub->messages());
+    }
+
+    /**
      * Test output without headers
      *
      * @return void