mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 00:36:38 +00:00
init introduce namespaces
This commit is contained in:
@@ -12,11 +12,12 @@
|
||||
"email": "will.knauss@gmail.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
".",
|
||||
"./extensions"
|
||||
]
|
||||
"autoload":{
|
||||
"psr-4":{
|
||||
"CSV\\": "src",
|
||||
"CSV\\extensions\\": "src\\extensions",
|
||||
"CSV\\tests\\": "tests"
|
||||
}
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.1.*"
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
namespace CSV;
|
||||
|
||||
class parseCSV {
|
||||
use CSV\extensions\DatatypeTrait;
|
||||
|
||||
class Csv {
|
||||
|
||||
/*
|
||||
Class: parseCSV v0.4.3 beta
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
namespace CSV\extensions;
|
||||
|
||||
trait DatatypeTrait {
|
||||
|
||||
@@ -1,22 +1,8 @@
|
||||
<?php
|
||||
|
||||
$dir = realpath(__DIR__);
|
||||
defined('BASE') OR define('BASE', dirname($dir) . '/');
|
||||
|
||||
recursivelyIncludeFiles(BASE . 'extensions');
|
||||
|
||||
require_once BASE . 'parsecsv.lib.php';
|
||||
require './vendor/autoload.php';
|
||||
|
||||
if (!class_exists('PHPUnit\Framework\TestCase')) {
|
||||
// we run on an older PHPUnit version without namespaces.
|
||||
require_once __DIR__ . '/PHPUnit_Framework_TestCase.inc.php';
|
||||
}
|
||||
|
||||
function recursivelyIncludeFiles($pathName){
|
||||
$dirIterator = new RecursiveDirectoryIterator($pathName);
|
||||
foreach ($dirIterator as $dir) {
|
||||
if ($dir->isFile() && $dir->getExtension() === 'php') {
|
||||
require_once $dir->getPathname();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
<?php
|
||||
namespace CSV\tests\methods;
|
||||
|
||||
class ConstructTest extends PHPUnit\Framework\TestCase {
|
||||
use CSV\Csv;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ConstructTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* CSV
|
||||
* The parseCSV object
|
||||
* The Csv object
|
||||
*
|
||||
* @access protected
|
||||
* @var [parseCSV]
|
||||
* @var [Csv]
|
||||
*/
|
||||
protected $csv = null;
|
||||
|
||||
@@ -19,7 +24,7 @@ class ConstructTest extends PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
public function setUp() {
|
||||
//setup parse CSV
|
||||
#$this->csv = new parseCSV();
|
||||
#$this->csv = new Csv();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,35 +39,35 @@ class ConstructTest extends PHPUnit\Framework\TestCase {
|
||||
|
||||
public function test_offset_param() {
|
||||
$offset = 10;
|
||||
$this->csv = new parseCSV(null, $offset);
|
||||
$this->csv = new Csv(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->csv = new Csv(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->csv = new Csv(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->csv = new Csv(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->csv = new Csv($csv, null, null, null, true);
|
||||
$this->assertTrue(is_string($this->csv->file_data));
|
||||
$this->assertEquals($csv, $this->csv->file_data);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
<?php
|
||||
namespace CSV\tests\methods;
|
||||
|
||||
class ParseTest extends PHPUnit\Framework\TestCase {
|
||||
use CSV\Csv;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class ParseTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* CSV
|
||||
* The parseCSV object
|
||||
* The CSV object
|
||||
*
|
||||
* @access protected
|
||||
* @var parseCSV
|
||||
* @var Csv
|
||||
*/
|
||||
protected $csv;
|
||||
|
||||
@@ -18,7 +23,7 @@ class ParseTest extends PHPUnit\Framework\TestCase {
|
||||
* @access public
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->csv = new parseCSV();
|
||||
$this->csv = new Csv();
|
||||
}
|
||||
|
||||
public function test_parse() {
|
||||
@@ -182,7 +187,7 @@ class ParseTest extends PHPUnit\Framework\TestCase {
|
||||
* @param string $enclosure
|
||||
*/
|
||||
public function testAutoQuotes($file, $enclosure) {
|
||||
$csv = new parseCSV();
|
||||
$csv = new Csv();
|
||||
$csv->auto($file, true, null, null, $enclosure);
|
||||
$this->assertArrayHasKey('column1', $csv->data[0], 'Data parsed incorrectly with enclosure ' . $enclosure);
|
||||
$this->assertEquals('value1', $csv->data[0]['column1'], 'Data parsed incorrectly with enclosure ' . $enclosure);
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
<?php
|
||||
namespace CSV\tests\methods;
|
||||
|
||||
class SaveTest extends PHPUnit\Framework\TestCase {
|
||||
use CSV\Csv;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
/** @var parseCSV */
|
||||
class SaveTest extends TestCase
|
||||
{
|
||||
|
||||
/** @var Csv */
|
||||
private $csv;
|
||||
|
||||
private $temp_filename;
|
||||
@@ -11,7 +16,7 @@ class SaveTest extends PHPUnit\Framework\TestCase {
|
||||
* Setup our test environment objects; will be called before each test.
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->csv = new parseCSV();
|
||||
$this->csv = new Csv();
|
||||
$this->csv->auto(__DIR__ . '/../example_files/single_column.csv');
|
||||
|
||||
// Remove last 2 lines to simplify comparison
|
||||
|
||||
Reference in New Issue
Block a user