Login   Register  
PHP Classes
elePHPant
Icontem

File: tests/src/SplitCSV/FileTest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Sergii Pryz  >  PHP Split CSV  >  tests/src/SplitCSV/FileTest.php  >  Download  
File: tests/src/SplitCSV/FileTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: PHP Split CSV
Split CSV files input multiple parts set by rules
Author: By
Last change:
Date: 2013-12-29 09:31
Size: 1,792 bytes
 

Contents

Class file image Download
<?php
/**
 * File Test
 * 
 * @link        https://github.com/picamator/SplitCSV
 * @license     http://opensource.org/licenses/BSD-3-Clause New BSD License
 */

namespace SplitCSV;

class 
FileTest extends BaseTest
{
    
/**
     * @dataProvider    providerSplitBy
     * @param string    $source_path
     * @param string    $destination_path
     * @param \SplitCSV\Rule\RuleInterface  $rule
     * @param integer   $exptected_parts
     */
    
public function testSplitBy($source_path$destination_path, \SplitCSV\Rule\RuleInterface $rule$exptected_parts)
    {
        
// get full path
        
$source_path        $this->getDataPath($source_path);
        
$destination_path   $this->getDataPath($destination_path); 
          
        
// create file obj and decorate them
        
$split          = new File($source_path$destination_path);
        
        
$actual_parts   $split->splitBy($rule);
        
        
// asserts
        
$this->assertEquals($exptected_parts$actual_parts);
        
        
// assert real number of created files
        
$iterator   = new \DirectoryIterator($destination_path);
        
$i          0;
        foreach (
$iterator as $item) {
            if(!
$item->isDot()) {
                
unlink($item->getPathname());// remove files
                
$i++;
            }
        }   
        
        
$this->assertEquals($exptected_parts$i);
    }
    
    public function 
providerSplitBy()
    {
        return array(
            array(
                
'test-10000-rows-357kb.csv''parts', new \SplitCSV\Rule\FileSize(array('size' => '100kb')), 4
            
),
            
           array(
                
'test-10000-rows-357kb.csv''parts', new \SplitCSV\Rule\NumberRow(array('number_row' => 10)), 1000
           
),
        );
    }
}