Browse Source

Merge branch 'master' into 3.next

Mark Story 7 years ago
parent
commit
c9686b68f1

+ 17 - 4
src/Controller/Controller.php

@@ -371,11 +371,24 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
         }
 
         list($plugin, $class) = pluginSplit($this->modelClass, true);
-        if ($class !== $name) {
-            return false;
-        }
+        if ($class === $name) {
+            return $this->loadModel($plugin . $class);
+        }
+
+        $trace = debug_backtrace();
+        $parts = explode('\\', get_class($this));
+        trigger_error(
+            sprintf(
+                'Undefined property: %s::$%s in %s on line %s',
+                array_pop($parts),
+                $name,
+                $trace[0]['file'],
+                $trace[0]['line']
+            ),
+            E_USER_NOTICE
+        );
 
-        return $this->loadModel($plugin . $class);
+        return false;
     }
 
     /**

+ 12 - 6
src/Database/Schema/MysqlSchema.php

@@ -137,7 +137,7 @@ class MysqlSchema extends BaseSchema
         if ($col === 'binary' && $length === 16) {
             return ['type' => TableSchema::TYPE_BINARY_UUID, 'length' => null];
         }
-        if (strpos($col, 'blob') !== false || $col === 'binary') {
+        if (strpos($col, 'blob') !== false || in_array($col, ['binary', 'varbinary'])) {
             $lengthName = substr($col, 0, -4);
             $length = isset(TableSchema::$columnLengths[$lengthName]) ? TableSchema::$columnLengths[$lengthName] : $length;
 
@@ -359,16 +359,22 @@ class MysqlSchema extends BaseSchema
                     break;
                 case TableSchema::TYPE_BINARY:
                     $isKnownLength = in_array($data['length'], TableSchema::$columnLengths);
-                    if (empty($data['length']) || !$isKnownLength) {
-                        $out .= ' BLOB';
-                        break;
-                    }
-
                     if ($isKnownLength) {
                         $length = array_search($data['length'], TableSchema::$columnLengths);
                         $out .= ' ' . strtoupper($length) . 'BLOB';
+                        break;
                     }
 
+                    if (empty($data['length'])) {
+                        $out .= ' BLOB';
+                        break;
+                    }
+
+                    if ($data['length'] > 2) {
+                        $out .= ' VARBINARY(' . $data['length'] . ')';
+                    } else {
+                        $out .= ' BINARY(' . $data['length'] . ')';
+                    }
                     break;
             }
         }

+ 3 - 1
src/Database/Schema/PostgresSchema.php

@@ -359,7 +359,6 @@ class PostgresSchema extends BaseSchema
             TableSchema::TYPE_TINYINTEGER => ' SMALLINT',
             TableSchema::TYPE_SMALLINTEGER => ' SMALLINT',
             TableSchema::TYPE_BINARY_UUID => ' UUID',
-            TableSchema::TYPE_BINARY => ' BYTEA',
             TableSchema::TYPE_BOOLEAN => ' BOOLEAN',
             TableSchema::TYPE_FLOAT => ' FLOAT',
             TableSchema::TYPE_DECIMAL => ' DECIMAL',
@@ -387,6 +386,9 @@ class PostgresSchema extends BaseSchema
         if ($data['type'] === TableSchema::TYPE_TEXT && $data['length'] !== TableSchema::LENGTH_TINY) {
             $out .= ' TEXT';
         }
+        if ($data['type'] === TableSchema::TYPE_BINARY) {
+            $out .= ' BYTEA';
+        }
 
         if ($data['type'] === TableSchema::TYPE_STRING ||
             ($data['type'] === TableSchema::TYPE_TEXT && $data['length'] === TableSchema::LENGTH_TINY)

+ 9 - 2
src/Database/Schema/SqliteSchema.php

@@ -102,7 +102,7 @@ class SqliteSchema extends BaseSchema
         if ($col === 'binary' && $length === 16) {
             return ['type' => TableSchema::TYPE_BINARY_UUID, 'length' => null];
         }
-        if (in_array($col, ['blob', 'clob', 'binary'])) {
+        if (in_array($col, ['blob', 'clob', 'binary', 'varbinary'])) {
             return ['type' => TableSchema::TYPE_BINARY, 'length' => $length];
         }
         if (in_array($col, ['date', 'time', 'timestamp', 'datetime'])) {
@@ -294,7 +294,6 @@ class SqliteSchema extends BaseSchema
             TableSchema::TYPE_INTEGER => ' INTEGER',
             TableSchema::TYPE_BIGINTEGER => ' BIGINT',
             TableSchema::TYPE_BOOLEAN => ' BOOLEAN',
-            TableSchema::TYPE_BINARY => ' BLOB',
             TableSchema::TYPE_FLOAT => ' FLOAT',
             TableSchema::TYPE_DECIMAL => ' DECIMAL',
             TableSchema::TYPE_DATE => ' DATE',
@@ -340,6 +339,14 @@ class SqliteSchema extends BaseSchema
             }
         }
 
+        if ($data['type'] === TableSchema::TYPE_BINARY) {
+            if (isset($data['length'])) {
+                $out .= ' BLOB(' . (int)$data['length'] . ')';
+            } else {
+                $out .= ' BLOB';
+            }
+        }
+
         $integerTypes = [
             TableSchema::TYPE_TINYINTEGER,
             TableSchema::TYPE_SMALLINTEGER,

+ 9 - 4
src/Database/Schema/SqlserverSchema.php

@@ -371,12 +371,17 @@ class SqlserverSchema extends BaseSchema
         }
 
         if ($data['type'] === TableSchema::TYPE_BINARY) {
-            $out .= ' VARBINARY';
+            if (!isset($data['length'])
+                || in_array($data['length'], [TableSchema::LENGTH_MEDIUM, TableSchema::LENGTH_LONG], true)) {
+                $data['length'] = 'MAX';
+            }
 
-            if ($data['length'] !== TableSchema::LENGTH_TINY) {
-                $out .= '(MAX)';
+            if ($data['length'] === 1) {
+                $out .= ' BINARY(1)';
             } else {
-                $out .= sprintf('(%s)', TableSchema::LENGTH_TINY);
+                $out .= ' VARBINARY';
+
+                $out .= sprintf('(%s)', $data['length']);
             }
         }
 

+ 1 - 1
src/View/ViewVarsTrait.php

@@ -75,7 +75,7 @@ trait ViewVarsTrait
         $builder = $this->viewBuilder();
         if ($viewClass === null && $builder->getClassName() === null) {
             $builder->setClassName($this->viewClass);
-            unset($this->viewClass);
+            $this->viewClass = null;
         }
         if ($viewClass) {
             $builder->setClassName($viewClass);

+ 28 - 2
tests/TestCase/Controller/ControllerTest.php

@@ -23,6 +23,7 @@ use Cake\Http\Response;
 use Cake\Http\ServerRequest;
 use Cake\Routing\Router;
 use Cake\TestSuite\TestCase;
+use PHPUnit\Framework\Error\Notice;
 use TestApp\Controller\Admin\PostsController;
 use TestPlugin\Controller\TestPluginController;
 
@@ -271,7 +272,7 @@ class ControllerTest extends TestCase
         $Controller = new Controller($request, $response);
         $Controller->modelClass = 'SiteArticles';
 
-        $this->assertFalse($Controller->Articles);
+        $this->assertFalse(isset($Controller->Articles));
         $this->assertInstanceOf(
             'Cake\ORM\Table',
             $Controller->SiteArticles
@@ -280,7 +281,7 @@ class ControllerTest extends TestCase
 
         $Controller->modelClass = 'Articles';
 
-        $this->assertFalse($Controller->SiteArticles);
+        $this->assertFalse(isset($Controller->SiteArticles));
         $this->assertInstanceOf(
             'TestApp\Model\Table\ArticlesTable',
             $Controller->Articles
@@ -288,6 +289,31 @@ class ControllerTest extends TestCase
     }
 
     /**
+     * testUndefinedPropertyError
+     *
+     * @return void
+     */
+    public function testUndefinedPropertyError()
+    {
+        $controller = new Controller();
+
+        $controller->Bar = true;
+        $this->assertTrue($controller->Bar);
+
+        if (class_exists(Notice::class)) {
+            $this->expectException(Notice::class);
+        } else {
+            $this->expectException(\PHPUnit_Framework_Error_Notice::class);
+        }
+        $this->expectExceptionMessage(sprintf(
+            'Undefined property: Controller::$Foo in %s on line %s',
+            __FILE__,
+            __LINE__ + 2
+        ));
+        $controller->Foo->baz();
+    }
+
+    /**
      * testLoadModel method
      *
      * @return void

+ 10 - 0
tests/TestCase/Database/Schema/MysqlSchemaTest.php

@@ -595,6 +595,16 @@ SQL;
                 ['type' => 'binary', 'length' => TableSchema::LENGTH_LONG, 'null' => false],
                 '`body` LONGBLOB NOT NULL'
             ],
+            [
+                'bytes',
+                ['type' => 'binary', 'length' => 5],
+                '`bytes` VARBINARY(5)'
+            ],
+            [
+                'bit',
+                ['type' => 'binary', 'length' => 1],
+                '`bit` BINARY(1)'
+            ],
             // Integers
             [
                 'post_id',

+ 10 - 0
tests/TestCase/Database/Schema/SqlserverSchemaTest.php

@@ -651,6 +651,16 @@ SQL;
                 ['type' => 'binary', 'length' => TableSchema::LENGTH_LONG],
                 '[img] VARBINARY(MAX)'
             ],
+            [
+                'bytes',
+                ['type' => 'binary', 'length' => 5],
+                '[bytes] VARBINARY(5)'
+            ],
+            [
+                'bytes',
+                ['type' => 'binary', 'length' => 1],
+                '[bytes] BINARY(1)'
+            ],
             // Boolean
             [
                 'checked',

+ 1 - 2
tests/TestCase/Error/ExceptionRendererTest.php

@@ -33,7 +33,6 @@ use Cake\Http\Exception\MethodNotAllowedException;
 use Cake\Http\Exception\NotFoundException;
 use Cake\Http\ServerRequest;
 use Cake\Mailer\Exception\MissingActionException as MissingMailerActionException;
-use Cake\Network\Exception\SocketException;
 use Cake\ORM\Exception\MissingBehaviorException;
 use Cake\Routing\DispatcherFactory;
 use Cake\Routing\Exception\MissingControllerException;
@@ -319,7 +318,7 @@ class ExceptionRendererTest extends TestCase
     public function testCakeErrorHelpersNotLost()
     {
         static::setAppNamespace();
-        $exception = new SocketException('socket exception');
+        $exception = new NotFoundException();
         $renderer = new \TestApp\Error\TestAppsExceptionRenderer($exception);
 
         $result = $renderer->render();