-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from cfv1000/feature/version-bump
feature/version-bump
- Loading branch information
Showing
5 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true"> | ||
|
||
<testsuites> | ||
<testsuite name="CSV Reader Tests"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory>src</directory> | ||
</include> | ||
<report> | ||
<clover outputFile="./.phpunit/clover.xml"/> | ||
<html outputDirectory="./.phpunit/coverage" lowUpperBound="35" highLowerBound="70"/> | ||
</report> | ||
</coverage> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
namespace cfv1000\CsvReader\Tests; | ||
|
||
use cfv1000\CsvReader\Reader; | ||
use org\bovigo\vfs\vfsStream; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ReaderTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
$this->root = vfsStream::setup('data', 0, [ | ||
'csv' => [ | ||
'file01.csv' => implode(PHP_EOL, [ | ||
'A1,B1,C1', | ||
'A2,B2,C2', | ||
'A3,B3,C3', | ||
'A4,B4,C4', | ||
'A5,B5,C5', | ||
]), | ||
'file02.csv' => implode(PHP_EOL, [ | ||
'A1|B1|C1', | ||
'A2|B2|C2', | ||
'A3|B3|C3', | ||
'A4|B4|C4', | ||
'A5|B5|C5', | ||
]) | ||
] | ||
]); | ||
} | ||
|
||
/** | ||
* Configurations on column separators | ||
*/ | ||
public function columnLineSeparatorDataProvider(): array | ||
{ | ||
return [ | ||
'initial file' => [ | ||
'file' => '/csv/file01.csv', | ||
'column separator' => ',', | ||
], | ||
'pipe column separator' => [ | ||
'file' => '/csv/file02.csv', | ||
'column separator' => '|' | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @return void | ||
* @dataProvider columnLineSeparatorDataProvider | ||
*/ | ||
public function testReader(string $file, string $columnSeparator): void | ||
{ | ||
$reader = new Reader($this->root->url() . $file, $columnSeparator); | ||
$data = $reader->current(); | ||
$this->assertSame(['A1', 'B1', 'C1'], $data); | ||
$this->assertSame(1, $reader->key()); | ||
} | ||
|
||
/** | ||
* @return void | ||
* @dataProvider columnLineSeparatorDataProvider | ||
*/ | ||
public function testKey(string $file, string $columnSeparator): void | ||
{ | ||
$reader = new Reader($this->root->url() . $file, $columnSeparator); | ||
$reader->next(); | ||
$reader->next(); | ||
|
||
$this->assertSame(3, $reader->key()); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testCount(): void | ||
{ | ||
$reader = new Reader($this->root->url() . '/csv/file01.csv'); | ||
$this->assertSame(4, $reader->count()); | ||
} | ||
|
||
/** | ||
* @return void | ||
* @dataProvider columnLineSeparatorDataProvider | ||
*/ | ||
public function testRewind(string $file, string $columnSeparator): void | ||
{ | ||
$reader = new Reader($this->root->url() . $file, $columnSeparator); | ||
$this->assertSame(['A1', 'B1', 'C1'], $reader->current()); | ||
$this->assertSame(['A2', 'B2', 'C2'], $reader->current()); | ||
$reader->rewind(); | ||
$this->assertSame(['A1', 'B1', 'C1'], $reader->current()); | ||
|
||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testTell(): void | ||
{ | ||
$reader = new Reader($this->root->url() . '/csv/file01.csv'); | ||
$this->assertSame(0, $reader->tell()); | ||
$reader->current(); | ||
$this->assertSame(10, $reader->tell()); | ||
$reader->current(); | ||