Browse Source

Merge pull request #208 from viest/dev

Fix: read: Turning data into custom types
viest 5 years ago
parent
commit
3c492819fd
3 changed files with 80 additions and 2 deletions
  1. 4 1
      kernel/read.c
  2. 75 0
      tests/fix-207.phpt
  3. 1 1
      tests/open_xlsx_get_data_with_set_type.phpt

+ 4 - 1
kernel/read.c

@@ -162,7 +162,10 @@ void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_res
 
     {
         zend_long _long = 0; double _double = 0;
-        is_numeric_string(string_value, strlen(string_value), &_long, &_double, 0);
+
+        if (!(type & READ_TYPE_STRING)) {
+            is_numeric_string(string_value, strlen(string_value), &_long, &_double, 0);
+        }
 
         if (Z_TYPE_P(zv_result_t) == IS_ARRAY) {
             if (_double > 0) {

+ 75 - 0
tests/fix-207.phpt

@@ -0,0 +1,75 @@
+--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(['Name', 'Code'])
+    ->data([
+        ['Viest', '00024']
+    ])
+    ->output();
+
+$dataOne = $excel->openFile('tutorial.xlsx')
+    ->openSheet()
+    ->setType([
+        \Vtiful\Kernel\Excel::TYPE_STRING,
+        \Vtiful\Kernel\Excel::TYPE_STRING,
+    ])
+    ->getSheetData();
+
+$dataTwo = $excel->openFile('tutorial.xlsx')
+    ->openSheet()
+    ->setType([
+        \Vtiful\Kernel\Excel::TYPE_STRING,
+        \Vtiful\Kernel\Excel::TYPE_INT,
+    ])
+    ->getSheetData();
+
+var_dump($dataOne);
+var_dump($dataTwo);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/tutorial.xlsx');
+?>
+--EXPECT--
+array(2) {
+  [0]=>
+  array(2) {
+    [0]=>
+    string(4) "Name"
+    [1]=>
+    string(4) "Code"
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    string(5) "Viest"
+    [1]=>
+    string(5) "00024"
+  }
+}
+array(2) {
+  [0]=>
+  array(2) {
+    [0]=>
+    string(4) "Name"
+    [1]=>
+    string(4) "Code"
+  }
+  [1]=>
+  array(2) {
+    [0]=>
+    string(5) "Viest"
+    [1]=>
+    int(24)
+  }
+}

+ 1 - 1
tests/open_xlsx_get_data_with_set_type.phpt

@@ -48,7 +48,7 @@ array(2) {
     [0]=>
     string(5) "Viest"
     [1]=>
-    int(24)
+    string(2) "24"
     [2]=>
     int(1568877706)
   }