Skip to content

Commit

Permalink
Fix which allows collections to exceed the size that Magento's collec…
Browse files Browse the repository at this point in the history
…tion getSize method returns.

So if collection getSize returns 2 but actual size is 4, all 4 records will be processed
  • Loading branch information
Aydin committed Oct 8, 2014
1 parent 28e97aa commit 5363c27
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Jh/DataImportMagento/Reader/MagentoReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function valid()
* seems to fix it but is hard to patch. This simple check should return false
* if the row if null
*/
return $this->current <= $this->count() && $this->data;
return $this->current <= $this->count() || $this->data;
}

/**
Expand Down
45 changes: 45 additions & 0 deletions test/DataImportMagentoTest/Reader/MagentoReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,49 @@ public function testIterator()
$i++;
}
}

public function testReaderReturnsAllDataIfCollectionSizeIsWrong()
{
$this->collection
->expects($this->once())
->method('getSelect')
->will($this->returnValue($this->select));

$this->collection
->expects($this->once())
->method('getSize')
->will($this->returnValue(1));

$this->reader = new MagentoReader($this->collection);
$statement = $this->getMock('\Zend_Db_Statement_Interface');
$this->select
->expects($this->once())
->method('query')
->will($this->returnValue($statement));

$data = array(
array('one' => 1, 'two' => 2, 'three' => 3),
array('one' => 11, 'two' => 22, 'three' => 33),
array('one' => 111, 'two' => 222, 'three' => 333),
);

$statement->expects($this->at(0))
->method('fetch')
->will($this->returnValue($data[0]));

$statement->expects($this->at(1))
->method('fetch')
->will($this->returnValue($data[1]));

$statement->expects($this->at(2))
->method('fetch')
->will($this->returnValue($data[2]));

$i = 1;
foreach ($this->reader as $key => $row) {
$this->assertEquals($i, $key);
$this->assertEquals($data[$i - 1], $row);
$i++;
}
}
}

0 comments on commit 5363c27

Please sign in to comment.