Browse Source

Add deprecation warnings to TableRegistry.

Robert Pustułka 8 years ago
parent
commit
0fe60af5a0
2 changed files with 72 additions and 20 deletions
  1. 40 0
      src/ORM/TableRegistry.php
  2. 32 20
      tests/TestCase/ORM/TableRegistryTest.php

+ 40 - 0
src/ORM/TableRegistry.php

@@ -73,6 +73,11 @@ class TableRegistry
      */
     public static function locator(LocatorInterface $locator = null)
     {
+        deprecationWarning(
+            'TableRegistry::locator() is deprecated. ' .
+            'Use getTableLocator()/setTableLocator() instead.'
+        );
+
         if ($locator) {
             static::setTableLocator($locator);
         }
@@ -116,6 +121,11 @@ class TableRegistry
      */
     public static function config($alias = null, $options = null)
     {
+        deprecationWarning(
+            'TableRegistry::config() is deprecated. ' .
+            'Use \Cake\ORM\Locator\TableLocator::config() instead.'
+        );
+
         return static::getTableLocator()->config($alias, $options);
     }
 
@@ -131,6 +141,11 @@ class TableRegistry
      */
     public static function get($alias, array $options = [])
     {
+        deprecationWarning(
+            'TableRegistry::get() is deprecated. ' .
+            'Use \Cake\ORM\Locator\TableLocator::get() instead.'
+        );
+
         return static::getTableLocator()->get($alias, $options);
     }
 
@@ -143,6 +158,11 @@ class TableRegistry
      */
     public static function exists($alias)
     {
+        deprecationWarning(
+            'TableRegistry::exists() is deprecated. ' .
+            'Use \Cake\ORM\Locator\TableLocator::exists() instead.'
+        );
+
         return static::getTableLocator()->exists($alias);
     }
 
@@ -156,6 +176,11 @@ class TableRegistry
      */
     public static function set($alias, Table $object)
     {
+        deprecationWarning(
+            'TableRegistry::set() is deprecated. ' .
+            'Use \Cake\ORM\Locator\TableLocator::set() instead.'
+        );
+
         return static::getTableLocator()->set($alias, $object);
     }
 
@@ -168,6 +193,11 @@ class TableRegistry
      */
     public static function remove($alias)
     {
+        deprecationWarning(
+            'TableRegistry::remove() is deprecated. ' .
+            'Use \Cake\ORM\Locator\TableLocator::remove() instead.'
+        );
+
         static::getTableLocator()->remove($alias);
     }
 
@@ -179,6 +209,11 @@ class TableRegistry
      */
     public static function clear()
     {
+        deprecationWarning(
+            'TableRegistry::clear() is deprecated. ' .
+            'Use \Cake\ORM\Locator\TableLocator::clear() instead.'
+        );
+
         static::getTableLocator()->clear();
     }
 
@@ -191,6 +226,11 @@ class TableRegistry
      */
     public static function __callStatic($name, $arguments)
     {
+        deprecationWarning(
+            'TableRegistry::' . $name . '() is deprecated. ' .
+            'Use \Cake\ORM\Locator\TableLocator::' . $name . '() instead.'
+        );
+
         return static::getTableLocator()->$name(...$arguments);
     }
 }

+ 32 - 20
tests/TestCase/ORM/TableRegistryTest.php

@@ -73,12 +73,14 @@ class TableRegistryTest extends TestCase
      */
     public function testLocator()
     {
-        $this->assertInstanceOf('Cake\ORM\Locator\LocatorInterface', TableRegistry::locator());
+        $this->deprecated(function () {
+            $this->assertInstanceOf('Cake\ORM\Locator\LocatorInterface', TableRegistry::locator());
 
-        $locator = $this->getMockBuilder('Cake\ORM\Locator\LocatorInterface')->getMock();
-        TableRegistry::locator($locator);
+            $locator = $this->getMockBuilder('Cake\ORM\Locator\LocatorInterface')->getMock();
+            TableRegistry::locator($locator);
 
-        $this->assertSame($locator, TableRegistry::locator());
+            $this->assertSame($locator, TableRegistry::locator());
+        });
     }
 
     /**
@@ -121,10 +123,12 @@ class TableRegistryTest extends TestCase
      */
     public function testConfig()
     {
-        $locator = $this->_setMockLocator();
-        $locator->expects($this->once())->method('config')->with('Test', []);
+        $this->deprecated(function () {
+            $locator = $this->_setMockLocator();
+            $locator->expects($this->once())->method('config')->with('Test', []);
 
-        TableRegistry::config('Test', []);
+            TableRegistry::config('Test', []);
+        });
     }
 
     /**
@@ -134,10 +138,12 @@ class TableRegistryTest extends TestCase
      */
     public function testGet()
     {
-        $locator = $this->_setMockLocator();
-        $locator->expects($this->once())->method('get')->with('Test', []);
+        $this->deprecated(function () {
+            $locator = $this->_setMockLocator();
+            $locator->expects($this->once())->method('get')->with('Test', []);
 
-        TableRegistry::get('Test', []);
+            TableRegistry::get('Test', []);
+        });
     }
 
     /**
@@ -147,12 +153,14 @@ class TableRegistryTest extends TestCase
      */
     public function testSet()
     {
-        $table = $this->getMockBuilder('Cake\ORM\Table')->getMock();
+        $this->deprecated(function () {
+            $table = $this->getMockBuilder('Cake\ORM\Table')->getMock();
 
-        $locator = $this->_setMockLocator();
-        $locator->expects($this->once())->method('set')->with('Test', $table);
+            $locator = $this->_setMockLocator();
+            $locator->expects($this->once())->method('set')->with('Test', $table);
 
-        TableRegistry::set('Test', $table);
+            TableRegistry::set('Test', $table);
+        });
     }
 
     /**
@@ -162,10 +170,12 @@ class TableRegistryTest extends TestCase
      */
     public function testRemove()
     {
-        $locator = $this->_setMockLocator();
-        $locator->expects($this->once())->method('remove')->with('Test');
+        $this->deprecated(function () {
+            $locator = $this->_setMockLocator();
+            $locator->expects($this->once())->method('remove')->with('Test');
 
-        TableRegistry::remove('Test');
+            TableRegistry::remove('Test');
+        });
     }
 
     /**
@@ -175,9 +185,11 @@ class TableRegistryTest extends TestCase
      */
     public function testClear()
     {
-        $locator = $this->_setMockLocator();
-        $locator->expects($this->once())->method('clear');
+        $this->deprecated(function () {
+            $locator = $this->_setMockLocator();
+            $locator->expects($this->once())->method('clear');
 
-        TableRegistry::clear();
+            TableRegistry::clear();
+        });
     }
 }