Bläddra i källkod

Merge pull request #15 from viest/dev

test cases and function adjustment
王杰新 7 år sedan
förälder
incheckning
864e41b273
10 ändrade filer med 143 tillägg och 12 borttagningar
  1. 2 1
      .gitignore
  2. 1 2
      .travis.yml
  3. 19 0
      excel.php
  4. 17 8
      kernel/excel.c
  5. 1 1
      tests/001.phpt
  6. 22 0
      tests/002.phpt
  7. 23 0
      tests/003.phpt
  8. 24 0
      tests/004.phpt
  9. 10 0
      tests/005.phpt
  10. 24 0
      travis/run-test.sh

+ 2 - 1
.gitignore

@@ -14,6 +14,7 @@ config.nice
 config.status
 config.sub
 configure
+configure.ac
 configure.in
 include
 install-sh
@@ -36,4 +37,4 @@ tests/*/*.sh
 .idea
 cmake-build-debug
 CMakeLists.txt
-local_test.php
+local_test.php

+ 1 - 2
.travis.yml

@@ -24,6 +24,5 @@ branches:
   only:
     - master
     - dev
-
 script:
-  - exit 0
+    - ./travis/run-test.sh

+ 19 - 0
excel.php

@@ -0,0 +1,19 @@
+<?php
+$config = ['path' => './tests/'];
+$excel = new \Vtiful\Kernel\Excel($config);
+$fileFd = $excel->fileName('tutorial01.xlsx');
+var_dump($fileFd);
+$setHeader = $fileFd->header(['Item', 'Cost']);
+var_dump($setHeader);
+$setData = $setHeader->data([
+        ['Rent', 1000],
+        ['Gas',  100],
+        ['Food', 300],
+        ['Gym',  50],
+
+    ]);
+var_dump($setData);
+$output = $setData->output();
+var_dump($output);
+?>
+

+ 17 - 8
kernel/excel.c

@@ -108,8 +108,8 @@ PHP_METHOD(vtiful_excel, __construct)
  */
 PHP_METHOD(vtiful_excel, fileName)
 {
-    zval rv, tmp_file_name, file_path, handle, *config, *tmp_path;
-    zend_string *file_name, *key;
+    zval rv, file_path, handle, *config, *tmp_path;
+    zend_string *file_name, *key, *full_path;
     excel_resource_t *res;
 
     ZEND_PARSE_PARAMETERS_START(1, 1)
@@ -129,19 +129,25 @@ PHP_METHOD(vtiful_excel, fileName)
         zend_throw_exception(vtiful_exception_ce, "Configure 'path' must be a string type", 120);
     }
 
-    ZVAL_STR(&tmp_file_name, file_name);
-    concat_function(&file_path, tmp_path, &tmp_file_name);
+    char *tmp_dir = emalloc(Z_STRLEN_P(tmp_path)+ZSTR_LEN(file_name)+2);
+    strcpy(tmp_dir, Z_STRVAL_P(tmp_path));
+    strcat(tmp_dir, "/");
+    strcat(tmp_dir, ZSTR_VAL(file_name));
+
+    full_path = zend_string_init(tmp_dir, strlen(tmp_dir), 0);
+    ZVAL_STR(&file_path, full_path);
 
     res = emalloc(sizeof(excel_resource_t));
-    res->workbook  = workbook_new(ZSTR_VAL(zval_get_string(&file_path)));
+    res->workbook  = workbook_new(tmp_dir);
     res->worksheet = workbook_add_worksheet(res->workbook, NULL);
-    zval_ptr_dtor(&file_path);
 
     ZVAL_RES(&handle, zend_register_resource(res, le_excel_writer));
 
     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_FIL), &file_path);
     zend_update_property(vtiful_excel_ce, return_value, ZEND_STRL(V_EXCEL_HANDLE), &handle);
+
     zval_ptr_dtor(&file_path);
+    efree(tmp_dir);
 }
 /* }}} */
 
@@ -207,10 +213,11 @@ PHP_METHOD(vtiful_excel, data)
  */
 PHP_METHOD(vtiful_excel, output)
 {
-    zval rv, *handle, null_handle;
+    zval rv, null_handle, *handle, *file_path;
     excel_resource_t *res;
 
-    handle = zend_read_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_HANDLE), 0, &rv TSRMLS_DC);
+    handle    = zend_read_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_HANDLE), 0, &rv TSRMLS_DC);
+    file_path = zend_read_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_FIL), 0, &rv TSRMLS_DC);
     res = zval_get_resource(handle);
 
     workbook_file(res, handle);
@@ -219,6 +226,8 @@ PHP_METHOD(vtiful_excel, output)
 
     ZVAL_NULL(&null_handle);
     zend_update_property(vtiful_excel_ce, getThis(), ZEND_STRL(V_EXCEL_HANDLE), &null_handle);
+
+    ZVAL_COPY(return_value, file_path);
 }
 /* }}} */
 

+ 1 - 1
tests/001.phpt

@@ -1,7 +1,7 @@
 --TEST--
 Check for vtiful presence
 --SKIPIF--
-<?php if (!extension_loaded("vtiful")) print "skip"; ?>
+<?php if (!extension_loaded("excel_writer")) print "skip"; ?>
 --FILE--
 <?php 
 echo "vtiful extension is available";

+ 22 - 0
tests/002.phpt

@@ -0,0 +1,22 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php if (!extension_loaded("excel_writer")) print "skip"; ?>
+--FILE--
+<?php 
+$config = ['path' => './tests/'];
+$excel = new \Vtiful\Kernel\Excel($config);
+var_dump($excel);
+?>
+--EXPECT--
+object(Vtiful\Kernel\Excel)#1 (3) {
+  ["config":"Vtiful\Kernel\Excel":private]=>
+  array(1) {
+    ["path"]=>
+    string(8) "./tests/"
+  }
+  ["fileName":"Vtiful\Kernel\Excel":private]=>
+  NULL
+  ["handle":"Vtiful\Kernel\Excel":private]=>
+  NULL
+}

+ 23 - 0
tests/003.phpt

@@ -0,0 +1,23 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php if (!extension_loaded("excel_writer")) print "skip"; ?>
+--FILE--
+<?php 
+$config = ['path' => './tests/'];
+$excel = new \Vtiful\Kernel\Excel($config);
+$fileFd = $excel->fileName('tutorial01.xlsx');
+var_dump($fileFd);
+?>
+--EXPECT--
+object(Vtiful\Kernel\Excel)#1 (3) {
+  ["config":"Vtiful\Kernel\Excel":private]=>
+  array(1) {
+    ["path"]=>
+    string(8) "./tests/"
+  }
+  ["fileName":"Vtiful\Kernel\Excel":private]=>
+  string(23) "./tests/tutorial01.xlsx"
+  ["handle":"Vtiful\Kernel\Excel":private]=>
+  resource(4) of type (vtiful)
+}

+ 24 - 0
tests/004.phpt

@@ -0,0 +1,24 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php if (!extension_loaded("excel_writer")) print "skip"; ?>
+--FILE--
+<?php 
+$config = ['path' => './tests/'];
+$excel = new \Vtiful\Kernel\Excel($config);
+$fileFd = $excel->fileName('tutorial01.xlsx');
+$setHeader = $fileFd->header(['Item', 'Cost']);
+var_dump($setHeader);
+?>
+--EXPECT--
+object(Vtiful\Kernel\Excel)#1 (3) {
+  ["config":"Vtiful\Kernel\Excel":private]=>
+  array(1) {
+    ["path"]=>
+    string(8) "./tests/"
+  }
+  ["fileName":"Vtiful\Kernel\Excel":private]=>
+  string(23) "./tests/tutorial01.xlsx"
+  ["handle":"Vtiful\Kernel\Excel":private]=>
+  resource(5) of type (vtiful)
+}

+ 10 - 0
tests/005.phpt

@@ -0,0 +1,10 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php if (!extension_loaded("excel_writer")) print "skip"; ?>
+--FILE--
+<?php 
+echo "output path";
+?>
+--EXPECT--
+output path

+ 24 - 0
travis/run-test.sh

@@ -0,0 +1,24 @@
+#!/bin/bash
+TEST_DIR="`pwd`/tests/"
+
+make test 
+
+for file in `find $TEST_DIR -name "*.diff" 2>/dev/null`
+do
+	grep "\-\-XFAIL--" ${file/%diff/phpt} >/dev/null 2>&1
+	if [ $? -gt 0 ]
+	then
+		FAILS[${#FAILS[@]}]="$file"
+	fi
+done
+
+if [ ${#FAILS[@]} -gt 0 ]
+then
+	for fail in "${FAILS[@]}"
+	do
+		sh -xc "cat $fail"
+	done
+	exit 1
+else
+	exit 0
+fi