From 0f6c391104162ca29198e958f7b348cb5d1b2a51 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 20 Oct 2015 12:45:26 -0400 Subject: [PATCH] Allow NULL in boolean types. BOOLEAN columns can be nullable, so we should allow that state. Refs #7583 --- src/Database/Type/BoolType.php | 2 +- tests/TestCase/Database/TypeTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Database/Type/BoolType.php b/src/Database/Type/BoolType.php index 66d6c086d87..b457608f117 100644 --- a/src/Database/Type/BoolType.php +++ b/src/Database/Type/BoolType.php @@ -36,7 +36,7 @@ class BoolType extends Type */ public function toDatabase($value, Driver $driver) { - if ($value === true || $value === false) { + if ($value === true || $value === false || $value === null) { return $value; } diff --git a/tests/TestCase/Database/TypeTest.php b/tests/TestCase/Database/TypeTest.php index e6186c32046..c7b1d96f27d 100644 --- a/tests/TestCase/Database/TypeTest.php +++ b/tests/TestCase/Database/TypeTest.php @@ -272,6 +272,7 @@ public function testBooleanToDatabase() $type = Type::build('boolean'); $driver = $this->getMock('\Cake\Database\Driver'); + $this->assertNull($type->toDatabase(null, $driver)); $this->assertTrue($type->toDatabase(true, $driver)); $this->assertFalse($type->toDatabase(false, $driver)); $this->assertTrue($type->toDatabase(1, $driver));