12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- use PHPUnit\Framework\TestCase;
- use const mtopcard\ProvinceList;
- const APP_ID = 'test';
- define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/global.php');
- require_once(BASE_ROOT_PATH . '/fooder.php');
- require_once(BASE_ROOT_PATH . "/helper/PHPExcel/PHPExcel.php");
- require_once(BASE_ROOT_PATH . "/helper/PHPExcel/PHPExcel/Reader/Excel2007.php");
- const LocalTest = 1;
- const NetTest = 2;
- const CurrentTest = NetTest;
- class TestExcelToDb extends TestCase
- {
- public function testImportingDataToDb()
- {
- $objReader = new PHPExcel_Reader_Excel2007;
- $objPHPExcel = $objReader->load("../sdm_business_code.xlsx");
- $sheetCount = $objPHPExcel->getSheetCount();
- $exportData = function ($sheetCount) use($objPHPExcel)
- {
- $businessCode = [];
- for ($i=0; $i<$sheetCount; $i++){
- $sheet = $objPHPExcel->getSheet($i);
- $businessCode[$i]["sheet_name"] = $sheet->getTitle();
- foreach($sheet->getRowIterator() as $key => $row) {
- $cellIterator = $row->getCellIterator();
- $cellIterator->setIterateOnlyExistingCells(true);
- foreach ($cellIterator as $cell) {
- if ($key > 1) {
- $columnValue = (string)$cell->getValue();
- $businessCode[$i]["data"][$key-2][] = $columnValue;
- }
- }
- }
- }
- return $businessCode;
- };
- $data = $exportData($sheetCount);
- }
- public function testTimes()
- {
- $timed = date("ymdhm", time());
- }
- public function testMd5()
- {
- $m = md5("123", true);
- }
- public function testGuid()
- {
- // if (function_exists('com_create_guid') === true) {
- // $guid = strtolower(str_replace('-', '', trim(com_create_guid(), '{}')));
- // }
- //
- // $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));
- $str = md5(uniqid(mt_rand(), true));
- $uuid = substr($str,0,8);
- $uuid .= substr($str,8,4);
- $uuid .= substr($str,12,4);
- $uuid .= substr($str,16,4);
- $uuid .= substr($str,20,12);
- }
- }
|