loaderTest.php 2.4 KB

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