Browse Source

Verify deprecation path for various warnings

Corey Taylor 4 years ago
parent
commit
c8fa715c06

+ 34 - 1
tests/TestCase/Controller/Component/PaginatorComponentTest.php

@@ -520,7 +520,7 @@ class PaginatorComponentTest extends TestCase
     /**
      * test that modifying the whitelist works.
      */
-    public function testMergeOptionsExtraWhitelist(): void
+    public function testDeprecatedMergeOptionsExtraWhitelist(): void
     {
         $this->controller->setRequest($this->controller->getRequest()->withQueryParams([
             'page' => 10,
@@ -551,6 +551,39 @@ class PaginatorComponentTest extends TestCase
     }
 
     /**
+     * Test path for deprecated whitelist.
+     */
+    public function testDeprecatedPathMergeOptionsExtraWhitelist(): void
+    {
+        $this->expectDeprecation();
+        $this->expectDeprecationMessage('Paginator.php');
+        $this->controller->setRequest($this->controller->getRequest()->withQueryParams([
+            'page' => 10,
+            'limit' => 10,
+            'fields' => ['bad.stuff'],
+            'recursive' => 1000,
+            'conditions' => ['bad.stuff'],
+            'contain' => ['bad'],
+        ]));
+        $settings = [
+            'page' => 1,
+            'limit' => 20,
+            'maxLimit' => 100,
+        ];
+
+        $this->Paginator->setConfig('whitelist', ['fields']);
+        $result = $this->Paginator->mergeOptions('Post', $settings);
+        $expected = [
+            'page' => 10,
+            'limit' => 10,
+            'maxLimit' => 100,
+            'fields' => ['bad.stuff'],
+            'whitelist' => ['limit', 'sort', 'page', 'direction', 'fields'],
+            'allowedParameters' => ['limit', 'sort', 'page', 'direction', 'fields'],
+        ];
+    }
+
+    /**
      * test mergeOptions with limit > maxLimit in code.
      */
     public function testMergeOptionsMaxLimit(): void

+ 10 - 1
tests/TestCase/Controller/ComponentTest.php

@@ -251,7 +251,7 @@ class ComponentTest extends TestCase
     /**
      * Tests deprecated shutdown callback
      */
-    public function testEventShutdown(): void
+    public function testDeprecatedEventShutdown(): void
     {
         $Collection = new ComponentRegistry();
 
@@ -270,6 +270,15 @@ class ComponentTest extends TestCase
         });
     }
 
+    public function testDeprecatedEventShutdownPath(): void
+    {
+        $this->expectDeprecation();
+        $this->expectDeprecationMessage('Component.php');
+
+        $component = new TestShutdownComponent(new ComponentRegistry());
+        $result = $component->__debugInfo();
+    }
+
     /**
      * Test that calling getController() without setting a controller throws exception
      */

+ 16 - 18
tests/TestCase/Controller/ControllerFactoryTest.php

@@ -68,24 +68,22 @@ class ControllerFactoryTest extends TestCase
     /**
      * Test building a prefixed app controller.
      */
-    public function testPrefixedAppControllerDeprecated(): void
-    {
-        $this->deprecated(function (): void {
-            $request = new ServerRequest([
-                'url' => 'admin/posts/index',
-                'params' => [
-                    'prefix' => 'Admin',
-                    'controller' => 'Posts',
-                    'action' => 'index',
-                ],
-            ]);
-            $result = $this->factory->create($request);
-            $this->assertInstanceOf(
-                'TestApp\Controller\Admin\PostsController',
-                $result
-            );
-            $this->assertSame($request, $result->getRequest());
-        });
+    public function testPrefixedAppController(): void
+    {
+        $request = new ServerRequest([
+            'url' => 'admin/posts/index',
+            'params' => [
+                'prefix' => 'Admin',
+                'controller' => 'Posts',
+                'action' => 'index',
+            ],
+        ]);
+        $result = $this->factory->create($request);
+        $this->assertInstanceOf(
+            'TestApp\Controller\Admin\PostsController',
+            $result
+        );
+        $this->assertSame($request, $result->getRequest());
     }
 
     /**

+ 1 - 0
tests/TestCase/Log/Engine/SyslogLogTest.php

@@ -110,6 +110,7 @@ class SyslogLogTest extends TestCase
     {
         $this->expectDeprecation();
         $this->expectDeprecationMessage('`format` option is now deprecated in favor of custom formatters');
+        $this->expectDeprecationMessage('SyslogLog.php');
         new SyslogLog(['format' => 'custom %s: %s']);
     }
 

+ 20 - 1
tests/TestCase/ORM/QueryTest.php

@@ -1840,7 +1840,7 @@ class QueryTest extends TestCase
      * @param mixed $arg
      * @param mixed $return
      */
-    public function testCollectionProxy(string $method, $arg, $return): void
+    public function testDeprecatedCollectionProxy(string $method, $arg, $return): void
     {
         $query = $this->getMockBuilder('Cake\ORM\Query')
             ->onlyMethods(['all'])
@@ -1865,6 +1865,25 @@ class QueryTest extends TestCase
     }
 
     /**
+     * Tests deprecation path for proxy collection methods.
+     *
+     * @dataProvider collectionMethodsProvider
+     */
+    public function testDeprecatedPathCollectionProxy(string $method, $arg, $return): void
+    {
+        $this->expectDeprecation();
+        $this->expectDeprecationMessage('QueryTest.php');
+
+        $query = $this->getMockBuilder('Cake\ORM\Query')
+            ->onlyMethods(['all'])
+            ->setConstructorArgs([$this->connection, $this->table])
+            ->getMock();
+        $query->select();
+
+        $this->assertSame($return, $query->{$method}($arg, 99));
+    }
+
+    /**
      * Tests that calling an nonexistent method in query throws an
      * exception
      */