mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
17
.travis.yml
Normal file
17
.travis.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.6
|
||||
- 5.5
|
||||
- 5.4
|
||||
- 5.3
|
||||
- hhvm
|
||||
|
||||
script:
|
||||
- phpunit --configuration tests/phpunit.xml
|
||||
|
||||
notifications:
|
||||
email:
|
||||
- will.knauss@gmail.com
|
||||
on_success: never
|
||||
on_failure: always
|
||||
15
Makefile
Normal file
15
Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
COMPOSER_BIN_DIR := vendor/bin
|
||||
PHPUNIT_ARGS = -c tests/phpunit.xml
|
||||
|
||||
test: phpunit-dep
|
||||
${COMPOSER_BIN_DIR}/phpunit ${PHPUNIT_ARGS}
|
||||
|
||||
phpunit-dep:
|
||||
test -f ${COMPOSER_BIN_DIR}/phpunit || ( \
|
||||
echo "phpunit is required to run tests." \
|
||||
"Please run: composer install" >&2 && \
|
||||
exit 1 \
|
||||
)
|
||||
|
||||
.SILENT:
|
||||
.PHONY: test phpunit-dep
|
||||
@@ -145,7 +145,7 @@ class parseCSV {
|
||||
* @var string
|
||||
*/
|
||||
public $enclosure = '"';
|
||||
|
||||
|
||||
/**
|
||||
* Enclose All
|
||||
* Force enclosing all columns
|
||||
|
||||
6
tests/Bootstrap.php
Normal file
6
tests/Bootstrap.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
$dir = realpath(dirname(__FILE__));
|
||||
defined('BASE') OR define('BASE', realpath($dir.'/../').DIRECTORY_SEPARATOR);
|
||||
|
||||
require_once BASE.'parsecsv.lib.php';
|
||||
68
tests/methods/construct_test.php
Normal file
68
tests/methods/construct_test.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
class construct_methods_Test extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* CSV
|
||||
* The parseCSV object
|
||||
*
|
||||
* @access protected
|
||||
* @var [parseCSV]
|
||||
*/
|
||||
protected $csv = null;
|
||||
|
||||
/**
|
||||
* Setup
|
||||
* Setup our test environment objects
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function setUp() {
|
||||
//setup parse CSV
|
||||
#$this->csv = new parseCSV();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down
|
||||
* Tear down our test environment objects
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function tearDown() {
|
||||
$this->csv = null;
|
||||
}
|
||||
|
||||
public function test_offset_param() {
|
||||
$offset = 10;
|
||||
$this->csv = new parseCSV(null,$offset);
|
||||
$this->assertTrue(is_numeric($this->csv->offset));
|
||||
$this->assertEquals($offset,$this->csv->offset);
|
||||
}
|
||||
|
||||
public function test_limit_param() {
|
||||
$limit = 10;
|
||||
$this->csv = new parseCSV(null,null,$limit);
|
||||
$this->assertTrue(is_numeric($this->csv->limit));
|
||||
$this->assertEquals($limit,$this->csv->limit);
|
||||
}
|
||||
|
||||
public function test_conditions_param() {
|
||||
$conditions = 'some column NOT value';
|
||||
$this->csv = new parseCSV(null,null,null,$conditions);
|
||||
$this->assertTrue(is_string($this->csv->conditions));
|
||||
$this->assertEquals($conditions,$this->csv->conditions);
|
||||
}
|
||||
|
||||
public function test_keep_file_data_param() {
|
||||
$keep = true;
|
||||
$this->csv = new parseCSV(null,null,null,null,$keep);
|
||||
$this->assertTrue(is_bool($this->csv->keep_file_data));
|
||||
$this->assertEquals($keep,$this->csv->keep_file_data);
|
||||
}
|
||||
|
||||
public function test_input_param() {
|
||||
$csv = "col1,col2,col3\r\nval1,val2,val3\r\nval1A,val2A,val3A\r\n";
|
||||
$this->csv = new parseCSV($csv,null,null,null,true);
|
||||
$this->assertTrue(is_string($this->csv->file_data));
|
||||
$this->assertEquals($csv,$this->csv->file_data);
|
||||
}
|
||||
}
|
||||
18
tests/phpunit.xml
Normal file
18
tests/phpunit.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit
|
||||
bootstrap="Bootstrap.php"
|
||||
colors="false"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
stopOnError="true"
|
||||
stopOnFailure="true"
|
||||
stopOnIncomplete="true"
|
||||
stopOnSkipped="false">
|
||||
<testsuites>
|
||||
<testsuite name="parseCSV Test Suite">
|
||||
<directory suffix="test.php">properties/</directory>
|
||||
<directory suffix="test.php">methods/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
161
tests/properties/default_values_test.php
Normal file
161
tests/properties/default_values_test.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
class default_values_properties_Test extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* CSV
|
||||
* The parseCSV object
|
||||
*
|
||||
* @access protected
|
||||
* @var [parseCSV]
|
||||
*/
|
||||
protected $csv = null;
|
||||
|
||||
/**
|
||||
* Setup
|
||||
* Setup our test environment objects
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function setUp() {
|
||||
//setup parse CSV
|
||||
$this->csv = new parseCSV();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down
|
||||
* Tear down our test environment objects
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function tearDown() {
|
||||
$this->csv = null;
|
||||
}
|
||||
|
||||
public function test_heading_default() {
|
||||
$this->assertTrue(is_bool($this->csv->heading));
|
||||
$this->assertTrue($this->csv->heading);
|
||||
}
|
||||
|
||||
public function test_fields_default() {
|
||||
$this->assertTrue(is_array($this->csv->fields));
|
||||
$this->assertCount(0,$this->csv->fields);
|
||||
}
|
||||
|
||||
public function test_sort_by_default() {
|
||||
$this->assertNull($this->csv->sort_by);
|
||||
}
|
||||
|
||||
public function test_sort_reverse_default() {
|
||||
$this->assertTrue(is_bool($this->csv->sort_reverse));
|
||||
$this->assertFalse($this->csv->sort_reverse);
|
||||
}
|
||||
|
||||
public function test_sort_type_default() {
|
||||
$this->assertNull($this->csv->sort_type);
|
||||
}
|
||||
|
||||
public function test_delimiter_default() {
|
||||
$this->assertTrue(is_string($this->csv->delimiter));
|
||||
$this->assertEquals(',',$this->csv->delimiter);
|
||||
}
|
||||
|
||||
public function test_enclosure_default() {
|
||||
$this->assertTrue(is_string($this->csv->enclosure));
|
||||
$this->assertEquals('"',$this->csv->enclosure);
|
||||
}
|
||||
|
||||
public function test_enclose_all_default() {
|
||||
$this->assertTrue(is_bool($this->csv->enclose_all));
|
||||
$this->assertFalse($this->csv->enclose_all);
|
||||
}
|
||||
|
||||
public function test_conditions_default() {
|
||||
$this->assertNull($this->csv->conditions);
|
||||
}
|
||||
|
||||
public function test_offset_default() {
|
||||
$this->assertNull($this->csv->offset);
|
||||
}
|
||||
|
||||
public function test_limit_default() {
|
||||
$this->assertNull($this->csv->limit);
|
||||
}
|
||||
|
||||
public function test_auto_depth_default() {
|
||||
$this->assertTrue(is_numeric($this->csv->auto_depth));
|
||||
$this->assertEquals(15,$this->csv->auto_depth);
|
||||
}
|
||||
|
||||
public function test_auto_non_chars_default() {
|
||||
$this->assertTrue(is_string($this->csv->auto_non_chars));
|
||||
$this->assertEquals("a-zA-Z0-9\n\r",$this->csv->auto_non_chars);
|
||||
}
|
||||
|
||||
public function test_auto_preferred_default() {
|
||||
$this->assertTrue(is_string($this->csv->auto_preferred));
|
||||
$this->assertEquals(",;\t.:|",$this->csv->auto_preferred);
|
||||
}
|
||||
|
||||
public function test_convert_encoding_default() {
|
||||
$this->assertTrue(is_bool($this->csv->convert_encoding));
|
||||
$this->assertFalse($this->csv->convert_encoding);
|
||||
}
|
||||
|
||||
public function test_input_encoding_default() {
|
||||
$this->assertTrue(is_string($this->csv->input_encoding));
|
||||
$this->assertEquals('ISO-8859-1',$this->csv->input_encoding);
|
||||
}
|
||||
|
||||
public function test_output_encoding_default() {
|
||||
$this->assertTrue(is_string($this->csv->output_encoding));
|
||||
$this->assertEquals('ISO-8859-1',$this->csv->output_encoding);
|
||||
}
|
||||
|
||||
public function test_linefeed_default() {
|
||||
$this->assertTrue(is_string($this->csv->linefeed));
|
||||
$this->assertEquals("\r",$this->csv->linefeed);
|
||||
}
|
||||
|
||||
public function test_output_delimiter_default() {
|
||||
$this->assertTrue(is_string($this->csv->output_delimiter));
|
||||
$this->assertEquals(',',$this->csv->output_delimiter);
|
||||
}
|
||||
|
||||
public function test_output_filename_default() {
|
||||
$this->assertTrue(is_string($this->csv->output_filename));
|
||||
$this->assertEquals('data.csv',$this->csv->output_filename);
|
||||
}
|
||||
|
||||
public function test_keep_file_data_default() {
|
||||
$this->assertTrue(is_bool($this->csv->keep_file_data));
|
||||
$this->assertFalse($this->csv->keep_file_data);
|
||||
}
|
||||
|
||||
public function test_file_default() {
|
||||
$this->assertNull($this->csv->file);
|
||||
}
|
||||
|
||||
public function test_file_data_default() {
|
||||
$this->assertNull($this->csv->file_data);
|
||||
}
|
||||
|
||||
public function test_error_default() {
|
||||
$this->assertTrue(is_numeric($this->csv->error));
|
||||
$this->assertEquals(0,$this->csv->error);
|
||||
}
|
||||
|
||||
public function test_error_info_default() {
|
||||
$this->assertTrue(is_array($this->csv->error_info));
|
||||
$this->assertCount(0,$this->csv->error_info);
|
||||
}
|
||||
|
||||
public function test_titles_default() {
|
||||
$this->assertTrue(is_array($this->csv->titles));
|
||||
$this->assertCount(0,$this->csv->titles);
|
||||
}
|
||||
|
||||
public function test_data_default() {
|
||||
$this->assertTrue(is_array($this->csv->data));
|
||||
$this->assertCount(0,$this->csv->data);
|
||||
}
|
||||
}
|
||||
144
tests/properties/worthless_test.php
Normal file
144
tests/properties/worthless_test.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
class worthless_properties_Test extends PHPUnit_Framework_TestCase {
|
||||
/**
|
||||
* CSV
|
||||
* The parseCSV object
|
||||
*
|
||||
* @access protected
|
||||
* @var [parseCSV]
|
||||
*/
|
||||
protected $csv = null;
|
||||
|
||||
/**
|
||||
* Reflection Object
|
||||
* The reflection class object
|
||||
*
|
||||
* @access protected
|
||||
* @var [ReflectionClass]
|
||||
*/
|
||||
protected $reflection = null;
|
||||
|
||||
/**
|
||||
* Reflection Properties
|
||||
* The reflected class properties
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected $properties = null;
|
||||
|
||||
/**
|
||||
* Setup
|
||||
* Setup our test environment objects
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function setUp() {
|
||||
//setup parse CSV
|
||||
$this->csv = new parseCSV();
|
||||
|
||||
//setup the reflection class
|
||||
$this->reflection = new ReflectionClass($this->csv);
|
||||
|
||||
//setup the reflected class properties
|
||||
$this->properties = $this->reflection->getProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down
|
||||
* Tear down our test environment objects
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function tearDown() {
|
||||
$this->csv = null;
|
||||
$this->reflection = null;
|
||||
$this->properties = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* test_propertiesCount
|
||||
* Counts the number of properties to make sure we didn't add or
|
||||
* subtract any without thinking
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function test_propertiesCount() {
|
||||
$this->assertCount(27,$this->properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* test_property_names
|
||||
* We have an expected set of properties that should exists
|
||||
* Make sure our expected number of properties matches the real
|
||||
* count of properties and also check to make sure our expected
|
||||
* properties exists within the class
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function test_property_names() {
|
||||
//set our expected properties name(s)
|
||||
$names = array(
|
||||
'heading',
|
||||
'fields',
|
||||
'sort_by',
|
||||
'sort_reverse',
|
||||
'sort_type',
|
||||
'delimiter',
|
||||
'enclosure',
|
||||
'enclose_all',
|
||||
'conditions',
|
||||
'offset',
|
||||
'limit',
|
||||
'auto_depth',
|
||||
'auto_non_chars',
|
||||
'auto_preferred',
|
||||
'convert_encoding',
|
||||
'input_encoding',
|
||||
'output_encoding',
|
||||
'linefeed',
|
||||
'output_delimiter',
|
||||
'output_filename',
|
||||
'keep_file_data',
|
||||
'file',
|
||||
'file_data',
|
||||
'error',
|
||||
'error_info',
|
||||
'titles',
|
||||
'data'
|
||||
);
|
||||
|
||||
//find our real properties
|
||||
$real_properties = array();
|
||||
for ($a=0; $a<count($this->properties); $a++) {
|
||||
$real_properties[] = $this->properties[$a]->getName();
|
||||
}
|
||||
|
||||
//lets make sure our expected matches the number of real properties
|
||||
$this->assertCount(count($names),$this->properties);
|
||||
|
||||
//lets loop through our expected to make sure they exists
|
||||
for ($a=0; $a<count($names); $a++) {
|
||||
$this->assertTrue(in_array($names[$a],$real_properties));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test_count_public_properties
|
||||
* We at this point only have public properties so
|
||||
* lets verify all properties are public
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function test_count_public_properties() {
|
||||
$counter = 0;
|
||||
|
||||
for ($a=0; $a<count($this->properties); $a++) {
|
||||
if ($this->properties[$a]->isPublic() === true) {
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertCount($counter,$this->properties);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user