PHP Classes

File: test/CSV_ParserTest.php

Recommend this page to a friend!
  Classes of Jabran Rafique   CSV Parser   test/CSV_ParserTest.php   Download  
File: test/CSV_ParserTest.php
Role: Unit test script
Content type: text/plain
Description: Class source
Class: CSV Parser
Parse CSV data to indexed or associative arrays
Author: By
Last change:
Date: 8 years ago
Size: 858 bytes
 

Contents

Class file image Download
<?php

/**
 * Unit test for CSV_Parser
 */

// require '../vendor/autoload.php';

class CSV_ParserTest extends PHPUnit_Framework_TestCase {
    public
$data, $csv;

    public function
setUp() {
       
$this->data = 'id,first_name,last_name,email,phone;1,Dave,John,dave@john.com,0123456789;2,John,Davis,john@davis.com,0978564321';
       
$this->csv = new CSV_Parser;
    }

    public function
tearDown() {
       
$this->csv = null;
    }

   
/**
     * @dataProvider testCaseCSVData
     */
   
public function testFromString($arr) {
       
$this->csv->fromString($this->data);
       
$result = $this->csv->parse();
       
$this->assertEquals($result, $arr);
    }

    public function
testCaseCSVData() {
        return array(
            array(
                array(
'id','first_name','last_name','email','phone'),
                array(
1,'Dave','John','dave@john.com','0123456789'),
                array(
2,'John','Davis','john@davis.com','0978564321')
            )
        );
    }
}