浏览代码

Test: insert date default format and read row with data type

viest 5 年之前
父节点
当前提交
2462b459e0
共有 3 个文件被更改,包括 77 次插入0 次删除
  1. 1 0
      kernel/excel.c
  2. 25 0
      tests/insert_date_default_format.phpt
  3. 51 0
      tests/open_xlsx_next_row_with_data_type.phpt

+ 1 - 0
kernel/excel.c

@@ -480,6 +480,7 @@ PHP_METHOD(vtiful_xls, insertDate)
         type_writer(&_zv_double_time, row, column, &obj->write_ptr, format, NULL);
     }
 
+    zend_string_release(format);
     zval_ptr_dtor(&_zv_double_time);
 }
 /* }}} */

+ 25 - 0
tests/insert_date_default_format.phpt

@@ -0,0 +1,25 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php if (!extension_loaded("xlswriter")) print "skip"; ?>
+--FILE--
+<?php
+$config = [
+    'path' => './tests'
+];
+
+$fileObject = new \Vtiful\Kernel\Excel($config);
+$fileObject = $fileObject->fileName('tutorial.xlsx');
+
+$filePath = $fileObject->header(['date'])
+    ->insertDate(1, 0, time())
+    ->output();
+
+var_dump($filePath);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+string(21) "./tests/tutorial.xlsx"

+ 51 - 0
tests/open_xlsx_next_row_with_data_type.phpt

@@ -0,0 +1,51 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php
+require __DIR__ . '/include/skipif.inc';
+skip_disable_reader();
+?>
+--FILE--
+<?php
+$config   = ['path' => './tests'];
+$excel    = new \Vtiful\Kernel\Excel($config);
+$filePath = $excel->fileName('tutorial.xlsx')
+    ->header(['Item', 'Cost'])
+    ->data([
+        ['Item_1', 'Cost_1'],
+    ])
+    ->output();
+
+$excel->openFile('tutorial.xlsx')
+    ->openSheet();
+
+var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
+var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
+var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
+var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
+var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
+var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
+var_dump($excel->nextRow([\Vtiful\Kernel\Excel::TYPE_STRING, \Vtiful\Kernel\Excel::TYPE_STRING]));
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+array(2) {
+  [0]=>
+  string(4) "Item"
+  [1]=>
+  string(4) "Cost"
+}
+array(2) {
+  [0]=>
+  string(6) "Item_1"
+  [1]=>
+  string(6) "Cost_1"
+}
+NULL
+NULL
+NULL
+NULL
+NULL