New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix map() resetting cached object allowing build() to use the updated object #11457

Merged
merged 2 commits into from Nov 23, 2017
Jump to file or symbol
Failed to load files and symbols.
+76 −14
Diff settings

Always

Just for now

View
@@ -162,7 +162,9 @@ public static function map($type = null, $className = null)
if ($className === null) {
return isset(self::$_types[$type]) ? self::$_types[$type] : null;
}
self::$_types[$type] = $className;
unset(self::$_builtTypes[$type]);
}
/**
@@ -17,18 +17,8 @@
use Cake\Database\Type;
use Cake\TestSuite\TestCase;
use PDO;
/**
* Mock class for testing type registering
*/
class FooType extends \Cake\Database\Type
{
public function getBaseType()
{
return 'text';
}
}
use TestApp\Database\Type\BarType;
use TestApp\Database\Type\FooType;
/**
* Tests Type class
@@ -131,7 +121,7 @@ public function testMapAndBuild()
$this->assertNotEmpty($map);
$this->assertFalse(isset($map['foo']));
$fooType = __NAMESPACE__ . '\FooType';
$fooType = FooType::class;
Type::map('foo', $fooType);
$map = Type::map();
$this->assertEquals($fooType, $map['foo']);
@@ -142,11 +132,31 @@ public function testMapAndBuild()
$this->assertEquals('foo', $type->getName());
$this->assertEquals('text', $type->getBaseType());
$fooType = new FooType();
Type::map('foo2', $fooType);
$map = Type::map();
$this->assertSame($fooType, $map['foo2']);
$this->assertSame($fooType, Type::map('foo2'));
$type = Type::build('foo2');
$this->assertInstanceOf($fooType, $type);
}
/**
* Tests overwriting type map works for building
*
* @return void
*/
public function testReMapAndBuild()
{
$fooType = FooType::class;
$map = Type::map('foo', $fooType);
$type = Type::build('foo');
$this->assertInstanceOf($fooType, $type);
$barType = BarType::class;
Type::map('foo', $barType);
$type = Type::build('foo');
$this->assertInstanceOf($barType, $type);
}
/**
@@ -0,0 +1,25 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 3.5.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace TestApp\Database\Type;
use Cake\Database\Type;
class BarType extends Type
{
public function getBaseType()
{
return 'text';
}
}
@@ -0,0 +1,25 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 3.5.0
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
namespace TestApp\Database\Type;
use Cake\Database\Type;
class FooType extends Type
{
public function getBaseType()
{
return 'text';
}
}
ProTip! Use n and p to navigate between commits in a pull request.