Pārlūkot izejas kodu

:bugfix: zend framework1 multi queries should default to min/max 1/500

Fixes https://github.com/TechEmpower/FrameworkBenchmarks/pull/874#discussion_r16033669
Gerard Roche 10 gadi atpakaļ
vecāks
revīzija
adf3e32b27

+ 3 - 1
frameworks/PHP/php-zend-framework1/application/controllers/DbMultiController.php

@@ -4,7 +4,9 @@ class DbMultiController extends Zend_Controller_Action
 {
     public function indexAction()
     {
-        $queries = $this->getParam('queries', 1);
+        $queries = (int) $this->getParam('queries', 1);
+        $queries = max(1, $queries);
+        $queries = min(500, $queries);
 
         $table = new Zend_Db_Table('World');
 

+ 23 - 0
frameworks/PHP/php-zend-framework1/test/application/controllers/DbMultiControllerTest.php

@@ -18,6 +18,29 @@ class DbMultiControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
         $this->assertResponseResultsEquals(2, $this->getResponse()->getBody());
     }
 
+    public function testType3MultipleDatabaseQueryLessThan1DefaultsTo1()
+    {
+        $this->dispatch('/db-multi?queries=-1');
+        $this->assertResponseResultsEquals(1, $this->getResponse()->getBody());
+    }
+
+    public function testType3MultipleDatabaseQueryMoreThan500DefaultsTo500()
+    {
+        $this->dispatch('/db-multi?queries=501');
+        $this->assertResponseResultsEquals(500, $this->getResponse()->getBody());
+    }
+
+    public function testType3MultipleDatabaseQueryNotAnIntDefaultsTo1()
+    {
+        $this->dispatch('/db-multi?queries=foobar');
+        $this->assertResponseResultsEquals(1, $this->getResponse()->getBody());
+    }
+
+    public function testType3MultipleDatabaseQueryNoQueriesParamDefaultsTo1()
+    {
+        $this->dispatch('/db-multi');
+        $this->assertResponseResultsEquals(1, $this->getResponse()->getBody());
+    }
     /**
      * Helper assertion
      *