TestExcelToDb.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. use const mtopcard\ProvinceList;
  4. const APP_ID = 'test';
  5. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  6. require_once(BASE_ROOT_PATH . '/global.php');
  7. require_once(BASE_ROOT_PATH . '/fooder.php');
  8. require_once(BASE_ROOT_PATH . "/helper/PHPExcel/PHPExcel.php");
  9. require_once(BASE_ROOT_PATH . "/helper/PHPExcel/PHPExcel/Reader/Excel2007.php");
  10. const LocalTest = 1;
  11. const NetTest = 2;
  12. const CurrentTest = NetTest;
  13. class TestExcelToDb extends TestCase
  14. {
  15. public function testImportingDataToDb()
  16. {
  17. $objReader = new PHPExcel_Reader_Excel2007;
  18. $objPHPExcel = $objReader->load("../sdm_business_code.xlsx");
  19. $sheetCount = $objPHPExcel->getSheetCount();
  20. $exportData = function ($sheetCount) use($objPHPExcel)
  21. {
  22. $businessCode = [];
  23. for ($i=0; $i<$sheetCount; $i++){
  24. $sheet = $objPHPExcel->getSheet($i);
  25. $businessCode[$i]["sheet_name"] = $sheet->getTitle();
  26. foreach($sheet->getRowIterator() as $key => $row) {
  27. $cellIterator = $row->getCellIterator();
  28. $cellIterator->setIterateOnlyExistingCells(true);
  29. foreach ($cellIterator as $cell) {
  30. if ($key > 1) {
  31. $columnValue = (string)$cell->getValue();
  32. $businessCode[$i]["data"][$key-2][] = $columnValue;
  33. }
  34. }
  35. }
  36. }
  37. return $businessCode;
  38. };
  39. $data = $exportData($sheetCount);
  40. }
  41. public function testTimes()
  42. {
  43. $timed = date("ymdhm", time());
  44. }
  45. public function testMd5()
  46. {
  47. $m = md5("123", true);
  48. }
  49. public function testGuid()
  50. {
  51. // if (function_exists('com_create_guid') === true) {
  52. // $guid = strtolower(str_replace('-', '', trim(com_create_guid(), '{}')));
  53. // }
  54. //
  55. // $guid = sprintf('%04x%04x%04x%04x%04x%04x%04x%04x', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
  56. $str = md5(uniqid(mt_rand(), true));
  57. $uuid = substr($str,0,8);
  58. $uuid .= substr($str,8,4);
  59. $uuid .= substr($str,12,4);
  60. $uuid .= substr($str,16,4);
  61. $uuid .= substr($str,20,12);
  62. }
  63. }