Skip to content
Permalink
Browse files

Add tests.

  • Loading branch information...
dereuromark committed Nov 23, 2017
1 parent 59d6610 commit 9902994c0436ce048f0a1a92d429833383ae13b5
@@ -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';
}
}

0 comments on commit 9902994

Please sign in to comment.
You can’t perform that action at this time.