Pārlūkot izejas kodu

[ZF-10173] Zend_Db_Table:

- Fixed throw a exception case illegal index.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22615 44c647ce-9c0f-0410-b52a-842ac1e357ba
ramon 16 gadi atpakaļ
vecāks
revīzija
c28b77744b

+ 6 - 1
library/Zend/Db/Table/Rowset/Abstract.php

@@ -349,7 +349,12 @@ abstract class Zend_Db_Table_Rowset_Abstract implements SeekableIterator, Counta
      */
     public function offsetGet($offset)
     {
-        $this->_pointer = (int) $offset;
+        $offset = (int) $offset;
+        if ($offset < 0 || $offset >= $this->_count) {
+            require_once 'Zend/Db/Table/Rowset/Exception.php';
+            throw new Zend_Db_Table_Rowset_Exception("Illegal index $offset");
+        }
+        $this->_pointer = $offset;
 
         return $this->current();
     }

+ 19 - 2
tests/Zend/Db/Table/Rowset/TestCommon.php

@@ -266,12 +266,29 @@ abstract class Zend_Db_Table_Rowset_TestCommon extends Zend_Db_Table_TestSetup
 
     /**
      * @group ZF-9213
+     * @group ZF-10173
      */
     public function testTableRowsetIndexesValid()
     {
         $rowset = $this->_table['bugs']->fetchAll();
-        $this->assertNull($rowset[-1]);
+        try {
+            $rowset[-1];
+            $this->fail();
+        } catch (Exception $e) {
+            $this->assertType('Zend_Db_Table_Rowset_Exception', $e);
+            $this->assertContains('Illegal index', $e->getMessage());
+        }
+
         $this->assertTrue($rowset[0] instanceof Zend_Db_Table_Row);
-        $this->assertNull($rowset[count($rowset) + 2]);
+
+        try {
+            $row = $rowset[count($rowset) + 1];
+            $this->fail();
+        } catch (Exception $e) {
+            $this->assertType('Zend_Db_Table_Rowset_Exception', $e);
+            $this->assertContains('Illegal index', $e->getMessage());
+        }
+        $this->assertEquals(0, $rowset->key());
     }
+
 }