Browse Source

Merge branch 'master' into 3.next

Mark Story 8 years ago
parent
commit
f0e61d9b66

+ 1 - 1
src/Database/Connection.php

@@ -859,7 +859,7 @@ class Connection implements ConnectionInterface
      */
     protected function _newLogger(StatementInterface $statement)
     {
-        $log = new LoggingStatement($statement, $this->getDriver());
+        $log = new LoggingStatement($statement, $this->_driver);
         $log->setLogger($this->getLogger());
 
         return $log;

+ 1 - 1
src/Database/Query.php

@@ -211,10 +211,10 @@ class Query implements ExpressionInterface, IteratorAggregate
     public function execute()
     {
         $statement = $this->_connection->run($this);
-        $driver = $this->_connection->getDriver();
         $typeMap = $this->getSelectTypeMap();
 
         if ($typeMap->toArray() && $this->_typeCastAttached === false) {
+            $driver = $this->_connection->getDriver();
             $this->decorateResults(new FieldTypeConverter($typeMap, $driver));
             $this->_typeCastAttached = true;
         }

+ 3 - 3
src/Datasource/Paginator.php

@@ -185,13 +185,13 @@ class Paginator implements PaginatorInterface
         $cleanQuery = clone $query;
         $results = $query->all();
         $numResults = count($results);
-        $count = $numResults ? $cleanQuery->count() : 0;
+        $count = $cleanQuery->count();
 
         $page = $options['page'];
         $limit = $options['limit'];
-        $pageCount = (int)ceil($count / $limit);
+        $pageCount = max((int)ceil($count / $limit), 1);
         $requestedPage = $page;
-        $page = max(min($page, $pageCount), 1);
+        $page = min($page, $pageCount);
 
         $order = (array)$options['order'];
         $sortDefault = $directionDefault = false;

+ 0 - 1
src/I18n/Formatter/IcuFormatter.php

@@ -17,7 +17,6 @@ namespace Cake\I18n\Formatter;
 use Aura\Intl\Exception\CannotFormat;
 use Aura\Intl\Exception\CannotInstantiateFormatter;
 use Aura\Intl\FormatterInterface;
-use Cake\I18n\PluralRules;
 use MessageFormatter;
 
 /**

+ 0 - 1
src/I18n/Formatter/SprintfFormatter.php

@@ -15,7 +15,6 @@
 namespace Cake\I18n\Formatter;
 
 use Aura\Intl\FormatterInterface;
-use Cake\I18n\PluralRules;
 
 /**
  * A formatter that will interpolate variables using sprintf and

+ 0 - 1
src/I18n/Translator.php

@@ -23,7 +23,6 @@ namespace Cake\I18n;
 use Aura\Intl\FormatterInterface;
 use Aura\Intl\Package;
 use Aura\Intl\TranslatorInterface;
-use Cake\I18n\PluralRules;
 
 /**
  * Provides missing message behavior for CakePHP internal message formats.

+ 59 - 2
tests/TestCase/Controller/Component/PaginatorComponentTest.php

@@ -679,6 +679,37 @@ class PaginatorComponentTest extends TestCase
     }
 
     /**
+     * Test empty pagination result.
+     *
+     * @return void
+     */
+    public function testEmptyPaginationResult()
+    {
+        $this->loadFixtures('Posts');
+
+        $table = TableRegistry::get('PaginatorPosts');
+        $table->deleteAll('1=1');
+
+        $this->Paginator->paginate($table);
+
+        $this->assertSame(
+            0,
+            $this->request->params['paging']['PaginatorPosts']['count'],
+            'Count should be 0'
+        );
+        $this->assertSame(
+            1,
+            $this->request->params['paging']['PaginatorPosts']['page'],
+            'Page number should not be 0'
+        );
+        $this->assertSame(
+            1,
+            $this->request->params['paging']['PaginatorPosts']['pageCount'],
+            'Page count number should not be 0'
+        );
+    }
+
+    /**
      * Test that a really large page number gets clamped to the max page size.
      *
      * @return void
@@ -702,6 +733,30 @@ class PaginatorComponentTest extends TestCase
     }
 
     /**
+     * Test that a out of bounds request still knows about the page size
+     *
+     * @return void
+     */
+    public function testOutOfRangePageNumberStillProvidesPageCount()
+    {
+        $this->loadFixtures('Posts');
+        $this->request->query['limit'] = 1;
+        $this->request->query['page'] = 4;
+
+        $table = TableRegistry::get('PaginatorPosts');
+        try {
+            $this->Paginator->paginate($table);
+            $this->fail('No exception raised');
+        } catch (NotFoundException $e) {
+            $this->assertEquals(
+                3,
+                $this->request->params['paging']['PaginatorPosts']['pageCount'],
+                'Page count number should not be 0'
+            );
+        }
+    }
+
+    /**
      * Test that a really REALLY large page number gets clamped to the max page size.
      *
      * @expectedException \Cake\Network\Exception\NotFoundException
@@ -1260,7 +1315,7 @@ class PaginatorComponentTest extends TestCase
      * Helper method for making mocks.
      *
      * @param array $methods
-     * @return \Cake\ORM\Table
+     * @return \Cake\ORM\Table|\PHPUnit_Framework_MockObject_MockObject
      */
     protected function _getMockPosts($methods = [])
     {
@@ -1284,7 +1339,9 @@ class PaginatorComponentTest extends TestCase
     /**
      * Helper method for mocking queries.
      *
-     * @return \Cake\ORM\Query
+     * @param string|null $table
+     *
+     * @return \Cake\ORM\Query|\PHPUnit_Framework_MockObject_MockObject
      */
     protected function _getMockFindQuery($table = null)
     {

+ 0 - 1
tests/TestCase/Http/ControllerFactoryTest.php

@@ -15,7 +15,6 @@
 namespace Cake\Test\TestCase\Http;
 
 use Cake\Http\ControllerFactory;
-use Cake\Http\Response;
 use Cake\Http\ServerRequest;
 use Cake\TestSuite\TestCase;
 

+ 0 - 1
tests/test_app/Plugin/TestPlugin/src/Log/Engine/TestPluginLog.php

@@ -14,7 +14,6 @@
  */
 namespace TestPlugin\Log\Engine;
 
-use Cake\Log\LogInterface;
 use Psr\Log\AbstractLogger;
 
 /**

+ 0 - 1
tests/test_app/TestApp/Controller/CakesController.php

@@ -2,7 +2,6 @@
 namespace TestApp\Controller;
 
 use Cake\Controller\Controller;
-use Cake\Network\Exception\NotFoundException;
 
 /**
  * CakesController class

+ 0 - 1
tests/test_app/TestApp/Controller/PostsController.php

@@ -15,7 +15,6 @@
 namespace TestApp\Controller;
 
 use Cake\Event\Event;
-use TestApp\Controller\AppController;
 
 /**
  * PostsController class

+ 0 - 1
tests/test_app/TestApp/Model/Behavior/SluggableBehavior.php

@@ -21,7 +21,6 @@ namespace TestApp\Model\Behavior;
 use Cake\Event\Event;
 use Cake\ORM\Behavior;
 use Cake\ORM\Query;
-use Cake\ORM\Table;
 use Cake\Utility\Inflector;
 
 class SluggableBehavior extends Behavior

+ 0 - 1
tests/test_app/TestApp/Model/Table/PaginatorPostsTable.php

@@ -15,7 +15,6 @@ namespace TestApp\Model\Table;
 
 use Cake\ORM\Query;
 use Cake\ORM\Table;
-use Cake\Utility\Hash;
 
 /**
  * PaginatorPostsTable class