Skip to content

Commit

Permalink
Get code coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
chadicus committed Jun 9, 2018
1 parent ca822d2 commit c2ffdb8
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/DeriveHeaderStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,30 @@ public function rowNotIsHeaderRow()
$this->assertFalse($strategy->isHeaderRow($fileObject->fgetcsv()));
}

/**
* @test
* @covers ::createDataRow
*/
public function createDataRow()
{
$fileObject = $this->getFileObject();
$strategy = new DeriveHeaderStrategy();
$strategy->getHeaders($fileObject);
$fileObject->fgetcsv();//skip header line
$this->assertSame(
[
'id' => 'bk101',
'author' => 'Gambardella, Matthew',
'title' => 'XML Developer\'s Guide',
'genre' => 'Computer',
'price' => '44.95',
'publish_date' => '2000-10-01',
'description' => 'An in-depth look at creating applications with XML.',
],
$strategy->createDataRow($fileObject->fgetcsv())
);
}

private function getFileObject() : SplFileObject
{
$fileObject = new SplFileObject(__DIR__ . '/_files/pipe_delimited.txt');
Expand Down
31 changes: 31 additions & 0 deletions tests/NoHeaderStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,35 @@ public function isHeaderRowAlwaysReturnsFalse()
$this->assertFalse($strategy->isHeaderRow($fileObject->fgetcsv()));
$this->assertFalse($strategy->isHeaderRow($fileObject->fgetcsv()));
}

/**
* @test
* @covers ::createDataRow
*/
public function createDataRow()
{
$row = [
'bk101',
'Gambardella, Matthew',
'XML Developer\'s Guide',
'Computer',
'44.95',
'2000-10-01',
'An in-depth look at creating applications with XML.',
];
$strategy = new NoHeaderStrategy();
$this->assertSame(
[
'bk101',
'Gambardella, Matthew',
'XML Developer\'s Guide',
'Computer',
'44.95',
'2000-10-01',
'An in-depth look at creating applications with XML.',
],
$strategy->createDataRow($row)
);
}

}
30 changes: 30 additions & 0 deletions tests/ProvidedHeaderStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,36 @@ public function rowIsNotHeaderRow()
$this->assertFalse($strategy->isHeaderRow($fileObject->fgetcsv()));
}

/**
* @test
* @covers ::createDataRow
*/
public function createDataRow()
{
$row = [
'bk101',
'Gambardella, Matthew',
'XML Developer\'s Guide',
'Computer',
'44.95',
'2000-10-01',
'An in-depth look at creating applications with XML.',
];
$strategy = $this->getStrategy();
$this->assertSame(
[
'id' => 'bk101',
'author' => 'Gambardella, Matthew',
'title' => 'XML Developer\'s Guide',
'genre' => 'Computer',
'price' => '44.95',
'publish_date' => '2000-10-01',
'description' => 'An in-depth look at creating applications with XML.',
],
$strategy->createDataRow($row)
);
}

private function getFileObject() : SplFileObject
{
$fileObject = new SplFileObject(__DIR__ . '/_files/basic.csv');
Expand Down

0 comments on commit c2ffdb8

Please sign in to comment.