Skip to content

Commit

Permalink
Merge pull request #36 from peter279k/test_enhancement
Browse files Browse the repository at this point in the history
Test enhancement
  • Loading branch information
jwage authored May 11, 2018
2 parents 352781c + e729a2f commit 7693a63
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ php:
- 5.6
- hhvm
- 7.0
- 7.1
- 7.2
- nightly

before_script: composer install

matrix:
allow_failures:
- php: hhvm
- php: 7.0
- php: nightly
fast_finish: true
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@
{"name": "Jonathan H. Wage", "email": "[email protected]"}
],
"autoload": {
"psr-0": {"EasyCSV": "lib/"}
"psr-4": {
"EasyCSV\\": "lib/EasyCSV"
}
},
"autoload-dev": {
"psr-4": {
"EasyCSV\\Tests\\": "tests/EasyCSV/Tests"
}
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.5|^6.5"
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<filter>
<whitelist>
<directory suffix=".php">./src/Purl/</directory>
<directory suffix=".php">./lib/EasyCSV</directory>
</whitelist>
</filter>
</phpunit>
19 changes: 16 additions & 3 deletions tests/EasyCSV/Tests/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace EasyCSV\Tests;

use EasyCSV\Reader;
use PHPUnit\Framework\TestCase;

class ReaderTest extends \PHPUnit_Framework_TestCase
class ReaderTest extends TestCase
{
protected $headers = array("column1", "column2", "column3");

Expand Down Expand Up @@ -206,11 +207,12 @@ public function testAdvanceToNoHeadersFirstRow(Reader $reader)
}

/**
* @dataProvider getReaders
* @dataProvider advanceToLastLineProvider
*/
public function testAdvanceToLastLine(Reader $reader)
public function testAdvanceToLastLine($expectedRows, Reader $reader)
{
$reader->advanceTo(5);
$this->assertSame($expectedRows, $reader->getCurrentRow());
}

/**
Expand Down Expand Up @@ -300,6 +302,17 @@ public function getReaders()
);
}

public function advanceToLastLineProvider()
{
$readerSemiColon = new Reader(__DIR__ . '/read_sc.csv');
$readerSemiColon->setDelimiter(';');

return array(
array(array('5column2value', '5column3value', '5column4value'), new Reader(__DIR__ . '/read.csv')),
array(array('5column2value', '5column3value', '5column4value'), $readerSemiColon),
);
}

public function getReadersNoHeadersFirstRow()
{
$readerSemiColon = new Reader(__DIR__ . '/read_header_line_sc.csv', 'r+', false);
Expand Down
32 changes: 25 additions & 7 deletions tests/EasyCSV/Tests/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@

namespace EasyCSV\Tests;

class WriterTest extends \PHPUnit_Framework_TestCase
use EasyCSV\Reader;
use EasyCSV\Writer;
use PHPUnit\Framework\TestCase;

class WriterTest extends TestCase
{
private $writer;

public function setUp()
{
$this->writer = new \EasyCSV\Writer(__DIR__ . '/write.csv');
$this->writerBOM = new \EasyCSV\Writer(__DIR__ . '/write_bom.csv', 'r+', true);
$this->writer = new Writer(__DIR__ . '/write.csv');
$this->writerBOM = new Writer(__DIR__ . '/write_bom.csv', 'r+', true);
}

public function testWriteRow()
{
$this->writer->writeRow('test1, test2, test3');
$this->assertEquals(18, $this->writer->writeRow('test1, test2, test3'));
}

public function testWriteBOMRow()
{
$this->writerBOM->writeRow('колонка 1, колонка 2, колонка 3');
$this->assertEquals(57, $this->writerBOM->writeRow('колонка 1, колонка 2, колонка 3'));
}

public function testWriteFromArray()
Expand All @@ -29,6 +33,13 @@ public function testWriteFromArray()
'1test1, 1test2ing this out, 1test3',
array('2test1', '2test2 ing this out ok', '2test3')
));
$reader = new Reader(__DIR__ . '/write.csv');
$results = $reader->getRow();
$this->assertEquals(array(
'column1' => '1test1',
'column2' => '1test2ing this out',
'column3' => '1test3'
), $results);
}

public function testWriteBOMFromArray()
Expand All @@ -38,11 +49,18 @@ public function testWriteBOMFromArray()
'значение 1, значение 2, значение 3',
array('значение 4', 'значение 5', 'значение 6')
));
$reader = new Reader(__DIR__ . '/write_bom.csv');
$results = $reader->getRow();
$this->assertEquals(array(
'колонка 1' => 'значение 1',
'колонка 2' => 'значение 2',
'колонка 3' => 'значение 3'
), $results);
}

public function testReadWrittenFile()
{
$reader = new \EasyCSV\Reader(__DIR__ . '/write.csv');
$reader = new Reader(__DIR__ . '/write.csv');
$results = $reader->getAll();
$expected = array(
array(
Expand All @@ -61,7 +79,7 @@ public function testReadWrittenFile()

public function testReadWrittenBOMFile()
{
$reader = new \EasyCSV\Reader(__DIR__ . '/write_bom.csv');
$reader = new Reader(__DIR__ . '/write_bom.csv');
$results = $reader->getAll();
$expected = array(
array(
Expand Down
6 changes: 0 additions & 6 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

call_user_func(function () {
$loader = new \Composer\Autoload\ClassLoader();
$loader->add('EasyCSV\Test', __DIR__);
$loader->register();
});

0 comments on commit 7693a63

Please sign in to comment.