ben                                      Tue, 15 Jun 2010 21:25:47 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=300481

Log:
Added tests for SplFileObject::fgetcsv

Changed paths:
    A   php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_basic.phpt
    A   
php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt
    A   
php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt
    A   
php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt
    A   
php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt
    A   php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt
    A   php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt

Added: php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_basic.phpt
===================================================================
--- php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_basic.phpt            
                (rev 0)
+++ php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_basic.phpt    
2010-06-15 21:25:47 UTC (rev 300481)
@@ -0,0 +1,31 @@
+--TEST--
+SplFileObject::fgetcsv default path
+--FILE--
+<?php
+$fp = fopen('SplFileObject::fgetcsv.csv', 'w+');
+fputcsv($fp, array(
+       'field1',
+       'field2',
+       'field3',
+       5
+));
+fclose($fp);
+
+$fo = new SplFileObject('SplFileObject::fgetcsv.csv');
+var_dump($fo->fgetcsv());
+?>
+--CLEAN--
+<?php
+unlink('SplFileObject::fgetcsv.csv');
+?>
+--EXPECTF--
+array(4) {
+  [0]=>
+  string(6) "field1"
+  [1]=>
+  string(6) "field2"
+  [2]=>
+  string(6) "field3"
+  [3]=>
+  string(1) "5"
+}

Added: 
php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt
===================================================================
--- php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt  
                        (rev 0)
+++ php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_delimiter_basic.phpt  
2010-06-15 21:25:47 UTC (rev 300481)
@@ -0,0 +1,31 @@
+--TEST--
+SplFileObject::fgetcsv with alternative delimeter
+--FILE--
+<?php
+$fp = fopen('SplFileObject::fgetcsv.csv', 'w+');
+fputcsv($fp, array(
+       'field1',
+       'field2',
+       'field3',
+       5
+), '|');
+fclose($fp);
+
+$fo = new SplFileObject('SplFileObject::fgetcsv.csv');
+var_dump($fo->fgetcsv('|'));
+?>
+--CLEAN--
+<?php
+unlink('SplFileObject::fgetcsv.csv');
+?>
+--EXPECTF--
+array(4) {
+  [0]=>
+  string(6) "field1"
+  [1]=>
+  string(6) "field2"
+  [2]=>
+  string(6) "field3"
+  [3]=>
+  string(1) "5"
+}

Added: 
php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt
===================================================================
--- php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt  
                        (rev 0)
+++ php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_delimiter_error.phpt  
2010-06-15 21:25:47 UTC (rev 300481)
@@ -0,0 +1,23 @@
+--TEST--
+SplFileObject::fgetcsv with alternative delimeter
+--FILE--
+<?php
+$fp = fopen('SplFileObject::fgetcsv.csv', 'w+');
+fputcsv($fp, array(
+       'field1',
+       'field2',
+       'field3',
+       5
+), '|');
+fclose($fp);
+
+$fo = new SplFileObject('SplFileObject::fgetcsv.csv');
+var_dump($fo->fgetcsv('invalid'));
+?>
+--CLEAN--
+<?php
+unlink('SplFileObject::fgetcsv.csv');
+?>
+--EXPECTF--
+Warning: SplFileObject::fgetcsv(): delimiter must be a character in %s on line 
%d
+bool(false)

Added: 
php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt
===================================================================
--- php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt  
                        (rev 0)
+++ php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_enclosure_basic.phpt  
2010-06-15 21:25:47 UTC (rev 300481)
@@ -0,0 +1,31 @@
+--TEST--
+SplFileObject::fgetcsv with alternative delimeter
+--FILE--
+<?php
+$fp = fopen('SplFileObject::fgetcsv.csv', 'w+');
+fputcsv($fp, array(
+       'field1',
+       'field2',
+       'field3',
+       5
+), ',', '"');
+fclose($fp);
+
+$fo = new SplFileObject('SplFileObject::fgetcsv.csv');
+var_dump($fo->fgetcsv(',', '"'));
+?>
+--CLEAN--
+<?php
+unlink('SplFileObject::fgetcsv.csv');
+?>
+--EXPECTF--
+array(4) {
+  [0]=>
+  string(6) "field1"
+  [1]=>
+  string(6) "field2"
+  [2]=>
+  string(6) "field3"
+  [3]=>
+  string(1) "5"
+}

Added: 
php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt
===================================================================
--- php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt  
                        (rev 0)
+++ php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt  
2010-06-15 21:25:47 UTC (rev 300481)
@@ -0,0 +1,23 @@
+--TEST--
+SplFileObject::fgetcsv with alternative delimeter
+--FILE--
+<?php
+$fp = fopen('SplFileObject::fgetcsv.csv', 'w+');
+fputcsv($fp, array(
+       'field1',
+       'field2',
+       'field3',
+       5
+), ',', '"');
+fclose($fp);
+
+$fo = new SplFileObject('SplFileObject::fgetcsv.csv');
+var_dump($fo->fgetcsv(',', 'invalid'));
+?>
+--CLEAN--
+<?php
+unlink('SplFileObject::fgetcsv.csv');
+?>
+--EXPECTF--
+Warning: SplFileObject::fgetcsv(): enclosure must be a character in %s on line 
%d
+bool(false)

Added: php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt
===================================================================
--- php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt     
                        (rev 0)
+++ php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_escape_basic.phpt     
2010-06-15 21:25:47 UTC (rev 300481)
@@ -0,0 +1,24 @@
+--TEST--
+SplFileObject::fgetcsv with alternative delimeter
+--FILE--
+<?php
+$fp = fopen('SplFileObject::fgetcsv.csv', 'w+');
+fwrite($fp, '"aaa","b""bb","ccc"');
+fclose($fp);
+
+$fo = new SplFileObject('SplFileObject::fgetcsv.csv');
+var_dump($fo->fgetcsv(',', '"', '"'));
+?>
+--CLEAN--
+<?php
+unlink('SplFileObject::fgetcsv.csv');
+?>
+--EXPECTF--
+array(3) {
+  [0]=>
+  string(3) "aaa"
+  [1]=>
+  string(4) "b"bb"
+  [2]=>
+  string(3) "ccc"
+}

Added: php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt
===================================================================
--- php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt     
                        (rev 0)
+++ php/php-src/trunk/ext/spl/tests/SplFileObject_fgetcsv_escape_error.phpt     
2010-06-15 21:25:47 UTC (rev 300481)
@@ -0,0 +1,18 @@
+--TEST--
+SplFileObject::fgetcsv with alternative delimeter
+--FILE--
+<?php
+$fp = fopen('SplFileObject::fgetcsv.csv', 'w+');
+fwrite($fp, '"aaa","b""bb","ccc"');
+fclose($fp);
+
+$fo = new SplFileObject('SplFileObject::fgetcsv.csv');
+var_dump($fo->fgetcsv(',', '"', 'invalid'));
+?>
+--CLEAN--
+<?php
+unlink('SplFileObject::fgetcsv.csv');
+?>
+--EXPECTF--
+Warning: SplFileObject::fgetcsv(): escape must be a character in %s on line %d
+bool(false)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to