loaderTest.php
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
/**
* Loader测试
* @author liu21st <liu21st@gmail.com>
*/
namespace tests\thinkphp\library\think;
use think\Loader;
class loaderTest extends \PHPUnit_Framework_TestCase
{
public function testAutoload()
{
$this->assertEquals(false, Loader::autoload('\think\Url'));
$this->assertEquals(false, Loader::autoload('think\Test'));
$this->assertEquals(false, Loader::autoload('my\HelloTest'));
}
public function testAddClassMap()
{
Loader::addClassMap('my\hello\Test', __DIR__ . DS . 'loader' . DS . 'Test.php');
}
public function testAddNamespace()
{
Loader::addNamespace('top', __DIR__ . DS . 'loader' . DS);
$this->assertEquals(true, Loader::autoload('top\test\Hello'));
}
public function testAddNamespaceAlias()
{
Loader::addNamespaceAlias('top', 'top\test');
Loader::addNamespaceAlias(['top' => 'top\test', 'app' => 'app\index']);
//$this->assertEquals(true, Loader::autoload('top\Hello'));
}
public function testTable()
{
Loader::db('mysql://root@127.0.0.1/test#utf8');
}
public function testImport()
{
$this->assertEquals(false, Loader::import('think.log.driver.MyTest'));
}
public function testParseName()
{
$this->assertEquals('HelloTest', Loader::parseName('hello_test', 1));
$this->assertEquals('hello_test', Loader::parseName('HelloTest', 0));
}
public function testParseClass()
{
$this->assertEquals('app\index\controller\User', Loader::parseClass('index', 'controller', 'user'));
$this->assertEquals('app\index\controller\user\Type', Loader::parseClass('index', 'controller', 'user.type'));
$this->assertEquals('app\admin\model\UserType', Loader::parseClass('admin', 'model', 'user_type'));
}
}