Browse Source

Formalize current deprecations

Add formal warnings for deprecations that have been added so far in 4.x.
I'll follow this up with a change to rector as well.
Mark Story 5 years ago
parent
commit
7667c927c9

+ 2 - 0
src/Cache/Cache.php

@@ -206,6 +206,8 @@ class Cache
      */
     public static function engine(string $config)
     {
+        deprecationWarning('Cache::engine() is deprecated. Use Cache::pool() instead.');
+
         return static::pool($config);
     }
 

+ 2 - 0
src/Database/Type/DateTimeType.php

@@ -163,6 +163,8 @@ class DateTimeType extends BaseType implements BatchCastingInterface
      */
     public function setTimezone($timezone)
     {
+        deprecationWarning('DateTimeType::setTimezone() is deprecated. use setDatabaseTimezone() instead.');
+
         return $this->setDatabaseTimezone($timezone);
     }
 

+ 2 - 0
src/Datasource/EntityTrait.php

@@ -457,6 +457,8 @@ trait EntityTrait
      */
     public function unsetProperty($field)
     {
+        deprecationWarning('EntityTrait::unsetProperty() is deprecated. Use unset() instead.');
+
         return $this->unset($field);
     }
 

+ 1 - 0
src/Form/Form.php

@@ -182,6 +182,7 @@ class Form implements EventListenerInterface, EventDispatcherInterface, Validato
      */
     public function schema(?Schema $schema = null): Schema
     {
+        deprecationWarning('Form::schema() is deprecated. Use setSchema() and getSchema() instead.');
         if ($schema !== null) {
             $this->setSchema($schema);
         }

+ 2 - 0
src/Http/Cookie/Cookie.php

@@ -431,6 +431,8 @@ class Cookie implements CookieInterface
      */
     public function getStringValue()
     {
+        deprecationWarning('Cookie::getStringValue() is deprecated. Use getStringValue() instead.');
+
         return $this->getScalarValue();
     }
 

+ 2 - 0
src/Http/Middleware/CsrfProtectionMiddleware.php

@@ -215,6 +215,8 @@ class CsrfProtectionMiddleware implements MiddlewareInterface
      */
     protected function _createToken(): string
     {
+        deprecationWarning('_createToken() is deprecated. Use createToken() instead.');
+
         return $this->createToken();
     }
 

+ 1 - 0
src/Mailer/Mailer.php

@@ -300,6 +300,7 @@ class Mailer implements EventListenerInterface
      */
     public function set($key, $value = null)
     {
+        deprecationWarning('Mailer::set() is deprecated. Use setViewVars() instead.');
         return $this->setViewVars($key, $value);
     }
 

+ 2 - 0
src/ORM/Behavior.php

@@ -188,6 +188,8 @@ class Behavior implements EventListenerInterface
      */
     public function getTable(): Table
     {
+        deprecationWarning('Behavior::getTable() is deprecated. Use table() instead.');
+
         return $this->table();
     }
 

+ 1 - 0
src/Validation/Validation.php

@@ -433,6 +433,7 @@ class Validation
      */
     public static function containsNonAlphaNumeric($check, int $count = 1): bool
     {
+        deprecationWarning('Validation::containsNonAlphaNumeric() is deprecated. Use notAlphaNumeric() instead.');
         if (!is_string($check)) {
             return false;
         }

+ 1 - 0
src/Validation/Validator.php

@@ -1691,6 +1691,7 @@ class Validator implements ArrayAccess, IteratorAggregate, Countable
      */
     public function containsNonAlphaNumeric(string $field, int $limit = 1, ?string $message = null, $when = null)
     {
+        deprecationWarning('Validator::containsNonAlphaNumeric() is deprecated. Use notAlphaNumeric() instead.');
         $extra = array_filter(['on' => $when, 'message' => $message]);
 
         return $this->add($field, 'containsNonAlphaNumeric', $extra + [

+ 2 - 0
src/View/Helper/NumberHelper.php

@@ -226,6 +226,8 @@ class NumberHelper extends Helper
      */
     public function defaultCurrency($currency): ?string
     {
+        deprecationWarning('NumberHelper::defaultCurreny() is deprecated. Use setDefaultCurreny() and getDefaultCurrent() instead.');
+
         return $this->_engine->defaultCurrency($currency);
     }
 

+ 12 - 12
tests/TestCase/Database/Type/DateTimeFractionalTypeTest.php

@@ -83,7 +83,7 @@ class DateTimeFractionalTypeTest extends TestCase
         $this->assertInstanceOf(FrozenTime::class, $result);
         $this->assertSame('123456', $result->format('u'));
 
-        $this->type->setTimezone('Asia/Kolkata'); // UTC+5:30
+        $this->type->setDatabaseTimezone('Asia/Kolkata'); // UTC+5:30
         $result = $this->type->toPHP('2001-01-04 12:00:00.123456', $this->driver);
         $this->assertInstanceOf(FrozenTime::class, $result);
         $this->assertSame('2001', $result->format('Y'));
@@ -122,7 +122,7 @@ class DateTimeFractionalTypeTest extends TestCase
             $this->type->manyToPHP($values, array_keys($values), $this->driver)
         );
 
-        $this->type->setTimezone('Asia/Kolkata'); // UTC+5:30
+        $this->type->setDatabaseTimezone('Asia/Kolkata'); // UTC+5:30
         $values = [
             'a' => null,
             'b' => '2001-01-04 12:13:14',
@@ -162,24 +162,24 @@ class DateTimeFractionalTypeTest extends TestCase
         $this->assertSame('2013-08-12 15:16:17.123456', $result);
 
         $tz = $date->getTimezone();
-        $this->type->setTimezone('Asia/Kolkata'); // UTC+5:30
+        $this->type->setDatabaseTimezone('Asia/Kolkata'); // UTC+5:30
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 20:46:17.123456', $result);
         $this->assertEquals($tz, $date->getTimezone());
 
-        $this->type->setTimezone(new DateTimeZone('Asia/Kolkata'));
+        $this->type->setDatabaseTimezone(new DateTimeZone('Asia/Kolkata'));
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 20:46:17.123456', $result);
-        $this->type->setTimezone(null);
+        $this->type->setDatabaseTimezone(null);
 
         $date = new FrozenTime('2013-08-12 15:16:17.123456');
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 15:16:17.123456', $result);
 
-        $this->type->setTimezone('Asia/Kolkata'); // UTC+5:30
+        $this->type->setDatabaseTimezone('Asia/Kolkata'); // UTC+5:30
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 20:46:17.123456', $result);
-        $this->type->setTimezone(null);
+        $this->type->setDatabaseTimezone(null);
     }
 
     /**
@@ -194,24 +194,24 @@ class DateTimeFractionalTypeTest extends TestCase
         $this->assertSame('2013-08-12 15:16:17.000000', $result);
 
         $tz = $date->getTimezone();
-        $this->type->setTimezone('Asia/Kolkata'); // UTC+5:30
+        $this->type->setDatabaseTimezone('Asia/Kolkata'); // UTC+5:30
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 20:46:17.000000', $result);
         $this->assertEquals($tz, $date->getTimezone());
 
-        $this->type->setTimezone(new DateTimeZone('Asia/Kolkata'));
+        $this->type->setDatabaseTimezone(new DateTimeZone('Asia/Kolkata'));
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 20:46:17.000000', $result);
-        $this->type->setTimezone(null);
+        $this->type->setDatabaseTimezone(null);
 
         $date = new FrozenTime('2013-08-12 15:16:17');
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 15:16:17.000000', $result);
 
-        $this->type->setTimezone('Asia/Kolkata'); // UTC+5:30
+        $this->type->setDatabaseTimezone('Asia/Kolkata'); // UTC+5:30
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 20:46:17.000000', $result);
-        $this->type->setTimezone(null);
+        $this->type->setDatabaseTimezone(null);
 
         $date = 1401906995;
         $result = $this->type->toDatabase($date, $this->driver);

+ 7 - 7
tests/TestCase/Database/Type/DateTimeTypeTest.php

@@ -96,7 +96,7 @@ class DateTimeTypeTest extends TestCase
         $this->assertSame('13', $result->format('i'));
         $this->assertSame('14', $result->format('s'));
 
-        $this->type->setTimezone('Asia/Kolkata'); // UTC+5:30
+        $this->type->setDatabaseTimezone('Asia/Kolkata'); // UTC+5:30
         $result = $this->type->toPHP('2001-01-04 12:00:00', $this->driver);
         $this->assertInstanceOf(FrozenTime::class, $result);
         $this->assertSame('2001', $result->format('Y'));
@@ -127,7 +127,7 @@ class DateTimeTypeTest extends TestCase
             $this->type->manyToPHP($values, array_keys($values), $this->driver)
         );
 
-        $this->type->setTimezone('Asia/Kolkata'); // UTC+5:30
+        $this->type->setDatabaseTimezone('Asia/Kolkata'); // UTC+5:30
         $values = [
             'a' => null,
             'b' => '2001-01-04 12:13:14',
@@ -173,24 +173,24 @@ class DateTimeTypeTest extends TestCase
         $this->assertSame('2013-08-12 15:16:17', $result);
 
         $tz = $date->getTimezone();
-        $this->type->setTimezone('Asia/Kolkata'); // UTC+5:30
+        $this->type->setDatabaseTimezone('Asia/Kolkata'); // UTC+5:30
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 20:46:17', $result);
         $this->assertEquals($tz, $date->getTimezone());
 
-        $this->type->setTimezone(new DateTimeZone('Asia/Kolkata'));
+        $this->type->setDatabaseTimezone(new DateTimeZone('Asia/Kolkata'));
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 20:46:17', $result);
-        $this->type->setTimezone(null);
+        $this->type->setDatabaseTimezone(null);
 
         $date = new FrozenTime('2013-08-12 15:16:17');
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 15:16:17', $result);
 
-        $this->type->setTimezone('Asia/Kolkata'); // UTC+5:30
+        $this->type->setDatabaseTimezone('Asia/Kolkata'); // UTC+5:30
         $result = $this->type->toDatabase($date, $this->driver);
         $this->assertSame('2013-08-12 20:46:17', $result);
-        $this->type->setTimezone(null);
+        $this->type->setDatabaseTimezone(null);
 
         $date = 1401906995;
         $result = $this->type->toDatabase($date, $this->driver);

+ 11 - 9
tests/TestCase/Form/FormTest.php

@@ -36,18 +36,20 @@ class FormTest extends TestCase
      */
     public function testSchema()
     {
-        $form = new Form();
-        $schema = $form->schema();
+        $this->deprecated(function () {
+            $form = new Form();
+            $schema = $form->schema();
 
-        $this->assertInstanceOf('Cake\Form\Schema', $schema);
-        $this->assertSame($schema, $form->schema(), 'Same instance each time');
+            $this->assertInstanceOf('Cake\Form\Schema', $schema);
+            $this->assertSame($schema, $form->schema(), 'Same instance each time');
 
-        $schema = new Schema();
-        $this->assertSame($schema, $form->schema($schema));
-        $this->assertSame($schema, $form->schema());
+            $schema = new Schema();
+            $this->assertSame($schema, $form->schema($schema));
+            $this->assertSame($schema, $form->schema());
 
-        $form = new AppForm();
-        $this->assertInstanceOf(FormSchema::class, $form->schema());
+            $form = new AppForm();
+            $this->assertInstanceOf(FormSchema::class, $form->schema());
+        });
     }
 
     /**

+ 8 - 6
tests/TestCase/Http/Cookie/CookieTest.php

@@ -128,14 +128,16 @@ class CookieTest extends TestCase
      */
     public function testGetStringValue()
     {
-        $cookie = new Cookie('cakephp', 'thing');
-        $this->assertSame('thing', $cookie->getStringValue());
+        $this->deprecated(function () {
+            $cookie = new Cookie('cakephp', 'thing');
+            $this->assertSame('thing', $cookie->getStringValue());
 
-        $value = ['user_id' => 1, 'token' => 'abc123'];
-        $cookie = new Cookie('cakephp', $value);
+            $value = ['user_id' => 1, 'token' => 'abc123'];
+            $cookie = new Cookie('cakephp', $value);
 
-        $this->assertSame($value, $cookie->getValue());
-        $this->assertSame(json_encode($value), $cookie->getStringValue());
+            $this->assertSame($value, $cookie->getValue());
+            $this->assertSame(json_encode($value), $cookie->getStringValue());
+        });
     }
 
     /**

+ 6 - 4
tests/TestCase/ORM/EntityTest.php

@@ -596,11 +596,13 @@ class EntityTest extends TestCase
      */
     public function testUnsetDeprecated()
     {
-        $entity = new Entity();
-        $entity->foo = 'foo';
+        $this->deprecated(function () {
+            $entity = new Entity();
+            $entity->foo = 'foo';
 
-        $entity->unsetProperty('foo');
-        $this->assertNull($entity->foo);
+            $entity->unsetProperty('foo');
+            $this->assertNull($entity->foo);
+        });
     }
 
     /**

+ 5 - 3
tests/TestCase/Validation/ValidatorTest.php

@@ -2467,9 +2467,11 @@ class ValidatorTest extends TestCase
      */
     public function testContainsNonAlphaNumeric()
     {
-        $validator = new Validator();
-        $this->assertProxyMethod($validator, 'containsNonAlphaNumeric', 2, [2]);
-        $this->assertNotEmpty($validator->validate(['username' => '$']));
+        $this->deprecated(function () {
+            $validator = new Validator();
+            $this->assertProxyMethod($validator, 'containsNonAlphaNumeric', 2, [2]);
+            $this->assertNotEmpty($validator->validate(['username' => '$']));
+        });
     }
 
     /**

+ 0 - 1
tests/TestCase/View/Helper/NumberHelperTest.php

@@ -80,7 +80,6 @@ class NumberHelperTest extends TestCase
             ['currency'],
             ['format'],
             ['formatDelta'],
-            ['defaultCurrency'],
             ['ordinal'],
         ];
     }