Skip to content

Commit

Permalink
Fixed numeric mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
Damien PIQUET committed Feb 15, 2018
1 parent bb487ed commit 2a18d7a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
17 changes: 14 additions & 3 deletions Tests/MappedRow/MappedRowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,27 @@ public function testinvalidKey($key, $cols, $row)

public function invalidKeyDataProvider()
{
$cols = ['a', 'c'];
$cols = [
'a' => 0,
'c' => 1,
];
$mockRow = $this->createMock(Row::class);
$mockRow
->method('getCellIterator')
->willReturn(new \ArrayIterator([$this->generateMockCell('a'), $this->generateMockCell('b')]))
;
yield ['invalidCellKey', $cols, $mockRow];

$cols = [455, 377];
yield ['invalidCellKey', $cols, $mockRow];
$numericCols = [
455 => 1,
377 => 0,
];
$numericMockRow = $this->createMock(Row::class);
$numericMockRow
->method('getCellIterator')
->willReturn(new \ArrayIterator([$this->generateMockCell(4), $this->generateMockCell(5)]))
;
yield ['invalidCellKey', $numericCols, $numericMockRow];
}

/**
Expand Down
17 changes: 15 additions & 2 deletions Tests/SpreadSheetMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
class SpreadSheetMappingTest extends TestCase
{

public function testBasicIntegration()
/**
* @param string $filename
* @dataProvider basicIntegrationFilenameProvider
*/
public function testBasicIntegration($filename)
{
$workbook = IOFactory::load('Tests/testData/simpleok.xlsx');
$workbook = IOFactory::load($filename);
$worksheet = $workbook->getSheet(0);

$mapping = new Mapping();
Expand All @@ -31,6 +35,15 @@ public function testBasicIntegration()
}
}

/**
* @return \Generator|string[]
*/
public function basicIntegrationFilenameProvider()
{
yield ['Tests/testData/simpleok.xlsx'];
yield ['Tests/testData/gaps.xlsx'];
}

public function testOnlyColumns()
{
$workbook = IOFactory::load('Tests/testData/simpleok.xlsx');
Expand Down
Binary file added Tests/testData/gaps.xlsx
Binary file not shown.
4 changes: 1 addition & 3 deletions src/MappedRow/MappedRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Dpiquet\SpreadsheetMapping\MappedRow;


use Dpiquet\Mapping\Mapping;
use Dpiquet\SpreadsheetMapping\MappedRow\Exception\InvalidKeyException;
use Dpiquet\SpreadsheetMapping\MappedRow\Exception\MissingValueException;
use PhpOffice\PhpSpreadsheet\Worksheet\Row;
Expand Down Expand Up @@ -47,7 +45,7 @@ public function __construct(array $map, Row $row)
* @throws MissingValueException
*/
public function get($key) {
if (!in_array($key, $this->map)) {
if (!array_key_exists($key, $this->map)) {
throw new InvalidKeyException($key);
}

Expand Down

0 comments on commit 2a18d7a

Please sign in to comment.