Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 23, 2017
1 parent 59d6610 commit 9902994
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 14 deletions.
38 changes: 24 additions & 14 deletions tests/TestCase/Database/TypeTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -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']);
Expand All @@ -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);
}

/**
Expand Down
25 changes: 25 additions & 0 deletions tests/test_app/TestApp/Database/Type/BarType.php
@@ -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';
}
}
25 changes: 25 additions & 0 deletions tests/test_app/TestApp/Database/Type/FooType.php
@@ -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.