Browse Source

Merge branch 'master' into 3.next

Mark Story 7 years ago
parent
commit
4047e7146c
4 changed files with 104 additions and 65 deletions
  1. 7 0
      src/Core/Plugin.php
  2. 14 0
      src/Http/Response.php
  3. 41 32
      tests/TestCase/Core/PluginTest.php
  4. 42 33
      tests/TestCase/Http/ResponseTest.php

+ 7 - 0
src/Core/Plugin.php

@@ -337,9 +337,16 @@ class Plugin
      * @param string|null $name name of the plugin, if null will operate on all
      *   plugins having enabled the loading of routes files.
      * @return bool
+     * @deprecated 3.6.5 This method is no longer needed when using HttpApplicationInterface based applications.
+     *   This method will be removed in 4.0.0
      */
     public static function routes($name = null)
     {
+        deprecationWarning(
+            'You no longer need to call `Plugin::routes()` after upgrading to use Http\Server. ' .
+            'See https://book.cakephp.org/3.0/en/development/application.html#adding-the-new-http-stack-to-an-existing-application ' .
+            'for upgrade information.'
+        );
         if ($name === null) {
             foreach (static::loaded() as $p) {
                 static::routes($p);

+ 14 - 0
src/Http/Response.php

@@ -1365,6 +1365,10 @@ class Response implements ResponseInterface
      */
     public function sharable($public = null, $time = null)
     {
+        deprecationWarning(
+            'Response::sharable() is deprecated. ' .
+            'Use withSharable() instead.'
+        );
         if ($public === null) {
             $public = array_key_exists('public', $this->_cacheDirectives);
             $private = array_key_exists('private', $this->_cacheDirectives);
@@ -1422,11 +1426,16 @@ class Response implements ResponseInterface
      * a good candidate to be fetched from a shared cache (like in a proxy server).
      * If called with no parameters, this function will return the current max-age value if any
      *
+     * @deprecated 3.6.5 Use withSharedMaxAge() instead.
      * @param int|null $seconds if null, the method will return the current s-maxage value
      * @return int|null
      */
     public function sharedMaxAge($seconds = null)
     {
+        deprecationWarning(
+            'Response::sharedMaxAge() is deprecated. ' .
+            'Use withSharedMaxAge() instead.'
+        );
         if ($seconds !== null) {
             $this->_cacheDirectives['s-maxage'] = $seconds;
             $this->_setCacheControl();
@@ -1462,11 +1471,16 @@ class Response implements ResponseInterface
      * a good candidate to be fetched from the local (client) cache.
      * If called with no parameters, this function will return the current max-age value if any
      *
+     * @deprecated 3.6.5 Use withMaxAge() instead.
      * @param int|null $seconds if null, the method will return the current max-age value
      * @return int|null
      */
     public function maxAge($seconds = null)
     {
+        deprecationWarning(
+            'Response::maxAge() is deprecated. ' .
+            'Use withMaxAge() instead.'
+        );
         if ($seconds !== null) {
             $this->_cacheDirectives['max-age'] = $seconds;
             $this->_setCacheControl();

+ 41 - 32
tests/TestCase/Core/PluginTest.php

@@ -177,16 +177,19 @@ class PluginTest extends TestCase
     /**
      * Tests loading a plugin with bootstrap file and routes file
      *
+     * @deprecated
      * @return void
      */
     public function testLoadSingleWithBootstrapAndRoutes()
     {
-        Plugin::load('TestPlugin', ['bootstrap' => true, 'routes' => true]);
-        $this->assertTrue(Plugin::loaded('TestPlugin'));
-        $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
-
-        Plugin::routes();
-        $this->assertEquals('loaded plugin routes', Configure::read('PluginTest.test_plugin.routes'));
+        $this->deprecated(function () {
+            Plugin::load('TestPlugin', ['bootstrap' => true, 'routes' => true]);
+            $this->assertTrue(Plugin::loaded('TestPlugin'));
+            $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
+
+            Plugin::routes();
+            $this->assertEquals('loaded plugin routes', Configure::read('PluginTest.test_plugin.routes'));
+        });
     }
 
     /**
@@ -247,16 +250,19 @@ class PluginTest extends TestCase
     /**
      * Test ignoring missing bootstrap/routes file
      *
+     * @deprecated
      * @return void
      */
     public function testIgnoreMissingFiles()
     {
-        Plugin::loadAll([[
-            'bootstrap' => true,
-            'routes' => true,
-            'ignoreMissing' => true
-        ]]);
-        $this->assertTrue(Plugin::routes());
+        $this->deprecated(function () {
+            Plugin::loadAll([[
+                'bootstrap' => true,
+                'routes' => true,
+                'ignoreMissing' => true
+            ]]);
+            $this->assertTrue(Plugin::routes());
+        });
     }
 
     /**
@@ -390,29 +396,32 @@ class PluginTest extends TestCase
      * Tests that Plugin::loadAll() will load all plugins in the configured folder wit defaults
      * and overrides for a plugin
      *
+     * @deprecated
      * @return void
      */
     public function testLoadAllWithDefaultsAndOverride()
     {
-        Plugin::loadAll([
-            ['bootstrap' => true, 'ignoreMissing' => true],
-            'TestPlugin' => ['routes' => true],
-            'TestPluginFour' => ['bootstrap' => true, 'classBase' => '']
-        ]);
-        Plugin::routes();
-
-        $expected = [
-            'Company', 'ParentPlugin', 'PluginJs', 'TestPlugin',
-            'TestPluginFour', 'TestPluginTwo', 'TestTheme'
-        ];
-        $this->assertEquals($expected, Plugin::loaded());
-        $this->assertEquals('loaded js plugin bootstrap', Configure::read('PluginTest.js_plugin.bootstrap'));
-        $this->assertEquals('loaded plugin routes', Configure::read('PluginTest.test_plugin.routes'));
-        $this->assertNull(Configure::read('PluginTest.test_plugin.bootstrap'));
-        $this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap'));
-        $this->assertEquals('loaded plugin four bootstrap', Configure::read('PluginTest.test_plugin_four.bootstrap'));
-
-        // TestPluginThree won't get loaded by loadAll() since it's in a sub directory.
-        $this->assertNull(Configure::read('PluginTest.test_plugin_three.bootstrap'));
+        $this->deprecated(function () {
+            Plugin::loadAll([
+                ['bootstrap' => true, 'ignoreMissing' => true],
+                'TestPlugin' => ['routes' => true],
+                'TestPluginFour' => ['bootstrap' => true, 'classBase' => '']
+            ]);
+            Plugin::routes();
+
+            $expected = [
+                'Company', 'ParentPlugin', 'PluginJs', 'TestPlugin',
+                'TestPluginFour', 'TestPluginTwo', 'TestTheme'
+            ];
+            $this->assertEquals($expected, Plugin::loaded());
+            $this->assertEquals('loaded js plugin bootstrap', Configure::read('PluginTest.js_plugin.bootstrap'));
+            $this->assertEquals('loaded plugin routes', Configure::read('PluginTest.test_plugin.routes'));
+            $this->assertNull(Configure::read('PluginTest.test_plugin.bootstrap'));
+            $this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap'));
+            $this->assertEquals('loaded plugin four bootstrap', Configure::read('PluginTest.test_plugin_four.bootstrap'));
+
+            // TestPluginThree won't get loaded by loadAll() since it's in a sub directory.
+            $this->assertNull(Configure::read('PluginTest.test_plugin_three.bootstrap'));
+        });
     }
 }

+ 42 - 33
tests/TestCase/Http/ResponseTest.php

@@ -1074,28 +1074,31 @@ class ResponseTest extends TestCase
     /**
      * Tests setting of public/private Cache-Control directives
      *
+     * @deprecated
      * @return void
      */
     public function testSharable()
     {
-        $response = new Response();
-        $this->assertNull($response->sharable());
-        $response->sharable(true);
-        $this->assertTrue($response->sharable());
-        $this->assertEquals('public', $response->getHeaderLine('Cache-Control'));
+        $this->deprecated(function () {
+            $response = new Response();
+            $this->assertNull($response->sharable());
+            $response->sharable(true);
+            $this->assertTrue($response->sharable());
+            $this->assertEquals('public', $response->getHeaderLine('Cache-Control'));
 
-        $response = new Response();
-        $response->sharable(false);
-        $this->assertFalse($response->sharable());
-        $this->assertEquals('private', $response->getHeaderLine('Cache-Control'));
+            $response = new Response();
+            $response->sharable(false);
+            $this->assertFalse($response->sharable());
+            $this->assertEquals('private', $response->getHeaderLine('Cache-Control'));
 
-        $response = new Response();
-        $response->sharable(true, 3600);
-        $this->assertEquals('public, max-age=3600', $response->getHeaderLine('Cache-Control'));
+            $response = new Response();
+            $response->sharable(true, 3600);
+            $this->assertEquals('public, max-age=3600', $response->getHeaderLine('Cache-Control'));
 
-        $response = new Response();
-        $response->sharable(false, 3600);
-        $this->assertEquals('private, max-age=3600', $response->getHeaderLine('Cache-Control'));
+            $response = new Response();
+            $response->sharable(false, 3600);
+            $this->assertEquals('private, max-age=3600', $response->getHeaderLine('Cache-Control'));
+        });
     }
 
     /**
@@ -1123,20 +1126,23 @@ class ResponseTest extends TestCase
     /**
      * Tests setting of max-age Cache-Control directive
      *
+     * @deprecated
      * @return void
      */
     public function testMaxAge()
     {
-        $response = new Response();
-        $this->assertNull($response->maxAge());
-        $response->maxAge(3600);
-        $this->assertEquals(3600, $response->maxAge());
-        $this->assertEquals('max-age=3600', $response->getHeaderLine('Cache-Control'));
+        $this->deprecated(function () {
+            $response = new Response();
+            $this->assertNull($response->maxAge());
+            $response->maxAge(3600);
+            $this->assertEquals(3600, $response->maxAge());
+            $this->assertEquals('max-age=3600', $response->getHeaderLine('Cache-Control'));
 
-        $response = new Response();
-        $response->maxAge(3600);
-        $response->sharable(false);
-        $this->assertEquals('max-age=3600, private', $response->getHeaderLine('Cache-Control'));
+            $response = new Response();
+            $response->maxAge(3600);
+            $response->sharable(false);
+            $this->assertEquals('max-age=3600, private', $response->getHeaderLine('Cache-Control'));
+        });
     }
 
     /**
@@ -1160,20 +1166,23 @@ class ResponseTest extends TestCase
     /**
      * Tests setting of s-maxage Cache-Control directive
      *
+     * @deprecated
      * @return void
      */
     public function testSharedMaxAge()
     {
-        $response = new Response();
-        $this->assertNull($response->maxAge());
-        $response->sharedMaxAge(3600);
-        $this->assertEquals(3600, $response->sharedMaxAge());
-        $this->assertEquals('s-maxage=3600', $response->getHeaderLine('Cache-Control'));
+        $this->deprecated(function () {
+            $response = new Response();
+            $this->assertNull($response->maxAge());
+            $response->sharedMaxAge(3600);
+            $this->assertEquals(3600, $response->sharedMaxAge());
+            $this->assertEquals('s-maxage=3600', $response->getHeaderLine('Cache-Control'));
 
-        $response = new Response();
-        $response->sharedMaxAge(3600);
-        $response->sharable(true);
-        $this->assertEquals('s-maxage=3600, public', $response->getHeaderLine('Cache-Control'));
+            $response = new Response();
+            $response->sharedMaxAge(3600);
+            $response->sharable(true);
+            $this->assertEquals('s-maxage=3600, public', $response->getHeaderLine('Cache-Control'));
+        });
     }
 
     /**