buildTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. * build测试
  13. * @author 刘志淳 <chun@engineer.com>
  14. */
  15. namespace tests\thinkphp\library\think;
  16. use think\Build;
  17. class buildTest extends \PHPUnit_Framework_TestCase
  18. {
  19. public function testRun()
  20. {
  21. $build = [
  22. // Test run directory
  23. '__dir__' => ['runtime/cache', 'runtime/log', 'runtime/temp', 'runtime/template'],
  24. '__file__' => ['common.php'],
  25. // Test generation module
  26. 'demo' => [
  27. '__file__' => ['common.php'],
  28. '__dir__' => ['behavior', 'controller', 'model', 'view', 'service'],
  29. 'controller' => ['Index', 'Test', 'UserType'],
  30. 'model' => ['User', 'UserType'],
  31. 'service' => ['User', 'UserType'],
  32. 'view' => ['index/index'],
  33. ],
  34. ];
  35. Build::run($build);
  36. $this->buildFileExists($build);
  37. }
  38. protected function buildFileExists($build)
  39. {
  40. foreach ($build as $module => $list) {
  41. if ('__dir__' == $module || '__file__' == $module) {
  42. foreach ($list as $file) {
  43. $this->assertFileExists(APP_PATH . $file);
  44. }
  45. } else {
  46. foreach ($list as $path => $moduleList) {
  47. if ('__file__' == $path || '__dir__' == $path) {
  48. foreach ($moduleList as $file) {
  49. $this->assertFileExists(APP_PATH . $module . '/' . $file);
  50. }
  51. } else {
  52. foreach ($moduleList as $file) {
  53. if ('view' == $path) {
  54. $file_name = APP_PATH . $module . '/' . $path . '/' . $file . '.html';
  55. } else {
  56. $file_name = APP_PATH . $module . '/' . $path . '/' . $file . EXT;
  57. }
  58. $this->assertFileExists($file_name);
  59. }
  60. }
  61. }
  62. $this->assertFileExists(APP_PATH . ($module ? $module . DS : '') . 'config.php');
  63. }
  64. }
  65. }
  66. }