Skip to content

Commit 2a18d7a

Browse files
author
Damien PIQUET
committed
Fixed numeric mapping
1 parent bb487ed commit 2a18d7a

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

Tests/MappedRow/MappedRowTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,27 @@ public function testinvalidKey($key, $cols, $row)
2323

2424
public function invalidKeyDataProvider()
2525
{
26-
$cols = ['a', 'c'];
26+
$cols = [
27+
'a' => 0,
28+
'c' => 1,
29+
];
2730
$mockRow = $this->createMock(Row::class);
2831
$mockRow
2932
->method('getCellIterator')
3033
->willReturn(new \ArrayIterator([$this->generateMockCell('a'), $this->generateMockCell('b')]))
3134
;
3235
yield ['invalidCellKey', $cols, $mockRow];
3336

34-
$cols = [455, 377];
35-
yield ['invalidCellKey', $cols, $mockRow];
37+
$numericCols = [
38+
455 => 1,
39+
377 => 0,
40+
];
41+
$numericMockRow = $this->createMock(Row::class);
42+
$numericMockRow
43+
->method('getCellIterator')
44+
->willReturn(new \ArrayIterator([$this->generateMockCell(4), $this->generateMockCell(5)]))
45+
;
46+
yield ['invalidCellKey', $numericCols, $numericMockRow];
3647
}
3748

3849
/**

Tests/SpreadSheetMappingTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
class SpreadSheetMappingTest extends TestCase
1212
{
1313

14-
public function testBasicIntegration()
14+
/**
15+
* @param string $filename
16+
* @dataProvider basicIntegrationFilenameProvider
17+
*/
18+
public function testBasicIntegration($filename)
1519
{
16-
$workbook = IOFactory::load('Tests/testData/simpleok.xlsx');
20+
$workbook = IOFactory::load($filename);
1721
$worksheet = $workbook->getSheet(0);
1822

1923
$mapping = new Mapping();
@@ -31,6 +35,15 @@ public function testBasicIntegration()
3135
}
3236
}
3337

38+
/**
39+
* @return \Generator|string[]
40+
*/
41+
public function basicIntegrationFilenameProvider()
42+
{
43+
yield ['Tests/testData/simpleok.xlsx'];
44+
yield ['Tests/testData/gaps.xlsx'];
45+
}
46+
3447
public function testOnlyColumns()
3548
{
3649
$workbook = IOFactory::load('Tests/testData/simpleok.xlsx');

Tests/testData/gaps.xlsx

4.55 KB
Binary file not shown.

src/MappedRow/MappedRow.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Dpiquet\SpreadsheetMapping\MappedRow;
44

5-
6-
use Dpiquet\Mapping\Mapping;
75
use Dpiquet\SpreadsheetMapping\MappedRow\Exception\InvalidKeyException;
86
use Dpiquet\SpreadsheetMapping\MappedRow\Exception\MissingValueException;
97
use PhpOffice\PhpSpreadsheet\Worksheet\Row;
@@ -47,7 +45,7 @@ public function __construct(array $map, Row $row)
4745
* @throws MissingValueException
4846
*/
4947
public function get($key) {
50-
if (!in_array($key, $this->map)) {
48+
if (!array_key_exists($key, $this->map)) {
5149
throw new InvalidKeyException($key);
5250
}
5351

0 commit comments

Comments
 (0)