Просмотр исходного кода

Test: Check for existence before opening file

viest 5 лет назад
Родитель
Сommit
556c8f95fc
2 измененных файлов с 26 добавлено и 0 удалено
  1. 2 0
      kernel/read.c
  2. 24 0
      tests/open_xlsx_file_not_found.phpt

+ 2 - 0
kernel/read.c

@@ -28,8 +28,10 @@ xlsxioreader file_open(const char *directory, const char *file_name) {
     php_stat(path, strlen(path), FS_IS_FILE, &file_exists);
 
     if (Z_TYPE(file_exists) == IS_FALSE) {
+        efree(path);
         zval_ptr_dtor(&file_exists);
         zend_throw_exception(vtiful_exception_ce, "File not found, please check the path in the config or file name", 121);
+        return NULL;
     }
 
     if ((file = xlsxioread_open(path)) == NULL) {

+ 24 - 0
tests/open_xlsx_file_not_found.phpt

@@ -0,0 +1,24 @@
+--TEST--
+Check for vtiful presence
+--SKIPIF--
+<?php
+require __DIR__ . '/include/skipif.inc';
+skip_disable_reader();
+?>
+--FILE--
+<?php
+try {
+    $config = ['path' => './tests'];
+    $excel  = new \Vtiful\Kernel\Excel($config);
+
+    $excel->openFile('tutorial_not_found.xlsx');
+} catch (Vtiful\Kernel\Exception $exception) {
+    var_dump($exception->getMessage());
+}
+?>
+--CLEAN--
+<?php
+//
+?>
+--EXPECT--
+string(64) "File not found, please check the path in the config or file name"