From 2a18d7abdf6bd49da1b8a2be13838767a2f4e817 Mon Sep 17 00:00:00 2001 From: Damien PIQUET Date: Thu, 15 Feb 2018 15:52:18 +0100 Subject: [PATCH] Fixed numeric mapping --- Tests/MappedRow/MappedRowTest.php | 17 ++++++++++++++--- Tests/SpreadSheetMappingTest.php | 17 +++++++++++++++-- Tests/testData/gaps.xlsx | Bin 0 -> 4662 bytes src/MappedRow/MappedRow.php | 4 +--- 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 Tests/testData/gaps.xlsx diff --git a/Tests/MappedRow/MappedRowTest.php b/Tests/MappedRow/MappedRowTest.php index 21a572f..3844c54 100644 --- a/Tests/MappedRow/MappedRowTest.php +++ b/Tests/MappedRow/MappedRowTest.php @@ -23,7 +23,10 @@ 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') @@ -31,8 +34,16 @@ public function invalidKeyDataProvider() ; 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]; } /** diff --git a/Tests/SpreadSheetMappingTest.php b/Tests/SpreadSheetMappingTest.php index 70511d2..6430fe9 100644 --- a/Tests/SpreadSheetMappingTest.php +++ b/Tests/SpreadSheetMappingTest.php @@ -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(); @@ -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'); diff --git a/Tests/testData/gaps.xlsx b/Tests/testData/gaps.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..bae2295e30cf11835a9fe9041a1ad2c25949a386 GIT binary patch literal 4662 zcmaJ^2RzjO|3CZ49+8uo)#1+GBO+&$k-am|;mFPmNw$)lY>~Z3M^+ihC=xPGM%GCp zME|?K|L-sV{=e_{^?BTVK6j7z>-BlRpRf5e&?X{g1OS0Rz-NDb9l#kmhkLg5b@oI; zMDX90X(L)hqO@_?u!NM5fF`D^PW9;c(Z`x$5m~QK?WG?7!Ff4BXn5=%>@#etg;foa@~2ebcyun1?lG8yax|pKJ&%@yOeph9Hfi@ZNW_eWe0`A!IgaF*{e*%UUx55eGXyA+RMndep zy+s1yo~Th>j~*x`>B8}Cbtsx|e_Y6~59W43o~cPqD)?M(Wdr*cvL>VPaAibv<7$3- zU|;m5jz_~;D6Xqpo@(3YG{kDg1>wn5K^wVWnFhEip7pK?Nqizq^_-SJWzC6;V0Cyv z3|O?wx4u{6Z+^Yas(cN@5&Yp+p5VZ8lQWfxpE^4->0 z_7H6wiWN}`62`J6)V?L1KKc^*)?=u7F4=-YXSF%xgl=K^RiR0(j)}r12#zdI4 zvoulI^Z~=AarXgA%S}GT^5>uSCYSb(iucdqAtL1zie1J5;7;&w5Ye55$PwY|jK}DH znyx+$qgd>Zgv$p~y6s)@(|Uvr4C%C#kuBWycY1UPT>w}u0c4S_)^V0g8Q+7p?Kw!^{8#@a=>UBGx{v|5WO{t{tN9BvoZJHO=NSDj` z%dc3iBwAE`p%OY18>hCpHl9m?`-|6bR1w==lY;P@IFdZ(KTX5w~uHm46_MBlVf*A&}sQ)TsF5=Lg zB5z$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