Przeglądaj źródła

ZF-7936 - Fix Truncate and Referential Integrity problems by using a Reverse Iterator in Truncate command

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@18390 44c647ce-9c0f-0410-b52a-842ac1e357ba
beberlei 16 lat temu
rodzic
commit
4af9ddc71e

+ 1 - 1
library/Zend/Test/PHPUnit/Db/Operation/Truncate.php

@@ -70,7 +70,7 @@ class Zend_Test_PHPUnit_Db_Operation_Truncate implements PHPUnit_Extensions_Data
             throw new Zend_Test_PHPUnit_Db_Exception("Not a valid Zend_Test_PHPUnit_Db_Connection instance, ".get_class($connection)." given!");
         }
 
-        foreach ($dataSet as $table) {
+        foreach ($dataSet->getReverseIterator() AS $table) {
             try {
                 $tableName = $table->getTableMetaData()->getTableName();
                 $this->truncate($connection->getConnection(), $tableName);

+ 24 - 4
tests/Zend/Test/PHPUnit/Db/Operation/TruncateTest.php

@@ -52,16 +52,16 @@ class Zend_Test_PHPUnit_Db_Operation_TruncateTest extends PHPUnit_Framework_Test
         $testAdapter = $this->getMock('Zend_Test_DbAdapter');
         $testAdapter->expects($this->at(0))
                     ->method('quoteIdentifier')
-                    ->with('foo')->will($this->returnValue('foo'));
+                    ->with('bar')->will($this->returnValue('bar'));
         $testAdapter->expects($this->at(1))
                     ->method('query')
-                    ->with('TRUNCATE foo');
+                    ->with('TRUNCATE bar');
         $testAdapter->expects($this->at(2))
                     ->method('quoteIdentifier')
-                    ->with('bar')->will($this->returnValue('bar'));
+                    ->with('foo')->will($this->returnValue('foo'));
         $testAdapter->expects($this->at(3))
                     ->method('query')
-                    ->with('TRUNCATE bar');
+                    ->with('TRUNCATE foo');
 
         $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
 
@@ -91,4 +91,24 @@ class Zend_Test_PHPUnit_Db_Operation_TruncateTest extends PHPUnit_Framework_Test
 
         $this->operation->execute($connection, $dataSet);
     }
+
+    /**
+     * @group ZF-7936
+     */
+    public function testTruncateAppliedToTablesInReverseOrder()
+    {
+        $testAdapter = new Zend_Test_DbAdapter();
+        $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
+
+        $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/truncateFixture.xml");
+
+        $this->operation->execute($connection, $dataSet);
+
+        $profiler = $testAdapter->getProfiler();
+        $queries = $profiler->getQueryProfiles();
+
+        $this->assertEquals(2, count($queries));
+        $this->assertContains('bar', $queries[0]->getQuery());
+        $this->assertContains('foo', $queries[1]->getQuery());
+    }
 }